Skip to content

Commit c0df287

Browse files
authored
chore: reduce test flakiness (#168)
1 parent 92b52f6 commit c0df287

File tree

75 files changed

+113
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+113
-50
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ jobs:
7878
- run: corepack yarn build # We need the stubs to run the tests
7979

8080
- run: corepack yarn test
81+
env:
82+
NOCK_ENV: replay

tests/Enable.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const engine = new Engine();
1111

1212
beforeEach(async () => {
1313
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
14+
process.env.COREPACK_DEFAULT_TO_LATEST = `0`;
1415
});
1516

1617
describe(`EnableCommand`, () => {
@@ -22,6 +23,8 @@ describe(`EnableCommand`, () => {
2223
try {
2324
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
2425
await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({
26+
stdout: ``,
27+
stderr: ``,
2528
exitCode: 0,
2629
});
2730
} finally {
@@ -46,6 +49,8 @@ describe(`EnableCommand`, () => {
4649
const corepackBin = await makeBin(cwd, `corepack` as Filename);
4750

4851
await expect(runCli(cwd, [`enable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({
52+
stdout: ``,
53+
stderr: ``,
4954
exitCode: 0,
5055
});
5156

@@ -70,6 +75,8 @@ describe(`EnableCommand`, () => {
7075
try {
7176
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
7277
await expect(runCli(cwd, [`enable`, `yarn`])).resolves.toMatchObject({
78+
stdout: ``,
79+
stderr: ``,
7380
exitCode: 0,
7481
});
7582
} finally {

tests/_runCli.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export async function runCli(cwd: PortablePath, argv: Array<string>) {
66
const err: Array<Buffer> = [];
77

88
return new Promise((resolve, reject) => {
9-
const child = spawn(process.execPath, [require.resolve(`corepack/dist/corepack.js`), ...argv], {
9+
if (process.env.RUN_CLI_ID)
10+
(process.env.RUN_CLI_ID as any)++;
11+
const child = spawn(process.execPath, [`--no-warnings`, `-r`, require.resolve(`./recordRequests.js`), require.resolve(`corepack/dist/corepack.js`), ...argv], {
1012
cwd: npath.fromPortablePath(cwd),
1113
env: process.env,
1214
stdio: `pipe`,

tests/main.test.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ it(`should refuse to download a package manager if the hash doesn't match`, asyn
1717

1818
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
1919
exitCode: 1,
20+
stderr: ``,
2021
stdout: /Mismatch hashes/,
2122
});
2223
});
@@ -52,6 +53,7 @@ for (const [name, version] of testedPackageManagers) {
5253

5354
await expect(runCli(cwd, [name, `--version`])).resolves.toMatchObject({
5455
exitCode: 0,
56+
stderr: ``,
5557
stdout: `${version.split(`+`, 1)[0]}\n`,
5658
});
5759
});
@@ -77,11 +79,13 @@ it(`should ignore the packageManager field when found within a node_modules vend
7779

7880
await expect(runCli(ppath.join(cwd, `node_modules/foo` as PortablePath), [`yarn`, `--version`])).resolves.toMatchObject({
7981
exitCode: 0,
82+
stderr: ``,
8083
stdout: `1.22.4\n`,
8184
});
8285

8386
await expect(runCli(ppath.join(cwd, `node_modules/@foo/bar` as PortablePath), [`yarn`, `--version`])).resolves.toMatchObject({
8487
exitCode: 0,
88+
stderr: ``,
8589
stdout: `1.22.4\n`,
8690
});
8791
});
@@ -101,6 +105,7 @@ it(`should use the closest matching packageManager field`, async () => {
101105

102106
await expect(runCli(ppath.join(cwd, `foo` as PortablePath), [`npm`, `--version`])).resolves.toMatchObject({
103107
exitCode: 0,
108+
stderr: ``,
104109
stdout: `6.14.2\n`,
105110
});
106111
});
@@ -127,6 +132,7 @@ it(`shouldn't allow using regular Yarn commands on npm-configured projects`, asy
127132

128133
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
129134
exitCode: 1,
135+
stderr: ``,
130136
});
131137
});
132138
});
@@ -137,8 +143,9 @@ it(`should allow using transparent commands on npm-configured projects`, async (
137143
packageManager: `npm@6.14.2`,
138144
});
139145

140-
await expect(runCli(cwd, [`yarn`, `dlx`, `cat@0.2.0`, __filename])).resolves.toMatchObject({
146+
await expect(runCli(cwd, [`yarn`, `dlx`, `--help`])).resolves.toMatchObject({
141147
exitCode: 0,
148+
stderr: ``,
142149
});
143150
});
144151
});
@@ -147,6 +154,7 @@ it(`should transparently use the preconfigured version when there is no local pr
147154
await xfs.mktempPromise(async cwd => {
148155
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
149156
exitCode: 0,
157+
stderr: ``,
150158
});
151159
});
152160
});
@@ -163,16 +171,19 @@ it(`should use the pinned version when local projects don't list any spec`, asyn
163171

164172
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
165173
stdout: `${config.definitions.yarn.default.split(`+`, 1)[0]}\n`,
174+
stderr: ``,
166175
exitCode: 0,
167176
});
168177

