Skip to content

Commit 88084f8

Browse files
Add yarnBerry to test suite
1 parent 47c83cb commit 88084f8

File tree

2 files changed

+95
-23
lines changed

2 files changed

+95
-23
lines changed

src/test/cli-options.test.ts

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import * as pathlib from 'path';
87
import * as assert from 'uvu/assert';
9-
import {suite} from 'uvu';
10-
import {rigTest} from './util/rig-test.js';
11-
import {WireitTestRig} from './util/test-rig.js';
12-
import {Options} from '../cli-options.js';
8+
import * as pathlib from 'path';
9+
import {Agent, Options} from '../cli-options.js';
10+
import {IS_WINDOWS} from '../util/windows.js';
1311
import {Result} from '../error.js';
12+
import {WireitTestRig} from './util/test-rig.js';
13+
import {rigTest} from './util/rig-test.js';
14+
import {suite} from 'uvu';
1415

1516
const test = suite<object>();
1617

@@ -29,6 +30,58 @@ async function getOptionsResult(
2930
extraScripts?: Record<string, string>,
3031
): Promise<Result<Options>> {
3132
rig.env.WIREIT_DEBUG_LOG_FILE = '';
33+
34+
if (command.startsWith('yarnBerry')) {
35+
// `yarn` chooses whether to use "classic" or "berry" based on the presence
36+
// of `yarnPath` in `.yarnrc.yml`.
37+
//
38+
// To closest simulate a user's environment, set `yarnPath` and let the
39+
// global `yarn` command pick it when testing `yarnBerry`.
40+
command = command.replace(/yarnBerry/g, 'yarn');
41+
42+
extraScripts = Object.fromEntries(
43+
Object.entries(extraScripts || {}).map(([scriptName, scriptCommand]) => [
44+
scriptName,
45+
scriptCommand.replace(/yarnBerry/g, 'yarn'),
46+
]),
47+
);
48+
49+
await rig.write({
50+
'.yarnrc.yml': `
51+
nodeLinker: node-modules
52+
yarnPath: ${pathlib.join(
53+
process.cwd(),
54+
'third_party',
55+
'.yarn',
56+
'releases',
57+
'yarn-4.0.1.cjs',
58+
)}
59+
`,
60+
});
61+
62+
// `yarn.lock` tells `yarn` that this test is meant to be its own workspace
63+
// root, even though there are higher `package.json` files in the file tree.
64+
//
65+
// This is the `yarn.lock` you get if you initialize `yarn` in an empty
66+
// folder.
67+
await rig.write({
68+
'yarn.lock': `
69+
# This file is generated by running "yarn install" inside your project.
70+
# Manual changes might be lost - proceed with caution!
71+
72+
__metadata:
73+
version: 8
74+
cacheKey: 10c0
75+
76+
"root-workspace-0b6124@workspace:.":
77+
version: 0.0.0-use.local
78+
resolution: "root-workspace-0b6124@workspace:."
79+
languageName: unknown
80+
linkType: soft
81+
`,
82+
});
83+
}
84+
3285
await rig.write({
3386
'package.json': {
3487
scripts: {
@@ -39,7 +92,12 @@ async function getOptionsResult(
3992
},
4093
},
4194
});
42-
env = {...env, WIREIT_DEBUG_LOG_FILE: ''};
95+
96+
env = {
97+
...env,
98+
WIREIT_DEBUG_LOG_FILE: '',
99+
};
100+
43101
assert.equal((await rig.exec(command, {env}).exit).code, 0);
44102
return JSON.parse(await rig.read('options.json')) as Result<Options>;
45103
}
@@ -67,8 +125,14 @@ async function assertOptions(
67125
});
68126
}
69127

70-
for (const command of ['npm', 'yarn', 'pnpm'] as const) {
71-
const agent = command === 'yarn' ? 'yarnClassic' : command;
128+
// yarnBerry tests work everywhere but Windows (#1014). Until Windows testing
129+
// is fixed, skip yarnBerry tests on Windows to prevent CI failures.
130+
const commands = (['npm', 'yarn', 'pnpm', 'yarnBerry'] as const).filter(
131+
(command) => !IS_WINDOWS || command !== 'yarnBerry',
132+
);
133+
134+
for (const command of commands) {
135+
const agent: Agent = command === 'yarn' ? 'yarnClassic' : command;
72136
// eslint-disable-next-line @typescript-eslint/unbound-method
73137
const skipIfYarn = command === 'yarn' ? test.skip : test;
74138
// eslint-disable-next-line @typescript-eslint/unbound-method

src/test/util/test-rig.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,30 @@ export class WireitTestRig
6464
*/
6565
override async setup() {
6666
await super.setup();
67-
const absWireitBinaryPath = pathlib.resolve(repoRoot, 'bin', 'wireit.js');
68-
const absWireitTempInstallPath = pathlib.resolve(
69-
this.temp,
70-
'node_modules',
71-
'.bin',
72-
'wireit',
67+
68+
await Promise.all(
69+
[['wireit', ['bin', 'wireit.js']] as const].map(
70+
async ([name, pathParts]) => {
71+
const binaryPath = pathlib.resolve(repoRoot, ...pathParts);
72+
const tempInstallPath = pathlib.resolve(
73+
this.temp,
74+
'node_modules',
75+
'.bin',
76+
name,
77+
);
78+
79+
if (IS_WINDOWS) {
80+
// Npm install works differently on Windows, since it won't recognize a
81+
// shebang like "#!/usr/bin/env node". Npm instead uses the cmd-shim
82+
// package to generate Windows shell wrappers for each binary, so we do
83+
// that here too.
84+
await cmdShim(binaryPath, tempInstallPath);
85+
} else {
86+
await this.symlink(binaryPath, tempInstallPath, 'file');
87+
}
88+
},
89+
),
7390
);
74-
if (IS_WINDOWS) {
75-
// Npm install works differently on Windows, since it won't recognize a
76-
// shebang like "#!/usr/bin/env node". Npm instead uses the cmd-shim
77-
// package to generate Windows shell wrappers for each binary, so we do
78-
// that here too.
79-
await cmdShim(absWireitBinaryPath, absWireitTempInstallPath);
80-
} else {
81-
await this.symlink(absWireitBinaryPath, absWireitTempInstallPath, 'file');
82-
}
8391
}
8492

8593
/**

0 commit comments

Comments
 (0)