Skip to content

Commit 36a9434

Browse files
authored
chore: run yarn with immutable flag (#10767)
1 parent 1dbdd67 commit 36a9434

23 files changed

+57
-52
lines changed

.azure-pipelines-steps.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ steps:
66
- checkout: self
77
path: jest
88

9-
# Ensure Node.js 12 is active
9+
# Ensure Node.js 14 is active
1010
- task: NodeTool@0
1111
inputs:
12-
versionSpec: '12.x'
13-
displayName: 'Use Node.js 12'
12+
versionSpec: '14.x'
13+
displayName: 'Use Node.js 14'
1414

1515
# Ensure Python 2.7 is active
1616
- task: UsePythonVersion@0
@@ -27,7 +27,7 @@ steps:
2727
path: $(yarnCache.folder)
2828
displayName: Cache Yarn packages
2929

30-
- script: yarn install
30+
- script: yarn install --immutable
3131
displayName: 'Install dependencies'
3232

3333
- script: yarn build:js

.circleci/config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ aliases:
44
ignore: gh-pages
55
- &install
66
pkg-manager: yarn
7-
override-ci-command: yarn install && yarn build:js
7+
override-ci-command: yarn install --immutable && yarn build:js
88
cache-path: ~/.yarn/berry/cache
99
include-branch-in-cache-key: false
1010
app-dir: ~/jest
@@ -51,7 +51,7 @@ jobs:
5151
install-npm: false
5252
- node/install-packages: *install
5353
- run:
54-
command: yarn test-ci
54+
command: yarn test-ci-partial
5555
- store_test_results:
5656
path: reports/junit
5757

@@ -79,7 +79,7 @@ jobs:
7979
install-npm: false
8080
- node/install-packages: *install
8181
- run:
82-
command: yarn test-ci-partial
82+
command: yarn test-ci
8383
- store_test_results:
8484
path: reports/junit
8585

.circleci/website.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ else
1313
git config --global user.name "Website Deployment Script"
1414
echo "machine github.com login docusaurus-bot password $DOCUSAURUS_PUBLISH_TOKEN" > ~/.netrc
1515
# install Docusaurus and generate file of English strings
16-
yarn && cd website && node fetchSupporters.js && yarn write-translations
16+
yarn --immutable && cd website && node fetchSupporters.js && yarn write-translations
1717
# crowdin install
1818
sudo apt-get update
1919
sudo apt-get install default-jre rsync
@@ -30,6 +30,6 @@ else
3030
GIT_USER=docusaurus-bot USE_SSH=false yarn publish-gh-pages
3131
else
3232
echo "Skipping deploy. Test website build"
33-
cd website && yarn && node fetchSupporters.js && yarn build
33+
yarn --immutable && cd website && node fetchSupporters.js && yarn build
3434
fi
3535
fi

.github/workflows/nodejs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
node-version: 12.x
3838
- name: install
39-
run: yarn
39+
run: yarn --immutable
4040
- name: build
4141
run: yarn build
4242
- name: test typings
@@ -80,7 +80,7 @@ jobs:
8080
with:
8181
node-version: ${{ matrix.node-version }}
8282
- name: install
83-
run: yarn
83+
run: yarn --immutable
8484
- name: build
8585
run: yarn build:js
8686
- name: Get number of CPU cores

e2e/Utils.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,20 @@ export const run = (
4444
return result;
4545
};
4646

47-
export const runYarn = (cwd: Config.Path, env?: Record<string, string>) => {
47+
export const runYarnInstall = (
48+
cwd: Config.Path,
49+
env?: Record<string, string>,
50+
) => {
4851
const lockfilePath = path.resolve(cwd, 'yarn.lock');
52+
let exists = true;
4953

5054
// If the lockfile doesn't exist, yarn's project detection is confused. Just creating an empty file works
5155
if (!fs.existsSync(lockfilePath)) {
56+
exists = false;
5257
fs.writeFileSync(lockfilePath, '');
5358
}
5459

55-
return run('yarn', cwd, env);
60+
return run(exists ? 'yarn install --immutable' : 'yarn install', cwd, env);
5661
};
5762

5863
export const linkJestPackage = (packageName: string, cwd: Config.Path) => {

e2e/__tests__/asyncRegenerator.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77

88
import * as path from 'path';
9-
import {runYarn} from '../Utils';
9+
import {runYarnInstall} from '../Utils';
1010
import {json as runWithJson} from '../runJest';
1111

1212
const dir = path.resolve(__dirname, '../async-regenerator');
1313

1414
beforeEach(() => {
15-
runYarn(dir);
15+
runYarnInstall(dir);
1616
});
1717

1818
test('successfully transpiles async', () => {

e2e/__tests__/babelPluginJestHoist.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77

88
import * as path from 'path';
9-
import {runYarn} from '../Utils';
9+
import {runYarnInstall} from '../Utils';
1010
import {json as runWithJson} from '../runJest';
1111

1212
const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist');
1313

1414
beforeEach(() => {
15-
runYarn(DIR);
15+
runYarnInstall(DIR);
1616
});
1717

1818
it('successfully runs the tests inside `babel-plugin-jest-hoist/`', () => {

e2e/__tests__/chaiAssertionLibrary.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import {extractSummary, runYarn} from '../Utils';
10+
import {extractSummary, runYarnInstall} from '../Utils';
1111
import runJest from '../runJest';
1212

1313
test('chai assertion errors should display properly', () => {
1414
const dir = path.resolve(__dirname, '../chai-assertion-library-errors');
15-
runYarn(dir);
15+
runYarnInstall(dir);
1616

1717
const {stderr} = runJest('chai-assertion-library-errors');
1818
const {rest} = extractSummary(stderr);

e2e/__tests__/console.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import {extractSummary, runYarn} from '../Utils';
10+
import {extractSummary, runYarnInstall} from '../Utils';
1111
import runJest from '../runJest';
1212

1313
test('console printing', () => {
@@ -99,7 +99,7 @@ test('the jsdom console is the same as the test console', () => {
9999

100100
test('does not error out when using winston', () => {
101101
const dir = path.resolve(__dirname, '../console-winston');
102-
runYarn(dir);
102+
runYarnInstall(dir);
103103
const {stderr, stdout, exitCode} = runJest(dir);
104104
const {summary, rest} = extractSummary(stderr);
105105

e2e/__tests__/coverageHandlebars.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import * as path from 'path';
99
import {readFileSync} from 'graceful-fs';
1010
import wrap from 'jest-snapshot-serializer-raw';
11-
import {cleanup, runYarn} from '../Utils';
11+
import {cleanup, runYarnInstall} from '../Utils';
1212
import runJest from '../runJest';
1313

1414
const dir = path.resolve(__dirname, '../coverage-handlebars');
@@ -19,7 +19,7 @@ beforeAll(() => {
1919
});
2020

2121
it('code coverage for Handlebars', () => {
22-
runYarn(dir);
22+
runYarnInstall(dir);
2323
const result = runJest(dir, ['--coverage', '--no-cache']);
2424

2525
expect(result.exitCode).toBe(0);

e2e/__tests__/coverageRemapping.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as path from 'path';
99
import {readFileSync} from 'graceful-fs';
10-
import {cleanup, runYarn} from '../Utils';
10+
import {cleanup, runYarnInstall} from '../Utils';
1111
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../coverage-remapping');
@@ -18,7 +18,7 @@ beforeAll(() => {
1818
});
1919

2020
it('maps code coverage against original source', () => {
21-
runYarn(dir);
21+
runYarnInstall(dir);
2222
const result = runJest(dir, ['--coverage', '--no-cache']);
2323

2424
expect(result.exitCode).toBe(0);

e2e/__tests__/coverageReport.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import * as path from 'path';
99
import * as fs from 'graceful-fs';
1010
import {wrap} from 'jest-snapshot-serializer-raw';
11-
import {extractSummary, runYarn} from '../Utils';
11+
import {extractSummary, runYarnInstall} from '../Utils';
1212
import runJest from '../runJest';
1313

1414
const DIR = path.resolve(__dirname, '../coverage-report');
1515

1616
beforeAll(() => {
17-
runYarn(DIR);
17+
runYarnInstall(DIR);
1818
});
1919

2020
test('outputs coverage report', () => {

e2e/__tests__/coverageTransformInstrumented.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as path from 'path';
99
import {readFileSync} from 'graceful-fs';
10-
import {cleanup, runYarn} from '../Utils';
10+
import {cleanup, runYarnInstall} from '../Utils';
1111
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../coverage-transform-instrumented');
@@ -18,7 +18,7 @@ beforeAll(() => {
1818
});
1919

2020
it('code coverage for transform instrumented code', () => {
21-
runYarn(dir);
21+
runYarnInstall(dir);
2222
const result = runJest(dir, ['--coverage', '--no-cache']);
2323

2424
expect(result.exitCode).toBe(0);

e2e/__tests__/expectAsyncMatcher.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import {extractSummary, runYarn} from '../Utils';
10+
import {extractSummary, runYarnInstall} from '../Utils';
1111
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../expect-async-matcher');
1414

1515
beforeAll(() => {
16-
runYarn(dir);
16+
runYarnInstall(dir);
1717
});
1818

1919
test('works with passing tests', () => {

e2e/__tests__/failures.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import {extractSummary, runYarn} from '../Utils';
10+
import {extractSummary, runYarnInstall} from '../Utils';
1111
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../failures');
@@ -24,7 +24,7 @@ function cleanStderr(stderr: string) {
2424
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);
2525

2626
beforeAll(() => {
27-
runYarn(dir);
27+
runYarnInstall(dir);
2828
});
2929

3030
test('not throwing Error objects', () => {

e2e/__tests__/globalSetup.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import {tmpdir} from 'os';
99
import * as path from 'path';
1010
import * as fs from 'graceful-fs';
11-
import {cleanup, runYarn} from '../Utils';
11+
import {cleanup, runYarnInstall} from '../Utils';
1212
import runJest, {json as runWithJson} from '../runJest';
1313

1414
const DIR = path.join(tmpdir(), 'jest-global-setup');
@@ -22,7 +22,7 @@ const nodeModulesDIR = path.join(tmpdir(), 'jest-global-setup-node-modules');
2222
const e2eDir = path.resolve(__dirname, '../global-setup');
2323

2424
beforeAll(() => {
25-
runYarn(e2eDir);
25+
runYarnInstall(e2eDir);
2626
});
2727

2828
beforeEach(() => {

e2e/__tests__/globalTeardown.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {tmpdir} from 'os';
99
import * as path from 'path';
1010
import * as fs from 'graceful-fs';
1111
import {createDirectory} from 'jest-util';
12-
import {cleanup, runYarn} from '../Utils';
12+
import {cleanup, runYarnInstall} from '../Utils';
1313
import runJest, {json as runWithJson} from '../runJest';
1414

1515
const DIR = path.join(tmpdir(), 'jest-global-teardown');
@@ -18,7 +18,7 @@ const project2DIR = path.join(tmpdir(), 'jest-global-teardown-project-2');
1818
const e2eDir = path.resolve(__dirname, '../global-teardown');
1919

2020
beforeAll(() => {
21-
runYarn(e2eDir);
21+
runYarnInstall(e2eDir);
2222
});
2323

2424
beforeEach(() => {

e2e/__tests__/nativeAsyncMock.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as path from 'path';
9-
import {extractSummary, runYarn} from '../Utils';
9+
import {extractSummary, runYarnInstall} from '../Utils';
1010
import runJest from '../runJest';
1111

1212
const dir = path.resolve(__dirname, '..', 'native-async-mock');
@@ -16,7 +16,7 @@ test('mocks async functions', () => {
1616
return;
1717
}
1818

19-
runYarn(dir);
19+
runYarnInstall(dir);
2020

2121
// --no-cache because babel can cache stuff and result in false green
2222
const {stderr} = runJest(dir, ['--no-cache']);

e2e/__tests__/pnp.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77

88
import * as path from 'path';
9-
import {runYarn} from '../Utils';
9+
import {runYarnInstall} from '../Utils';
1010
import {json as runWithJson} from '../runJest';
1111

1212
const DIR = path.resolve(__dirname, '..', 'pnp');
1313

1414
beforeEach(() => {
15-
runYarn(DIR, {YARN_NODE_LINKER: 'pnp'});
15+
runYarnInstall(DIR, {YARN_NODE_LINKER: 'pnp'});
1616
});
1717

1818
it('successfully runs the tests inside `pnp/`', () => {

e2e/__tests__/stackTraceSourceMaps.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*/
77

88
import * as path from 'path';
9-
import {runYarn} from '../Utils';
9+
import {runYarnInstall} from '../Utils';
1010
import runJest from '../runJest';
1111

1212
it('processes stack traces and code frames with source maps', () => {
1313
const dir = path.resolve(__dirname, '../stack-trace-source-maps');
14-
runYarn(dir);
14+
runYarnInstall(dir);
1515
const {stderr} = runJest(dir, ['--no-cache']);
1616
expect(stderr).toMatch('> 15 | (() => expect(false).toBe(true))();');
1717
expect(stderr).toMatch(`at __tests__/fails.ts:15:24

e2e/__tests__/stackTraceSourceMapsWithCoverage.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77
import * as path from 'path';
88
import wrap from 'jest-snapshot-serializer-raw';
9-
import {extractSummary, runYarn} from '../Utils';
9+
import {extractSummary, runYarnInstall} from '../Utils';
1010
import runJest from '../runJest';
1111

1212
it('processes stack traces and code frames with source maps with coverage', () => {
1313
const dir = path.resolve(
1414
__dirname,
1515
'../stack-trace-source-maps-with-coverage',
1616
);
17-
runYarn(dir);
17+
runYarnInstall(dir);
1818
const {stderr} = runJest(dir, ['--no-cache', '--coverage']);
1919

2020
// Should report an error at source line 13 in lib.ts at line 10 of the test

0 commit comments

Comments
 (0)