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

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(),
};

View File

@ -17,5 +17,6 @@ module.exports = {
globals: { globals: {
__PATH_PREFIX__: '' __PATH_PREFIX__: ''
}, },
testURL: 'http://localhost/' testURL: 'http://localhost/',
setupFiles: ['<rootDir>/tests/loadershim.js']
}; };

View File

@ -1,7 +1,11 @@
'use strict'; 'use strict';
const babelOptions = { const babelOptions = {
presets: ['@babel/react', '@babel/env'], presets: [
'@babel/react',
'@babel/env',
'babel-preset-gatsby'
],
plugins: [ plugins: [
'@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-class-properties',

5
jest/loadershim.js Normal file
View File

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

View File

@ -12,9 +12,9 @@
"lint:js": "eslint --cache --ext .js,.jsx --ignore-pattern public .", "lint:js": "eslint --cache --ext .js,.jsx --ignore-pattern public .",
"lint:scss": "stylelint \"src/**/*.scss\"", "lint:scss": "stylelint \"src/**/*.scss\"",
"lint": "concurrently \"yarn run lint:js\" \"yarn run lint:scss\" \"yarn flow\"", "lint": "concurrently \"yarn run lint:js\" \"yarn run lint:scss\" \"yarn flow\"",
"test": "jest --config ./tests/jest-config.js", "test": "jest --config ./jest/jest-config.js",
"test:coverage": "jest --coverage --config ./tests/jest-config.js", "test:coverage": "jest --coverage --config ./jest/jest-config.js",
"test:watch": "jest --watch --config ./tests/jest-config.js", "test:watch": "jest --watch --config ./jest/jest-config.js",
"release": "standard-version" "release": "standard-version"
}, },
"repository": "https://github.com/alxshelepenok/gatsby-starter-lumen", "repository": "https://github.com/alxshelepenok/gatsby-starter-lumen",
@ -87,6 +87,7 @@
"@babel/plugin-transform-flow-strip-types": "^7.4.4", "@babel/plugin-transform-flow-strip-types": "^7.4.4",
"@babel/preset-env": "7.4.4", "@babel/preset-env": "7.4.4",
"@babel/preset-react": "7.0.0", "@babel/preset-react": "7.0.0",
"babel-preset-gatsby": "0.1.11",
"autoprefixer": "9.5.1", "autoprefixer": "9.5.1",
"babel-core": "7.0.0-bridge.0", "babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1", "babel-eslint": "10.0.1",

View File

@ -1,10 +0,0 @@
'use strict';
const gatsby = jest.requireActual('gatsby');
module.exports = {
...gatsby,
graphql: jest.fn(),
Link: 'Link',
StaticQuery: 'StaticQuery'
};