chore: update mocks, move configs to jest dir

This commit is contained in:
alxshelepenok
2019-05-09 00:11:44 +03:00
parent 42d6377fde
commit 32351b33c2
7 changed files with 45 additions and 15 deletions

View File

@@ -0,0 +1,3 @@
'use strict';
module.exports = 'file';

29
jest/__mocks__/gatsby.js Normal file
View File

@@ -0,0 +1,29 @@
'use strict';
const React = require('react');
const gatsby = jest.requireActual('gatsby');
module.exports = {
...gatsby,
graphql: jest.fn(),
Link: jest.fn().mockImplementation(
({
activeClassName,
activeStyle,
getProps,
innerRef,
ref,
replace,
to,
...rest
}) => (
React.createElement('a', {
...rest,
href: to,
})
)
),
StaticQuery: jest.fn(),
useStaticQuery: jest.fn(),
};

22
jest/jest-config.js Normal file
View File

@@ -0,0 +1,22 @@
'use strict';
module.exports = {
rootDir: '../',
transform: {
'^.+\\.js?$': '<rootDir>/tests/jest-preprocess.js'
},
testMatch: ['**/__tests__/**/*.js', '**/?(*.)test.js'],
moduleNameMapper: {
'.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
'.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/tests/__mocks__/fileMock.js'
},
testPathIgnorePatterns: ['node_modules', '.cache', 'public'],
transformIgnorePatterns: [
'node_modules/(?!(gatsby)/)'
],
globals: {
__PATH_PREFIX__: ''
},
testURL: 'http://localhost/',
setupFiles: ['<rootDir>/tests/loadershim.js']
};

16
jest/jest-preprocess.js Normal file
View File

@@ -0,0 +1,16 @@
'use strict';
const babelOptions = {
presets: [
'@babel/react',
'@babel/env',
'babel-preset-gatsby'
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-flow-strip-types',
],
};
module.exports = require('babel-jest').createTransformer(babelOptions);

5
jest/loadershim.js Normal file
View File

@@ -0,0 +1,5 @@
'use strict';
global.___loader = {
enqueue: jest.fn(),
};