fixes tests

This commit is contained in:
James
2020-11-29 12:41:13 -05:00
parent 53d78e995b
commit 767b68b0bd
5 changed files with 8 additions and 12 deletions

View File

@@ -2,11 +2,14 @@ module.exports = {
verbose: true, verbose: true,
testEnvironment: 'node', testEnvironment: 'node',
globalSetup: '<rootDir>/tests/api/globalSetup.js', globalSetup: '<rootDir>/tests/api/globalSetup.js',
globalTeardown: '<rootDir>/tests/api/globalTeardown.js',
testPathIgnorePatterns: [ testPathIgnorePatterns: [
'node_modules', 'node_modules',
'src/admin/*', 'src/admin/*',
'dist', 'dist',
], ],
testTimeout: 15000, testTimeout: 15000,
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/src/webpack/mocks/fileMock.js',
'\\.(css|scss)$': '<rootDir>/src/webpack/mocks/emptyModule.js',
},
}; };

View File

@@ -23,8 +23,8 @@
"lint": "eslint .", "lint": "eslint .",
"test": "yarn test:int && yarn test:client", "test": "yarn test:int && yarn test:client",
"pretest": "tsc-silent --project tsconfig.json --suppress @", "pretest": "tsc-silent --project tsconfig.json --suppress @",
"test:int": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.js NODE_ENV=test DISABLE_LOGGING=true jest --forceExit --runInBand", "test:int": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts NODE_ENV=test DISABLE_LOGGING=true jest --forceExit --runInBand",
"test:client": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.js NODE_ENV=test jest --config=jest.react.config.js" "test:client": "cross-env PAYLOAD_CONFIG_PATH=demo/payload.config.ts NODE_ENV=test jest --config=jest.react.config.js"
}, },
"dependencies": { "dependencies": {
"@babel/cli": "^7.12.8", "@babel/cli": "^7.12.8",

View File

@@ -7,6 +7,7 @@ import findConfig from './find';
const removedExtensions = ['.scss', '.css', '.svg', '.png', '.jpg', '.eot', '.ttf', '.woff', '.woff2']; const removedExtensions = ['.scss', '.css', '.svg', '.png', '.jpg', '.eot', '.ttf', '.woff', '.woff2'];
const configPath = findConfig(); const configPath = findConfig();
const loadConfig = (): PayloadConfig => { const loadConfig = (): PayloadConfig => {
removedExtensions.forEach((ext) => { removedExtensions.forEach((ext) => {
require.extensions[ext] = () => null; require.extensions[ext] = () => null;

View File

@@ -1,14 +1,12 @@
require('isomorphic-fetch'); require('isomorphic-fetch');
require('../../demo/server');
const server = require('../../demo/server');
const loadConfig = require('../../src/config/load').default; const loadConfig = require('../../src/config/load').default;
const { email, password } = require('./credentials'); const { email, password } = require('./credentials');
const { serverURL } = loadConfig(); const { serverURL } = loadConfig();
const globalSetup = async () => { const globalSetup = async () => {
global.PAYLOAD_SERVER = server.start();
const response = await fetch(`${serverURL}/api/admins/first-register`, { const response = await fetch(`${serverURL}/api/admins/first-register`, {
body: JSON.stringify({ body: JSON.stringify({
email, email,

View File

@@ -1,6 +0,0 @@
const globalTeardown = async () => {
const serverClosePromise = new Promise((resolve) => global.PAYLOAD_SERVER.close(resolve));
await serverClosePromise;
};
module.exports = globalTeardown;