From 1c751472b22a34870bdcdfb03280afeff8770ea4 Mon Sep 17 00:00:00 2001 From: Konstantin Vyatkin Date: Tue, 29 Oct 2019 10:05:37 -0400 Subject: [PATCH] [Tooling] Transpile tests targeting Node, not browser (#700) * transplite tests for higher target * fix test * add to lint-stagged too --- .babelrc | 16 +++++++++++++++- lint-staged.config.js | 2 +- package.json | 6 +++--- src/scripts/choices.test.js | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.babelrc b/.babelrc index e9e94c2..de74bdc 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,17 @@ { - "presets": [["@babel/preset-env", { "loose": true }]] + "presets": [["@babel/preset-env", { "loose": true }]], + "env": { + "test": { + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": true + } + } + ] + ] + } + } } diff --git a/lint-staged.config.js b/lint-staged.config.js index 14c24f3..ed07144 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -10,5 +10,5 @@ module.exports = { ], '.codecov.yml': () => 'curl -f --silent --data-binary @.codecov.yml https://codecov.io/validate', - 'src/scripts/**/*.js': () => 'mocha', + 'src/scripts/**/*.js': () => 'npm run test:unit', }; diff --git a/package.json b/package.json index 7dc7242..4cbf8e0 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,14 @@ "start": "run-p js:watch css:watch", "build": "run-p js:build css:build", "lint": "eslint src/scripts", - "coverage": "nyc --reporter=lcov --reporter=text --reporter=text-summary mocha", + "coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha", "bundlesize": "bundlesize", "cypress:run": "$(npm bin)/cypress run", "cypress:open": "$(npm bin)/cypress open", "cypress:ci": "cypress run --record --group --ci-build-id $GITHUB_SHA", "test": "run-s test:unit test:e2e", - "test:unit": "mocha", - "test:unit:watch": "mocha --watch --inspect=5556", + "test:unit": "NODE_ENV=test mocha", + "test:unit:watch": "NODE_ENV=test mocha --watch --inspect=5556", "test:e2e": "run-p --race start cypress:run", "js:watch": "NODE_ENV=development node server.js", "js:build": "webpack --config webpack.config.prod.js", diff --git a/src/scripts/choices.test.js b/src/scripts/choices.test.js index bb286e4..71e116c 100644 --- a/src/scripts/choices.test.js +++ b/src/scripts/choices.test.js @@ -1331,7 +1331,7 @@ describe('choices', () => { ...choices[0], choices, }, - ...choices[1], + choices[1], ]; beforeEach(() => {