Skip to content

Commit

Permalink
[jest.config.js] Add separate project configurations for
Browse files Browse the repository at this point in the history
client/server/app

[server:tests:index] Remove jest-env comment flag, no longer necessary
  • Loading branch information
chichiwang committed Mar 20, 2024
1 parent c9b27dd commit 3adc051
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
49 changes: 41 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
const sharedConfigs = {
transform: {
'\\.[jt]sx?$': 'babel-jest',
'\\.mjs?$': 'babel-jest',
},
moduleNameMapper: {
'^app/(.*)$': '<rootDir>/app/$1',
},
};

const appConfig = {
displayName: 'App Tests',
testMatch: [
'<rootDir>/app/**/__tests__/**/*.[jt]s?(x)',
'<rootDir>/app/**/?(*.)+(spec|test).[jt]s?(x)',
],
testEnvironment: 'jsdom',
...sharedConfigs,
};

const clientConfig = {
displayName: 'Client Tests',
testMatch: [
'<rootDir>/client/**/__tests__/**/*.[jt]s?(x)',
'<rootDir>/client/**/?(*.)+(spec|test).[jt]s?(x)',
],
testEnvironment: 'jsdom',
...sharedConfigs,
};

const serverConfig = {
displayName: 'Server Tests',
testMatch: [
'<rootDir>/server/**/__tests__/**/*.[jt]s?(x)',
'<rootDir>/server/**/?(*.)+(spec|test).[jt]s?(x)',
],
testEnvironment: 'node',
...sharedConfigs,
};

module.exports = {
projects: [clientConfig, serverConfig, appConfig],
collectCoverage: true,
coverageDirectory: '__coverage__',
coverageThreshold: {
Expand All @@ -9,12 +50,4 @@ module.exports = {
statements: 100,
},
},
transform: {
'\\.[jt]sx?$': 'babel-jest',
'\\.mjs?$': 'babel-jest',
},
moduleNameMapper: {
'^app/(.*)$': '<rootDir>/app/$1',
},
testEnvironment: 'jsdom',
};
4 changes: 0 additions & 4 deletions server/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* @jest-environment node
*/

/* eslint global-require: 0 */
import express from 'express';
import { renderToPipeableStream } from 'react-dom/server';
Expand Down

0 comments on commit 3adc051

Please sign in to comment.