-
Notifications
You must be signed in to change notification settings - Fork 4k
/
jest.config.js
87 lines (84 loc) · 3.16 KB
/
jest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* External dependencies
*/
const glob = require( 'glob' ).sync;
const path = require( 'path' );
const defaultPlatform = 'android';
const rnPlatform = process.env.TEST_RN_PLATFORM || defaultPlatform;
if ( process.env.TEST_RN_PLATFORM ) {
// eslint-disable-next-line no-console
console.log( 'Setting RN platform to: ' + process.env.TEST_RN_PLATFORM );
} else {
// eslint-disable-next-line no-console
console.log( 'Setting RN platform to: default (' + defaultPlatform + ')' );
}
const transpiledPackageNames = glob( 'packages/*/src/index.{js,ts}' ).map(
( fileName ) => fileName.split( '/' )[ 1 ]
);
module.exports = {
verbose: true,
rootDir: '../../',
// Automatically clear mock calls and instances between every test.
clearMocks: true,
preset: 'react-native',
setupFiles: [ '<rootDir>/test/native/setup.js' ],
setupFilesAfterEnv: [ '<rootDir>/test/native/setup-after-env.js' ],
testMatch: [
'<rootDir>/test/**/*.native.[jt]s?(x)',
'<rootDir>/**/test/!(helper)*.native.[jt]s?(x)',
'<rootDir>/packages/react-native-*/**/?(*.)+(spec|test).[jt]s?(x)',
],
testPathIgnorePatterns: [ '/node_modules/', '/__device-tests__/' ],
testEnvironmentOptions: {
url: 'http://localhost/',
},
resolver: '<rootDir>/test/unit/scripts/resolver.js',
// Add the `Libraries/Utilities` subfolder to the module directories, otherwise haste/jest doesn't find Platform.js on Travis,
// and add it first so https://github.com/facebook/react-native/blob/v0.60.0/Libraries/react-native/react-native-implementation.js#L324-L326 doesn't pick up the Platform npm module.
moduleDirectories: [
'node_modules/react-native/Libraries/Utilities',
'node_modules',
],
moduleNameMapper: {
// Mock the CSS modules. See https://facebook.github.io/jest/docs/en/webpack.html#handling-static-assets
'\\.(scss)$': '<rootDir>/test/native/__mocks__/styleMock.js',
'\\.(eot|otf|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/test/native/__mocks__/fileMock.js',
[ `@wordpress\\/(${ transpiledPackageNames.join( '|' ) })$` ]:
'<rootDir>/packages/$1/src',
'test/helpers$': '<rootDir>/test/native/helpers.js',
},
modulePathIgnorePatterns: [
'<rootDir>/packages/react-native-editor/node_modules',
],
haste: {
defaultPlatform: rnPlatform,
platforms: [ 'android', 'ios', 'native' ],
},
transform: {
'\\.[jt]sx?$': [
'babel-jest',
// https://git.io/JYiYc
{
configFile: path.resolve( __dirname, 'babel.config.js' ),
},
],
},
transformIgnorePatterns: [
// This is required for now to have jest transform some of our modules
// See: https://github.com/wordpress-mobile/gutenberg-mobile/pull/257#discussion_r234978268
// There is no overloading in jest so we need to rewrite the config from react-native-jest-preset:
// https://github.com/facebook/react-native/blob/HEAD/jest-preset.json#L20
'node_modules/(?!(simple-html-tokenizer|(jest-)?react-native|@react-native|react-clone-referenced-element|@react-navigation))',
],
snapshotSerializers: [ '@emotion/jest/serializer' ],
snapshotFormat: {
escapeString: false,
printBasicPrototype: false,
},
reporters: [ 'default', 'jest-junit' ],
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
};