169178
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
170179
stdout: `${config.definitions.pnpm.default.split(`+`, 1)[0]}\n`,
180+
stderr: ``,
171181
exitCode: 0,
172182
});
173183

174184
await expect(runCli(cwd, [`npm`, `--version`])).resolves.toMatchObject({
175185
stdout: `${config.definitions.npm.default.split(`+`, 1)[0]}\n`,
186+
stderr: ``,
176187
exitCode: 0,
177188
});
178189
});
@@ -182,6 +193,7 @@ it(`should allow updating the pinned version using the "prepare" command`, async
182193
await xfs.mktempPromise(async cwd => {
183194
await expect(runCli(cwd, [`prepare`, `--activate`, `yarn@1.0.0`])).resolves.toMatchObject({
184195
exitCode: 0,
196+
stderr: ``,
185197
});
186198

187199
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
@@ -190,6 +202,7 @@ it(`should allow updating the pinned version using the "prepare" command`, async
190202

191203
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
192204
stdout: `1.0.0\n`,
205+
stderr: ``,
193206
exitCode: 0,
194207
});
195208
});
@@ -203,6 +216,7 @@ it(`should allow to call "prepare" without arguments within a configured project
203216

204217
await expect(runCli(cwd, [`prepare`, `--activate`])).resolves.toMatchObject({
205218
exitCode: 0,
219+
stderr: ``,
206220
});
207221

208222
// Disable the network to make sure we don't succeed by accident
@@ -211,6 +225,7 @@ it(`should allow to call "prepare" without arguments within a configured project
211225
try {
212226
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
213227
stdout: `1.0.0\n`,
228+
stderr: ``,
214229
exitCode: 0,
215230
});
216231
} finally {
@@ -255,23 +270,27 @@ it(`should allow to call "prepare" with --all to prepare all package managers`,
255270

256271
await expect(runCli(cwd, [`prepare`, `--all`])).resolves.toMatchObject({
257272
exitCode: 0,
273+
stderr: ``,
258274
});
259275

260276
process.env.COREPACK_ENABLE_NETWORK = `0`;
261277

262278
try {
263279
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
264280
stdout: `${config.definitions.yarn.default.split(`+`, 1)[0]}\n`,
281+
stderr: ``,
265282
exitCode: 0,
266283
});
267284

268285
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
269286
stdout: `${config.definitions.pnpm.default.split(`+`, 1)[0]}\n`,
287+
stderr: ``,
270288
exitCode: 0,
271289
});
272290

