From 32351b33c21da7a71428d22c04dc6edf207cfd23 Mon Sep 17 00:00:00 2001 From: alxshelepenok Date: Thu, 9 May 2019 00:11:44 +0300 Subject: [PATCH] chore: update mocks, move configs to jest dir --- {tests => jest}/__mocks__/fileMock.js | 0 jest/__mocks__/gatsby.js | 29 +++++++++++++++++++++++++++ {tests => jest}/jest-config.js | 3 ++- {tests => jest}/jest-preprocess.js | 6 +++++- jest/loadershim.js | 5 +++++ package.json | 7 ++++--- tests/__mocks__/gatsby.js | 10 --------- 7 files changed, 45 insertions(+), 15 deletions(-) rename {tests => jest}/__mocks__/fileMock.js (100%) create mode 100644 jest/__mocks__/gatsby.js rename {tests => jest}/jest-config.js (87%) rename {tests => jest}/jest-preprocess.js (77%) create mode 100644 jest/loadershim.js delete mode 100644 tests/__mocks__/gatsby.js diff --git a/tests/__mocks__/fileMock.js b/jest/__mocks__/fileMock.js similarity index 100% rename from tests/__mocks__/fileMock.js rename to jest/__mocks__/fileMock.js diff --git a/jest/__mocks__/gatsby.js b/jest/__mocks__/gatsby.js new file mode 100644 index 0000000..38c547f --- /dev/null +++ b/jest/__mocks__/gatsby.js @@ -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(), +}; diff --git a/tests/jest-config.js b/jest/jest-config.js similarity index 87% rename from tests/jest-config.js rename to jest/jest-config.js index 5425d27..41e60e6 100644 --- a/tests/jest-config.js +++ b/jest/jest-config.js @@ -17,5 +17,6 @@ module.exports = { globals: { __PATH_PREFIX__: '' }, - testURL: 'http://localhost/' + testURL: 'http://localhost/', + setupFiles: ['/tests/loadershim.js'] }; diff --git a/tests/jest-preprocess.js b/jest/jest-preprocess.js similarity index 77% rename from tests/jest-preprocess.js rename to jest/jest-preprocess.js index 9cd07d3..8fb3260 100644 --- a/tests/jest-preprocess.js +++ b/jest/jest-preprocess.js @@ -1,7 +1,11 @@ 'use strict'; const babelOptions = { - presets: ['@babel/react', '@babel/env'], + presets: [ + '@babel/react', + '@babel/env', + 'babel-preset-gatsby' + ], plugins: [ '@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-class-properties', diff --git a/jest/loadershim.js b/jest/loadershim.js new file mode 100644 index 0000000..82ce7b1 --- /dev/null +++ b/jest/loadershim.js @@ -0,0 +1,5 @@ +'use strict'; + +global.___loader = { + enqueue: jest.fn(), +}; diff --git a/package.json b/package.json index d1988f0..bd465fd 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "lint:js": "eslint --cache --ext .js,.jsx --ignore-pattern public .", "lint:scss": "stylelint \"src/**/*.scss\"", "lint": "concurrently \"yarn run lint:js\" \"yarn run lint:scss\" \"yarn flow\"", - "test": "jest --config ./tests/jest-config.js", - "test:coverage": "jest --coverage --config ./tests/jest-config.js", - "test:watch": "jest --watch --config ./tests/jest-config.js", + "test": "jest --config ./jest/jest-config.js", + "test:coverage": "jest --coverage --config ./jest/jest-config.js", + "test:watch": "jest --watch --config ./jest/jest-config.js", "release": "standard-version" }, "repository": "https://github.com/alxshelepenok/gatsby-starter-lumen", @@ -87,6 +87,7 @@ "@babel/plugin-transform-flow-strip-types": "^7.4.4", "@babel/preset-env": "7.4.4", "@babel/preset-react": "7.0.0", + "babel-preset-gatsby": "0.1.11", "autoprefixer": "9.5.1", "babel-core": "7.0.0-bridge.0", "babel-eslint": "10.0.1", diff --git a/tests/__mocks__/gatsby.js b/tests/__mocks__/gatsby.js deleted file mode 100644 index 8a10a62..0000000 --- a/tests/__mocks__/gatsby.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -const gatsby = jest.requireActual('gatsby'); - -module.exports = { - ...gatsby, - graphql: jest.fn(), - Link: 'Link', - StaticQuery: 'StaticQuery' -};