Skip to content

Commit 37b2bd8

Browse files
committed
chore: configure jest
1 parent 3b276f7 commit 37b2bd8

File tree

6 files changed

+35
-0
lines changed

6 files changed

+35
-0
lines changed

__mocks__/file-mock.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

__mocks__/react-dom.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
...jest.requireActual('react-dom'),
3+
createPortal: (element) => element,
4+
};

jest-preprocess.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = require('babel-jest').createTransformer({
2+
presets: ['babel-preset-gatsby', '@emotion/babel-preset-css-prop'],
3+
});

jest.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
transform: {
3+
'^.+\\.jsx?$': '<rootDir>/jest-preprocess.js',
4+
},
5+
moduleNameMapper: {
6+
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
7+
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
8+
'<rootDir>/__mocks__/file-mock.js',
9+
},
10+
testPathIgnorePatterns: ['node_modules', '\\.cache', '<rootDir>.*/public'],
11+
transformIgnorePatterns: [
12+
'node_modules/(?!(gatsby)||@newrelic/gatsby-theme-newrelic||@elastic/react-search-ui-views/)',
13+
],
14+
globals: {
15+
__PATH_PREFIX__: '',
16+
},
17+
setupFiles: ['<rootDir>/loadershim.js'],
18+
setupFilesAfterEnv: ['<rootDir>/setup-test-env.js'],
19+
};

loadershim.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global.___loader = {
2+
enqueue: jest.fn(),
3+
};

setup-test-env.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* global expect */
2+
import { createSerializer } from 'jest-emotion';
3+
import * as emotion from '@emotion/core';
4+
5+
expect.addSnapshotSerializer(createSerializer(emotion));

0 commit comments

Comments
 (0)