Skip to content

Commit ebfa31a

Browse files
committed
chore: move jest configuration to test folder
1 parent 90f0ee2 commit ebfa31a

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

jest.setup.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
}
125125
},
126126
"test": {
127-
"command": "$(npm bin)/jest",
127+
"command": "$(npm bin)/jest -c ./test/support/jest.config.js",
128128
"env": {
129129
"NODE_ENV": "test"
130130
}

jest.config.js renamed to test/support/jest.config.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const { mapValues, mapKeys } = require('lodash');
2-
const { _moduleAliases } = require('./package.json');
2+
const { _moduleAliases } = require('../../package.json');
3+
const escapeStringRegexp = require('escape-string-regexp');
4+
5+
const toRegex = (alias) => `^${escapeStringRegexp(alias)}/(.*)$`;
36

47
// Maps _moduleAliases in package.json to Jest's regex format that it can read
58
const moduleAliasesMap = mapValues(
6-
mapKeys(_moduleAliases, (_, alias) => `${alias}/(.*)$`),
9+
mapKeys(_moduleAliases, (_, alias) => toRegex(alias)),
710
path => `<rootDir>/${path}/$1`
811
);
912

@@ -15,8 +18,10 @@ const staticFiles =
1518
module.exports = {
1619
verbose: true,
1720
moduleFileExtensions: ['js', 'jsx'],
21+
rootDir: process.cwd(),
1822
snapshotSerializers: ['enzyme-to-json/serializer'],
19-
setupTestFrameworkScriptFile: '<rootDir>/jest.setup.js',
23+
setupTestFrameworkScriptFile: '<rootDir>/test/support/jest.setup.js',
24+
globalSetup: '<rootDir>/test/support/jest.globalSetup.js',
2025
moduleNameMapper: {
2126
...moduleAliasesMap,
2227
[staticFiles]: '<rootDir>/__mocks__/fileMock.js',

test/support/jest.globalSetup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = async () => {
2+
// This module can be used to do any sort of global setup before tests are
3+
// run, such as connecting to or seeding a database.
4+
};

test/support/jest.setup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { configure } from 'enzyme';
2+
import Adapter from 'enzyme-adapter-react-16';
3+
4+
// configure an adapter for enzyme
5+
configure({ adapter: new Adapter() });

0 commit comments

Comments
 (0)