diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 258fe9b14..c56b9c70c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -89,9 +89,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 @@ -110,7 +113,7 @@ jobs: node-version: ${{ matrix.node-version }} cache: "yarn" - run: yarn upgrade jest@^27.5.0 jest-circus@27.5.0 jest-cli@27.5.0 jest-diff@27.5.0 jest-junit@13.0.0 - if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '17.x' + if: matrix.node-version == '10.x' || matrix.node-version == '12.x' - run: yarn --frozen-lockfile if: matrix.node-version == '10.x' || matrix.node-version == '12.x' - run: yarn link --frozen-lockfile || true diff --git a/package.json b/package.json index 08970df5f..2846dc9ec 100644 --- a/package.json +++ b/package.json @@ -235,7 +235,7 @@ "/schemas", "/node_modules" ], - "testEnvironment": "node", + "testEnvironment": "./test/patch-node-env.js", "coverageReporters": [ "json" ], diff --git a/test/helpers/createLazyTestEnv.js b/test/helpers/createLazyTestEnv.js index c16f32ee5..518f97d52 100644 --- a/test/helpers/createLazyTestEnv.js +++ b/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; diff --git a/test/patch-node-env.js b/test/patch-node-env.js new file mode 100644 index 000000000..3d40db111 --- /dev/null +++ b/test/patch-node-env.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line node/no-extraneous-require +const NodeEnvironment = require("jest-environment-node").TestEnvironment; + +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;