Skip to content

Commit e321920

Browse files
WIP add yarnBerry to test suite
1 parent 47c83cb commit e321920

File tree

2 files changed

+76
-19
lines changed

2 files changed

+76
-19
lines changed

src/test/cli-options.test.ts

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import * as assert from 'uvu/assert';
99
import {suite} from 'uvu';
1010
import {rigTest} from './util/rig-test.js';
1111
import {WireitTestRig} from './util/test-rig.js';
12-
import {Options} from '../cli-options.js';
12+
import {Agent, Options} from '../cli-options.js';
1313
import {Result} from '../error.js';
14+
import {IS_WINDOWS} from '../util/windows.js';
1415

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

@@ -39,7 +40,38 @@ async function getOptionsResult(
3940
},
4041
},
4142
});
42-
env = {...env, WIREIT_DEBUG_LOG_FILE: ''};
43+
44+
if (command.startsWith('yarnBerry')) {
45+
await rig.write({
46+
'yarn.lock': `# This file is generated by running "yarn install" inside your project.
47+
# Manual changes might be lost - proceed with caution!
48+
49+
__metadata:
50+
version: 8
51+
cacheKey: 10c0
52+
53+
"root-workspace-0b6124@workspace:.":
54+
version: 0.0.0-use.local
55+
resolution: "root-workspace-0b6124@workspace:."
56+
languageName: unknown
57+
linkType: soft
58+
`,
59+
});
60+
await rig.write({
61+
'.yarnrc.yml': 'nodeLinker: node-modules',
62+
});
63+
}
64+
65+
const PATH_SEPARATOR = IS_WINDOWS ? `;` : `:`;
66+
67+
env = {
68+
...env,
69+
WIREIT_DEBUG_LOG_FILE: '',
70+
PATH: `${env?.PATH ?? process.env.PATH}${PATH_SEPARATOR}${
71+
rig.temp
72+
}/node_modules/.bin`,
73+
};
74+
4375
assert.equal((await rig.exec(command, {env}).exit).code, 0);
4476
return JSON.parse(await rig.read('options.json')) as Result<Options>;
4577
}
@@ -67,8 +99,8 @@ async function assertOptions(
6799
});
68100
}
69101

70-
for (const command of ['npm', 'yarn', 'pnpm'] as const) {
71-
const agent = command === 'yarn' ? 'yarnClassic' : command;
102+
for (const command of ['npm', 'yarn', 'pnpm', 'yarnBerry'] as const) {
103+
const agent: Agent = command === 'yarn' ? 'yarnClassic' : command;
72104
// eslint-disable-next-line @typescript-eslint/unbound-method
73105
const skipIfYarn = command === 'yarn' ? test.skip : test;
74106
// eslint-disable-next-line @typescript-eslint/unbound-method
@@ -87,6 +119,19 @@ for (const command of ['npm', 'yarn', 'pnpm'] as const) {
87119
}),
88120
);
89121

122+
test(
123+
`${command} run main`,
124+
rigTest(async ({rig}) => {
125+
await assertOptions(rig, `${command} run main`, {
126+
agent,
127+
script: {
128+
packageDir: rig.temp,
129+
name: 'main',
130+
},
131+
});
132+
}),
133+
);
134+
90135
test(
91136
`${command} test`,
92137
rigTest(async ({rig}) => {

src/test/util/test-rig.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,34 @@ 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+
[
70+
['wireit', ['bin', 'wireit.js']] as const,
71+
[
72+
'yarnBerry',
73+
['third_party', '.yarn', 'releases', 'yarn-4.0.1.cjs'],
74+
] as const,
75+
].map(async ([name, pathParts]) => {
76+
const binaryPath = pathlib.resolve(repoRoot, ...pathParts);
77+
const tempInstallPath = pathlib.resolve(
78+
this.temp,
79+
'node_modules',
80+
'.bin',
81+
name,
82+
);
83+
84+
if (IS_WINDOWS) {
85+
// Npm install works differently on Windows, since it won't recognize a
86+
// shebang like "#!/usr/bin/env node". Npm instead uses the cmd-shim
87+
// package to generate Windows shell wrappers for each binary, so we do
88+
// that here too.
89+
await cmdShim(binaryPath, tempInstallPath);
90+
} else {
91+
await this.symlink(binaryPath, tempInstallPath, 'file');
92+
}
93+
}),
7394
);
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-
}
8395
}
8496

8597
/**

0 commit comments

Comments
 (0)