44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import * as pathlib from 'path' ;
87import * 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' ;
1311import { 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
1516const 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 ( / y a r n B e r r y / g, 'yarn' ) ;
41+
42+ extraScripts = Object . fromEntries (
43+ Object . entries ( extraScripts || { } ) . map ( ( [ scriptName , scriptCommand ] ) => [
44+ scriptName ,
45+ scriptCommand . replace ( / y a r n B e r r y / 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
0 commit comments