diff --git a/.azure-pipelines-steps.yml b/.azure-pipelines-steps.yml index 573a5f650397..ca30fe83d8c4 100644 --- a/.azure-pipelines-steps.yml +++ b/.azure-pipelines-steps.yml @@ -6,11 +6,11 @@ steps: - checkout: self path: jest - # Ensure Node.js 12 is active + # Ensure Node.js 14 is active - task: NodeTool@0 inputs: - versionSpec: '12.x' - displayName: 'Use Node.js 12' + versionSpec: '14.x' + displayName: 'Use Node.js 14' # Ensure Python 2.7 is active - task: UsePythonVersion@0 @@ -27,7 +27,7 @@ steps: path: $(yarnCache.folder) displayName: Cache Yarn packages - - script: yarn install + - script: yarn install --immutable displayName: 'Install dependencies' - script: yarn build:js diff --git a/.circleci/config.yml b/.circleci/config.yml index c1df85935a23..778bfd690351 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ aliases: ignore: gh-pages - &install pkg-manager: yarn - override-ci-command: yarn install && yarn build:js + override-ci-command: yarn install --immutable && yarn build:js cache-path: ~/.yarn/berry/cache include-branch-in-cache-key: false app-dir: ~/jest @@ -51,7 +51,7 @@ jobs: install-npm: false - node/install-packages: *install - run: - command: yarn test-ci + command: yarn test-ci-partial - store_test_results: path: reports/junit @@ -79,7 +79,7 @@ jobs: install-npm: false - node/install-packages: *install - run: - command: yarn test-ci-partial + command: yarn test-ci - store_test_results: path: reports/junit diff --git a/.circleci/website.sh b/.circleci/website.sh index b20b2d567c59..01dfb8aa6af1 100755 --- a/.circleci/website.sh +++ b/.circleci/website.sh @@ -13,7 +13,7 @@ else git config --global user.name "Website Deployment Script" echo "machine github.com login docusaurus-bot password $DOCUSAURUS_PUBLISH_TOKEN" > ~/.netrc # install Docusaurus and generate file of English strings - yarn && cd website && node fetchSupporters.js && yarn write-translations + yarn --immutable && cd website && node fetchSupporters.js && yarn write-translations # crowdin install sudo apt-get update sudo apt-get install default-jre rsync @@ -30,6 +30,6 @@ else GIT_USER=docusaurus-bot USE_SSH=false yarn publish-gh-pages else echo "Skipping deploy. Test website build" - cd website && yarn && node fetchSupporters.js && yarn build + yarn --immutable && cd website && node fetchSupporters.js && yarn build fi fi diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 2cdf9ab3b869..e8be810c51c9 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -36,7 +36,7 @@ jobs: with: node-version: 12.x - name: install - run: yarn + run: yarn --immutable - name: build run: yarn build - name: test typings @@ -80,7 +80,7 @@ jobs: with: node-version: ${{ matrix.node-version }} - name: install - run: yarn + run: yarn --immutable - name: build run: yarn build:js - name: Get number of CPU cores diff --git a/e2e/Utils.ts b/e2e/Utils.ts index c8d20585e834..e91c4df6fc0f 100644 --- a/e2e/Utils.ts +++ b/e2e/Utils.ts @@ -44,15 +44,20 @@ export const run = ( return result; }; -export const runYarn = (cwd: Config.Path, env?: Record) => { +export const runYarnInstall = ( + cwd: Config.Path, + env?: Record, +) => { const lockfilePath = path.resolve(cwd, 'yarn.lock'); + let exists = true; // If the lockfile doesn't exist, yarn's project detection is confused. Just creating an empty file works if (!fs.existsSync(lockfilePath)) { + exists = false; fs.writeFileSync(lockfilePath, ''); } - return run('yarn', cwd, env); + return run(exists ? 'yarn install --immutable' : 'yarn install', cwd, env); }; export const linkJestPackage = (packageName: string, cwd: Config.Path) => { diff --git a/e2e/__tests__/asyncRegenerator.test.ts b/e2e/__tests__/asyncRegenerator.test.ts index cbad304f0256..684ef69b179a 100644 --- a/e2e/__tests__/asyncRegenerator.test.ts +++ b/e2e/__tests__/asyncRegenerator.test.ts @@ -6,13 +6,13 @@ */ import * as path from 'path'; -import {runYarn} from '../Utils'; +import {runYarnInstall} from '../Utils'; import {json as runWithJson} from '../runJest'; const dir = path.resolve(__dirname, '../async-regenerator'); beforeEach(() => { - runYarn(dir); + runYarnInstall(dir); }); test('successfully transpiles async', () => { diff --git a/e2e/__tests__/babelPluginJestHoist.test.ts b/e2e/__tests__/babelPluginJestHoist.test.ts index 31f0d62326d6..c47a2546859c 100644 --- a/e2e/__tests__/babelPluginJestHoist.test.ts +++ b/e2e/__tests__/babelPluginJestHoist.test.ts @@ -6,13 +6,13 @@ */ import * as path from 'path'; -import {runYarn} from '../Utils'; +import {runYarnInstall} from '../Utils'; import {json as runWithJson} from '../runJest'; const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist'); beforeEach(() => { - runYarn(DIR); + runYarnInstall(DIR); }); it('successfully runs the tests inside `babel-plugin-jest-hoist/`', () => { diff --git a/e2e/__tests__/chaiAssertionLibrary.ts b/e2e/__tests__/chaiAssertionLibrary.ts index 9cad190a4353..8d7b77d0086f 100644 --- a/e2e/__tests__/chaiAssertionLibrary.ts +++ b/e2e/__tests__/chaiAssertionLibrary.ts @@ -7,12 +7,12 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; test('chai assertion errors should display properly', () => { const dir = path.resolve(__dirname, '../chai-assertion-library-errors'); - runYarn(dir); + runYarnInstall(dir); const {stderr} = runJest('chai-assertion-library-errors'); const {rest} = extractSummary(stderr); diff --git a/e2e/__tests__/console.test.ts b/e2e/__tests__/console.test.ts index b83ef9f70229..0030d2a4eff1 100644 --- a/e2e/__tests__/console.test.ts +++ b/e2e/__tests__/console.test.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; test('console printing', () => { @@ -99,7 +99,7 @@ test('the jsdom console is the same as the test console', () => { test('does not error out when using winston', () => { const dir = path.resolve(__dirname, '../console-winston'); - runYarn(dir); + runYarnInstall(dir); const {stderr, stdout, exitCode} = runJest(dir); const {summary, rest} = extractSummary(stderr); diff --git a/e2e/__tests__/coverageHandlebars.test.ts b/e2e/__tests__/coverageHandlebars.test.ts index 2c30ba13601f..3a1cf3be05c7 100644 --- a/e2e/__tests__/coverageHandlebars.test.ts +++ b/e2e/__tests__/coverageHandlebars.test.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import {readFileSync} from 'graceful-fs'; import wrap from 'jest-snapshot-serializer-raw'; -import {cleanup, runYarn} from '../Utils'; +import {cleanup, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '../coverage-handlebars'); @@ -19,7 +19,7 @@ beforeAll(() => { }); it('code coverage for Handlebars', () => { - runYarn(dir); + runYarnInstall(dir); const result = runJest(dir, ['--coverage', '--no-cache']); expect(result.exitCode).toBe(0); diff --git a/e2e/__tests__/coverageRemapping.test.ts b/e2e/__tests__/coverageRemapping.test.ts index 6312ddbdf726..7830ee8a7876 100644 --- a/e2e/__tests__/coverageRemapping.test.ts +++ b/e2e/__tests__/coverageRemapping.test.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import {readFileSync} from 'graceful-fs'; -import {cleanup, runYarn} from '../Utils'; +import {cleanup, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '../coverage-remapping'); @@ -18,7 +18,7 @@ beforeAll(() => { }); it('maps code coverage against original source', () => { - runYarn(dir); + runYarnInstall(dir); const result = runJest(dir, ['--coverage', '--no-cache']); expect(result.exitCode).toBe(0); diff --git a/e2e/__tests__/coverageReport.test.ts b/e2e/__tests__/coverageReport.test.ts index 9ab9a82d3cfd..b268c60d2d16 100644 --- a/e2e/__tests__/coverageReport.test.ts +++ b/e2e/__tests__/coverageReport.test.ts @@ -8,13 +8,13 @@ import * as path from 'path'; import * as fs from 'graceful-fs'; import {wrap} from 'jest-snapshot-serializer-raw'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const DIR = path.resolve(__dirname, '../coverage-report'); beforeAll(() => { - runYarn(DIR); + runYarnInstall(DIR); }); test('outputs coverage report', () => { diff --git a/e2e/__tests__/coverageTransformInstrumented.test.ts b/e2e/__tests__/coverageTransformInstrumented.test.ts index d9002375d2a4..7e7898959769 100644 --- a/e2e/__tests__/coverageTransformInstrumented.test.ts +++ b/e2e/__tests__/coverageTransformInstrumented.test.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import {readFileSync} from 'graceful-fs'; -import {cleanup, runYarn} from '../Utils'; +import {cleanup, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '../coverage-transform-instrumented'); @@ -18,7 +18,7 @@ beforeAll(() => { }); it('code coverage for transform instrumented code', () => { - runYarn(dir); + runYarnInstall(dir); const result = runJest(dir, ['--coverage', '--no-cache']); expect(result.exitCode).toBe(0); diff --git a/e2e/__tests__/expectAsyncMatcher.test.ts b/e2e/__tests__/expectAsyncMatcher.test.ts index e8c71ae418b2..f9b19723dcd5 100644 --- a/e2e/__tests__/expectAsyncMatcher.test.ts +++ b/e2e/__tests__/expectAsyncMatcher.test.ts @@ -7,13 +7,13 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '../expect-async-matcher'); beforeAll(() => { - runYarn(dir); + runYarnInstall(dir); }); test('works with passing tests', () => { diff --git a/e2e/__tests__/failures.test.ts b/e2e/__tests__/failures.test.ts index f0e2c906712b..48c96cc974b3 100644 --- a/e2e/__tests__/failures.test.ts +++ b/e2e/__tests__/failures.test.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '../failures'); @@ -24,7 +24,7 @@ function cleanStderr(stderr: string) { const nodeMajorVersion = Number(process.versions.node.split('.')[0]); beforeAll(() => { - runYarn(dir); + runYarnInstall(dir); }); test('not throwing Error objects', () => { diff --git a/e2e/__tests__/globalSetup.test.ts b/e2e/__tests__/globalSetup.test.ts index a37e5063808b..a7b993b4ba84 100644 --- a/e2e/__tests__/globalSetup.test.ts +++ b/e2e/__tests__/globalSetup.test.ts @@ -8,7 +8,7 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; -import {cleanup, runYarn} from '../Utils'; +import {cleanup, runYarnInstall} from '../Utils'; import runJest, {json as runWithJson} from '../runJest'; const DIR = path.join(tmpdir(), 'jest-global-setup'); @@ -22,7 +22,7 @@ const nodeModulesDIR = path.join(tmpdir(), 'jest-global-setup-node-modules'); const e2eDir = path.resolve(__dirname, '../global-setup'); beforeAll(() => { - runYarn(e2eDir); + runYarnInstall(e2eDir); }); beforeEach(() => { diff --git a/e2e/__tests__/globalTeardown.test.ts b/e2e/__tests__/globalTeardown.test.ts index 1d1b229e5474..a3947ef1c337 100644 --- a/e2e/__tests__/globalTeardown.test.ts +++ b/e2e/__tests__/globalTeardown.test.ts @@ -9,7 +9,7 @@ import {tmpdir} from 'os'; import * as path from 'path'; import * as fs from 'graceful-fs'; import {createDirectory} from 'jest-util'; -import {cleanup, runYarn} from '../Utils'; +import {cleanup, runYarnInstall} from '../Utils'; import runJest, {json as runWithJson} from '../runJest'; const DIR = path.join(tmpdir(), 'jest-global-teardown'); @@ -18,7 +18,7 @@ const project2DIR = path.join(tmpdir(), 'jest-global-teardown-project-2'); const e2eDir = path.resolve(__dirname, '../global-teardown'); beforeAll(() => { - runYarn(e2eDir); + runYarnInstall(e2eDir); }); beforeEach(() => { diff --git a/e2e/__tests__/nativeAsyncMock.test.ts b/e2e/__tests__/nativeAsyncMock.test.ts index dcd321d03358..e0e43cb1d02e 100644 --- a/e2e/__tests__/nativeAsyncMock.test.ts +++ b/e2e/__tests__/nativeAsyncMock.test.ts @@ -6,7 +6,7 @@ */ import * as path from 'path'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; const dir = path.resolve(__dirname, '..', 'native-async-mock'); @@ -16,7 +16,7 @@ test('mocks async functions', () => { return; } - runYarn(dir); + runYarnInstall(dir); // --no-cache because babel can cache stuff and result in false green const {stderr} = runJest(dir, ['--no-cache']); diff --git a/e2e/__tests__/pnp.test.ts b/e2e/__tests__/pnp.test.ts index 9c419592ce07..89918a4f3b41 100644 --- a/e2e/__tests__/pnp.test.ts +++ b/e2e/__tests__/pnp.test.ts @@ -6,13 +6,13 @@ */ import * as path from 'path'; -import {runYarn} from '../Utils'; +import {runYarnInstall} from '../Utils'; import {json as runWithJson} from '../runJest'; const DIR = path.resolve(__dirname, '..', 'pnp'); beforeEach(() => { - runYarn(DIR, {YARN_NODE_LINKER: 'pnp'}); + runYarnInstall(DIR, {YARN_NODE_LINKER: 'pnp'}); }); it('successfully runs the tests inside `pnp/`', () => { diff --git a/e2e/__tests__/stackTraceSourceMaps.test.ts b/e2e/__tests__/stackTraceSourceMaps.test.ts index be0f05d663fc..2f689ce37bd3 100644 --- a/e2e/__tests__/stackTraceSourceMaps.test.ts +++ b/e2e/__tests__/stackTraceSourceMaps.test.ts @@ -6,12 +6,12 @@ */ import * as path from 'path'; -import {runYarn} from '../Utils'; +import {runYarnInstall} from '../Utils'; import runJest from '../runJest'; it('processes stack traces and code frames with source maps', () => { const dir = path.resolve(__dirname, '../stack-trace-source-maps'); - runYarn(dir); + runYarnInstall(dir); const {stderr} = runJest(dir, ['--no-cache']); expect(stderr).toMatch('> 15 | (() => expect(false).toBe(true))();'); expect(stderr).toMatch(`at __tests__/fails.ts:15:24 diff --git a/e2e/__tests__/stackTraceSourceMapsWithCoverage.test.ts b/e2e/__tests__/stackTraceSourceMapsWithCoverage.test.ts index 8a1b3f207b44..192ad7103909 100644 --- a/e2e/__tests__/stackTraceSourceMapsWithCoverage.test.ts +++ b/e2e/__tests__/stackTraceSourceMapsWithCoverage.test.ts @@ -6,7 +6,7 @@ */ import * as path from 'path'; import wrap from 'jest-snapshot-serializer-raw'; -import {extractSummary, runYarn} from '../Utils'; +import {extractSummary, runYarnInstall} from '../Utils'; import runJest from '../runJest'; it('processes stack traces and code frames with source maps with coverage', () => { @@ -14,7 +14,7 @@ it('processes stack traces and code frames with source maps with coverage', () = __dirname, '../stack-trace-source-maps-with-coverage', ); - runYarn(dir); + runYarnInstall(dir); const {stderr} = runJest(dir, ['--no-cache', '--coverage']); // Should report an error at source line 13 in lib.ts at line 10 of the test diff --git a/e2e/__tests__/transform.test.ts b/e2e/__tests__/transform.test.ts index db68750b7d86..c906f94333ca 100644 --- a/e2e/__tests__/transform.test.ts +++ b/e2e/__tests__/transform.test.ts @@ -14,7 +14,7 @@ import { createEmptyPackage, extractSummary, linkJestPackage, - runYarn, + runYarnInstall, } from '../Utils'; import runJest, {json as runWithJson} from '../runJest'; @@ -22,7 +22,7 @@ describe('babel-jest', () => { const dir = path.resolve(__dirname, '..', 'transform/babel-jest'); beforeEach(() => { - runYarn(dir); + runYarnInstall(dir); }); it('runs transpiled code', () => { @@ -59,7 +59,7 @@ describe('babel-jest with manual transformer', () => { const dir = path.resolve(__dirname, '..', 'transform/babel-jest-manual'); beforeEach(() => { - runYarn(dir); + runYarnInstall(dir); }); it('runs transpiled code', () => { @@ -133,7 +133,7 @@ describe('multiple-transformers', () => { const dir = path.resolve(__dirname, '..', 'transform/multiple-transformers'); beforeEach(() => { - runYarn(dir); + runYarnInstall(dir); }); it('transforms dependencies using specific transformers', () => { @@ -164,7 +164,7 @@ describe('transformer-config', () => { const dir = path.resolve(__dirname, '..', 'transform/transformer-config'); beforeEach(() => { - runYarn(dir); + runYarnInstall(dir); }); it('runs transpiled code', () => { diff --git a/e2e/__tests__/typescriptCoverage.test.ts b/e2e/__tests__/typescriptCoverage.test.ts index 2fdd327d31fc..f22e76c209f1 100644 --- a/e2e/__tests__/typescriptCoverage.test.ts +++ b/e2e/__tests__/typescriptCoverage.test.ts @@ -7,12 +7,12 @@ import * as path from 'path'; import {wrap} from 'jest-snapshot-serializer-raw'; -import {runYarn} from '../Utils'; +import {runYarnInstall} from '../Utils'; import runJest from '../runJest'; it('instruments and collects coverage for typescript files', () => { const dir = path.resolve(__dirname, '../typescript-coverage'); - runYarn(dir); + runYarnInstall(dir); const {stdout} = runJest(dir, ['--coverage', '--no-cache'], { stripAnsi: true, });