273291
await expect(runCli(cwd, [`npm`, `--version`])).resolves.toMatchObject({
274292
stdout: `${config.definitions.npm.default.split(`+`, 1)[0]}\n`,
293+
stderr: ``,
275294
exitCode: 0,
276295
});
277296
} finally {
@@ -291,6 +310,7 @@ it(`should support disabling the network accesses from the environment`, async (
291310

292311
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
293312
stdout: expect.stringContaining(`Network access disabled by the environment`),
313+
stderr: ``,
294314
exitCode: 1,
295315
});
296316
});
@@ -303,6 +323,7 @@ it(`should support hydrating package managers from cached archives`, async () =>
303323
await xfs.mktempPromise(async cwd => {
304324
await expect(runCli(cwd, [`prepare`, `yarn@2.2.2`, `-o`])).resolves.toMatchObject({
305325
exitCode: 0,
326+
stderr: ``,
306327
});
307328

308329
// Use a new cache
@@ -314,6 +335,7 @@ it(`should support hydrating package managers from cached archives`, async () =>
314335
try {
315336
await expect(runCli(cwd, [`hydrate`, `corepack.tgz`])).resolves.toMatchObject({
316337
stdout: `Hydrating yarn@2.2.2...\nAll done!\n`,
338+
stderr: ``,
317339
exitCode: 0,
318340
});
319341

@@ -323,6 +345,7 @@ it(`should support hydrating package managers from cached archives`, async () =>
323345

324346
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
325347
stdout: `2.2.2\n`,
348+
stderr: ``,
326349
exitCode: 0,
327350
});
328351
} finally {
@@ -335,6 +358,7 @@ it(`should support hydrating multiple package managers from cached archives`, as
335358
await xfs.mktempPromise(async cwd => {
336359
await expect(runCli(cwd, [`prepare`, `yarn@2.2.2`, `pnpm@5.8.0`, `-o`])).resolves.toMatchObject({
337360
exitCode: 0,
361+
stderr: ``,
338362
});
339363

340364
// Use a new cache
@@ -346,6 +370,7 @@ it(`should support hydrating multiple package managers from cached archives`, as
346370
try {
347371
await expect(runCli(cwd, [`hydrate`, `corepack.tgz`])).resolves.toMatchObject({
348372
stdout: `Hydrating yarn@2.2.2...\nHydrating pnpm@5.8.0...\nAll done!\n`,
373+
stderr: ``,
349374
exitCode: 0,
350375
});
351376

@@ -355,6 +380,7 @@ it(`should support hydrating multiple package managers from cached archives`, as
355380

356381
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
357382
stdout: `2.2.2\n`,
383+
stderr: ``,
358384
exitCode: 0,
359385
});
360386

@@ -364,6 +390,7 @@ it(`should support hydrating multiple package managers from cached archives`, as
364390

365391
await expect(runCli(cwd, [`pnpm`, `--version`])).resolves.toMatchObject({
366392
stdout: `5.8.0\n`,
393+
stderr: ``,
367394
exitCode: 0,
368395
});
369396
} finally {
@@ -380,11 +407,13 @@ it(`should support running package managers with bin array`, async () => {
380407

381408
await expect(runCli(cwd, [`yarnpkg`, `--version`])).resolves.toMatchObject({
382409
stdout: `2.2.2\n`,
410+
stderr: ``,
383411
exitCode: 0,
384412
});
385413

386414
await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
387415
stdout: `2.2.2\n`,
416+
stderr: ``,
388417
exitCode: 0,
389418
});
390419
});
@@ -403,14 +432,17 @@ it(`should handle parallel installs`, async () => {
403432
])).resolves.toMatchObject([
404433
{
405434
stdout: `2.2.2\n`,
435+
stderr: ``,
406436
exitCode: 0,
407437
},
408438
{
409439
stdout: `2.2.2\n`,
440+
stderr: ``,
410441
exitCode: 0,
411442
},
412443
{
413444
stdout: `2.2.2\n`,
445+
stderr: ``,
414446
exitCode: 0,
415447
},
416448
]);

0 commit comments

Comments
 (0)