Skip to content

Commit

Permalink
Merge pull request #16947 from webpack/chore-jest
Browse files Browse the repository at this point in the history
Update Jest to v29 and fix bugs with Jest not working past node 16
  • Loading branch information
TheLarkInn committed Apr 12, 2023
2 parents 0e0dab0 + 76f077b commit 4d2bdfc
Show file tree
Hide file tree
Showing 8 changed files with 624 additions and 795 deletions.
27 changes: 18 additions & 9 deletions .github/workflows/test.yml
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
36 changes: 32 additions & 4 deletions azure-pipelines.yml
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
19 changes: 12 additions & 7 deletions package.json
Expand Up @@ -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",
Expand Down Expand Up @@ -235,9 +236,13 @@
"<rootDir>/schemas",
"<rootDir>/node_modules"
],
"testEnvironment": "node",
"testEnvironment": "./test/patch-node-env.js",
"coverageReporters": [
"json"
]
],
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
}
}
3 changes: 2 additions & 1 deletion test/StatsTestCases.basictest.js
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/cases/json/import-assertions-type-json/errors.js
@@ -1,3 +1,3 @@
module.exports = [
[{ moduleName: /data.poison/, message: /Unexpected token .+ in JSON/ }]
[{ moduleName: /data.poison/, message: /Unexpected token .+ JSON/ }]
];
15 changes: 1 addition & 14 deletions test/helpers/createLazyTestEnv.js
@@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/patch-node-env.js
@@ -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;

0 comments on commit 4d2bdfc

Please sign in to comment.