From c070aeb7f411fb1d22ae13e8f1f9b3b6b5529b04 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 4 Nov 2020 21:03:37 +0800 Subject: [PATCH] chore: use env variable to choose the webpack version to test --- jest-webpack5.config.js | 15 --------------- jest.config.js | 20 +++++++++++++++++++- package.json | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) delete mode 100644 jest-webpack5.config.js diff --git a/jest-webpack5.config.js b/jest-webpack5.config.js deleted file mode 100644 index 5776742dd..000000000 --- a/jest-webpack5.config.js +++ /dev/null @@ -1,15 +0,0 @@ -const config = require('./jest.config') - -module.exports = { - ...config, - - globals: { - 'ts-jest': { - diagnostics: false, - }, - }, - moduleNameMapper: { - '^webpack$': 'webpack5', - '^webpack/(.*)': 'webpack5/$1', - }, -} diff --git a/jest.config.js b/jest.config.js index 245053594..e87a53ff1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,6 +1,24 @@ -module.exports = { +const config = { preset: 'ts-jest', testTimeout: 10000, testEnvironment: 'node', testPathIgnorePatterns: ['/dist/', '/node_modules/'], } + +if (process.env.WEBPACK5) { + module.exports = { + ...config, + + globals: { + 'ts-jest': { + diagnostics: false, + }, + }, + moduleNameMapper: { + '^webpack$': 'webpack5', + '^webpack/(.*)': 'webpack5/$1', + }, + } +} else { + module.exports = config +} diff --git a/package.json b/package.json index a07e7bb48..4c4891cef 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "tsc", "pretest": "tsc", "test": "jest --coverage", - "test:webpack5": "jest -c jest-webpack5.config.js --coverage", + "test:webpack5": "WEBPACK5=true jest -c --coverage", "dev-example": "webpack-dev-server --config example/webpack.config.js --inline --hot", "build-example": "rm -rf example/dist && webpack --config example/webpack.config.js --env.prod", "lint": "prettier --write --parser typescript \"{src,test}/**/*.{j,t}s\"",