diff --git a/jest.config.js b/jest.config.js index 20d39ad9..3017fba1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ module.exports = { rootDir: './src', + automock: false, coverageDirectory: 'coverage/', collectCoverage: true, testURL: 'http://localhost', @@ -10,4 +11,7 @@ module.exports = { collectCoverageFrom: [ 'utils/**.js', ], + setupFiles: [ + './support/setupJest.js', + ], }; diff --git a/package.json b/package.json index 2f7113b0..3467d307 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "flow-webpack-plugin": "^1.2.0", "hdkey": "^0.8.0", "html-webpack-plugin": "^3.2.0", + "jest-fetch-mock": "^1.6.5", "npm-run-all": "^4.1.3", "prop-types": "^15.6.2", "raf": "^3.4.0", diff --git a/src/support/setupJest.js b/src/support/setupJest.js new file mode 100644 index 00000000..8e88457e --- /dev/null +++ b/src/support/setupJest.js @@ -0,0 +1 @@ +global.fetch = require('jest-fetch-mock'); \ No newline at end of file diff --git a/src/utils/__tests__/networkUtils.test.js b/src/utils/__tests__/networkUtils.test.js new file mode 100644 index 00000000..190707ce --- /dev/null +++ b/src/utils/__tests__/networkUtils.test.js @@ -0,0 +1,15 @@ +import * as networkUtils from '../networkUtils'; + +describe('network utils', () => { + beforeEach(() => { + fetch.resetMocks(); + }); + + it('httpRequest', () => { + + }); + + it('JSONRequest', () => { + + }); +}); diff --git a/src/utils/networkUtils.js b/src/utils/networkUtils.js index 360168d9..fc29250b 100644 --- a/src/utils/networkUtils.js +++ b/src/utils/networkUtils.js @@ -1,6 +1,5 @@ /* @flow */ - import 'whatwg-fetch'; export const httpRequest = async (url: string, type: string = 'text'): any => { @@ -15,16 +14,6 @@ export const httpRequest = async (url: string, type: string = 'text'): any => { await response.text(); } throw new Error(`${url} ${response.statusText}`); - - - // return fetch(url, { credentials: 'same-origin' }).then((response) => { - // if (response.status === 200) { - - // return response.text().then(result => (json ? JSON.parse(result) : result)); - // } else { - // throw new Error(response.statusText); - // } - // }) }; export const JSONRequest = async (url: string): Promise => { diff --git a/webpack/dev.babel.js b/webpack/dev.babel.js index 484f9e33..9bd1123f 100644 --- a/webpack/dev.babel.js +++ b/webpack/dev.babel.js @@ -48,6 +48,7 @@ module.exports = { { loader: 'stylelint-custom-processor-loader', options: { + emitWarning: true, configPath: '.stylelintrc', }, }, diff --git a/webpack/local.babel.js b/webpack/local.babel.js index 93e9d5cb..db71f539 100644 --- a/webpack/local.babel.js +++ b/webpack/local.babel.js @@ -59,6 +59,7 @@ module.exports = { { loader: 'stylelint-custom-processor-loader', options: { + emitWarning: true, configPath: '.stylelintrc', }, }, diff --git a/yarn.lock b/yarn.lock index 46ed0785..435da204 100644 --- a/yarn.lock +++ b/yarn.lock @@ -255,6 +255,10 @@ version "0.7.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.7.0.tgz#9a06f4f137ee84d7df0460c1fdb1135ffa6c50fd" +"@types/jest@^23.0.0": + version "23.3.2" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.3.2.tgz#07b90f6adf75d42c34230c026a2529e56c249dbb" + "@webassemblyjs/ast@1.5.13": version "1.5.13" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.5.13.tgz#81155a570bd5803a30ec31436bc2c9c0ede38f25" @@ -5330,7 +5334,7 @@ isobject@^3.0.0, isobject@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df" -isomorphic-fetch@^2.1.1: +isomorphic-fetch@^2.1.1, isomorphic-fetch@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9" dependencies: @@ -5522,6 +5526,14 @@ jest-environment-node@^23.4.0: jest-mock "^23.2.0" jest-util "^23.4.0" +jest-fetch-mock@^1.6.5: + version "1.6.5" + resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-1.6.5.tgz#178fa1a937ef6f61fb8e8483b6d4602b17e0d96d" + dependencies: + "@types/jest" "^23.0.0" + isomorphic-fetch "^2.2.1" + promise-polyfill "^7.1.1" + jest-get-type@^22.1.0: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" @@ -7711,6 +7723,10 @@ promise-inflight@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" +promise-polyfill@^7.1.1: + version "7.1.2" + resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-7.1.2.tgz#ab05301d8c28536301622d69227632269a70ca3b" + promise@^7.1.1: version "7.3.1" resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"