mirror of https://github.com/webpack/webpack.git
Merge pull request #16947 from webpack/chore-jest
Update Jest to v29 and fix bugs with Jest not working past node 16
This commit is contained in:
commit
4d2bdfc7c3
|
@ -24,9 +24,9 @@ jobs:
|
|||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 17.x
|
||||
node-version: 16.x
|
||||
cache: "yarn"
|
||||
- run: yarn --frozen-lockfile --ignore-engines
|
||||
- run: yarn --frozen-lockfile
|
||||
- uses: actions/cache@v3
|
||||
with:
|
||||
path: .eslintcache
|
||||
|
@ -40,9 +40,9 @@ jobs:
|
|||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 17.x
|
||||
node-version: 16.x
|
||||
cache: "yarn"
|
||||
- run: yarn --frozen-lockfile --ignore-engines
|
||||
- run: yarn --frozen-lockfile
|
||||
- run: yarn link --frozen-lockfile || true
|
||||
- run: yarn link webpack --frozen-lockfile
|
||||
- run: yarn test:basic --ci
|
||||
|
@ -59,6 +59,7 @@ jobs:
|
|||
with:
|
||||
node-version: 10.x
|
||||
cache: "yarn"
|
||||
# Remove `devDependencies` from `package.json` to avoid `yarn install` compatibility error
|
||||
- run: node -e "const content = require('./package.json');delete content.devDependencies;require('fs').writeFileSync('package.json', JSON.stringify(content, null, 2));"
|
||||
- run: yarn install --production --frozen-lockfile
|
||||
unit:
|
||||
|
@ -68,9 +69,9 @@ jobs:
|
|||
- name: Use Node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 17.x
|
||||
node-version: 16.x
|
||||
cache: "yarn"
|
||||
- run: yarn --frozen-lockfile --ignore-engines
|
||||
- run: yarn --frozen-lockfile
|
||||
- run: yarn link --frozen-lockfile || true
|
||||
- run: yarn link webpack --frozen-lockfile
|
||||
- uses: actions/cache@v3
|
||||
|
@ -89,9 +90,12 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
node-version: [10.x, 17.x]
|
||||
node-version: [10.x, 19.x]
|
||||
part: [a, b]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
node-version: 18.x
|
||||
part: a
|
||||
- os: ubuntu-latest
|
||||
node-version: 16.x
|
||||
part: a
|
||||
|
@ -109,8 +113,13 @@ jobs:
|
|||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: "yarn"
|
||||
# Using `--ignore-engines` for Node.js 10 and 12
|
||||
- run: yarn --frozen-lockfile --ignore-engines
|
||||
# Install old `jest` version and deps for legacy node versions
|
||||
- run: |
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 --ignore-engines
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
|
||||
- run: yarn --frozen-lockfile
|
||||
if: matrix.node-version != '10.x' && matrix.node-version != '12.x' && matrix.node-version != '14.x'
|
||||
- run: yarn link --frozen-lockfile || true
|
||||
- run: yarn link webpack --frozen-lockfile
|
||||
- uses: actions/cache@v3
|
||||
|
|
|
@ -27,7 +27,7 @@ jobs:
|
|||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
yarn --frozen-lockfile
|
||||
yarn link --frozen-lockfile || true
|
||||
yarn link webpack --frozen-lockfile
|
||||
displayName: "Install dependencies"
|
||||
|
@ -60,7 +60,7 @@ jobs:
|
|||
steps:
|
||||
- task: NodeTool@0
|
||||
inputs:
|
||||
versionSpec: "^14.0.0"
|
||||
versionSpec: "^16.0.0"
|
||||
displayName: "Install Node.js"
|
||||
- script: |
|
||||
curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
|
@ -79,7 +79,7 @@ jobs:
|
|||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
yarn --frozen-lockfile
|
||||
yarn link --frozen-lockfile || true
|
||||
yarn link webpack --frozen-lockfile
|
||||
displayName: "Install dependencies"
|
||||
|
@ -141,8 +141,15 @@ jobs:
|
|||
key: yarn | $(Agent.OS) | yarn.lock
|
||||
path: $(YARN_CACHE_FOLDER)
|
||||
displayName: "Cache Yarn packages"
|
||||
- script: yarn --frozen-lockfile --ignore-engines
|
||||
# Install old `jest` version and ignore platform problem for legacy node versions
|
||||
- script: |
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 --ignore-engines
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
displayName: "Install dependencies (old node.js version)"
|
||||
condition: or(eq(variables['node_version'], '^10.13.0'), eq(variables['node_version'], '^12.4.0'))
|
||||
- script: yarn --frozen-lockfile
|
||||
displayName: "Install dependencies"
|
||||
condition: and(not(eq(variables['node_version'], '^10.13.0')), not(eq(variables['node_version'], '^12.4.0')))
|
||||
- script: yarn link --frozen-lockfile || true
|
||||
displayName: "Link webpack"
|
||||
continueOnError: true
|
||||
|
@ -207,13 +214,24 @@ jobs:
|
|||
key: yarn | $(Agent.OS) | yarn.lock
|
||||
path: $(YARN_CACHE_FOLDER)
|
||||
displayName: "Cache Yarn packages"
|
||||
# Install old `jest` version and ignore platform problem for legacy node versions
|
||||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 --ignore-engines
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
yarn link --frozen-lockfile || true
|
||||
yarn link webpack --frozen-lockfile
|
||||
displayName: "Install dependencies (old node.js version)"
|
||||
condition: or(eq(variables['node_version'], '^10.13.0'), eq(variables['node_version'], '^12.4.0'), eq(variables['node_version'], '^14.0.0'))
|
||||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn --frozen-lockfile
|
||||
yarn link --frozen-lockfile || true
|
||||
yarn link webpack --frozen-lockfile
|
||||
displayName: "Install dependencies"
|
||||
condition: and(not(eq(variables['node_version'], '^10.13.0')), not(eq(variables['node_version'], '^12.4.0')), not(eq(variables['node_version'], '^14.0.0')))
|
||||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
|
@ -272,10 +290,20 @@ jobs:
|
|||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 --ignore-engines
|
||||
yarn --frozen-lockfile --ignore-engines
|
||||
yarn link --frozen-lockfile || true
|
||||
yarn link webpack --frozen-lockfile
|
||||
displayName: "Install dependencies (old node.js version)"
|
||||
condition: or(eq(variables['node_version'], '^10.13.0'), eq(variables['node_version'], '^12.4.0'))
|
||||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn --frozen-lockfile
|
||||
yarn link --frozen-lockfile || true
|
||||
yarn link webpack --frozen-lockfile
|
||||
displayName: "Install dependencies"
|
||||
condition: and(not(eq(variables['node_version'], '^10.13.0')), not(eq(variables['node_version'], '^12.4.0')))
|
||||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
|
|
19
package.json
19
package.json
|
@ -66,11 +66,12 @@
|
|||
"husky": "^8.0.3",
|
||||
"is-ci": "^3.0.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"jest": "^27.5.0",
|
||||
"jest-circus": "^27.5.0",
|
||||
"jest-cli": "^27.5.0",
|
||||
"jest-diff": "^27.5.0",
|
||||
"jest-junit": "^13.0.0",
|
||||
"jest": "^29.5.0",
|
||||
"jest-circus": "^29.5.0",
|
||||
"jest-cli": "^29.5.0",
|
||||
"jest-diff": "^29.5.0",
|
||||
"jest-environment-node": "^29.5.0",
|
||||
"jest-junit": "^15.0.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"json5": "^2.1.3",
|
||||
"less": "^4.0.0",
|
||||
|
@ -235,9 +236,13 @@
|
|||
"<rootDir>/schemas",
|
||||
"<rootDir>/node_modules"
|
||||
],
|
||||
"testEnvironment": "node",
|
||||
"testEnvironment": "./test/patch-node-env.js",
|
||||
"coverageReporters": [
|
||||
"json"
|
||||
]
|
||||
],
|
||||
"snapshotFormat": {
|
||||
"escapeString": true,
|
||||
"printBasicPrototype": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,7 +191,8 @@ describe("StatsTestCases", () => {
|
|||
.replace(/webpack [^ )]+(\)?) compiled/g, "webpack x.x.x$1 compiled")
|
||||
.replace(new RegExp(quoteMeta(testPath), "g"), "Xdir/" + testName)
|
||||
.replace(/(\w)\\(\w)/g, "$1/$2")
|
||||
.replace(/, additional resolving: X ms/g, "");
|
||||
.replace(/, additional resolving: X ms/g, "")
|
||||
.replace(/Unexpected identifier '.+?'/g, "Unexpected identifier");
|
||||
expect(actual).toMatchSnapshot();
|
||||
if (testConfig.validate) testConfig.validate(stats, stderr.toString());
|
||||
done();
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = [
|
||||
[{ moduleName: /data.poison/, message: /Unexpected token .+ in JSON/ }]
|
||||
[{ moduleName: /data.poison/, message: /Unexpected token .+ JSON/ }]
|
||||
];
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
const STATE_SYM = Object.getOwnPropertySymbols(global).find(
|
||||
Symbol("x").description
|
||||
? s => s.description === "JEST_STATE_SYMBOL"
|
||||
: s => s.toString() === "Symbol(JEST_STATE_SYMBOL)"
|
||||
);
|
||||
if (!STATE_SYM) {
|
||||
throw new Error(
|
||||
`Unable to find JEST_STATE_SYMBOL in ${Object.getOwnPropertySymbols(global)
|
||||
.map(s => s.toString())
|
||||
.join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = (globalTimeout = 2000, nameSuffix = "") => {
|
||||
const state = global[STATE_SYM];
|
||||
const state = global["JEST_STATE_SYMBOL"];
|
||||
let currentDescribeBlock;
|
||||
let currentlyRunningTest;
|
||||
let runTests = -1;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
const NodeEnvironment =
|
||||
// For jest@29
|
||||
require("jest-environment-node").TestEnvironment ||
|
||||
// For jest@27
|
||||
require("jest-environment-node");
|
||||
|
||||
class CustomEnvironment extends NodeEnvironment {
|
||||
constructor(config, context) {
|
||||
super(config, context);
|
||||
}
|
||||
|
||||
// Workaround for `Symbol('JEST_STATE_SYMBOL')`
|
||||
async handleTestEvent(event, state) {
|
||||
if (!this.global["JEST_STATE_SYMBOL"]) {
|
||||
this.global["JEST_STATE_SYMBOL"] = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CustomEnvironment;
|
Loading…
Reference in New Issue