@@ -9,7 +9,7 @@ import * as assert from 'uvu/assert';
99import { suite } from 'uvu' ;
1010import { rigTest } from './util/rig-test.js' ;
1111import { WireitTestRig } from './util/test-rig.js' ;
12- import { Options } from '../cli-options.js' ;
12+ import { Agent , Options } from '../cli-options.js' ;
1313import { Result } from '../error.js' ;
1414
1515const test = suite < object > ( ) ;
@@ -29,6 +29,58 @@ async function getOptionsResult(
2929 extraScripts ?: Record < string , string > ,
3030) : Promise < Result < Options > > {
3131 rig . env . WIREIT_DEBUG_LOG_FILE = '' ;
32+
33+ if ( command . startsWith ( 'yarnBerry' ) ) {
34+ // `yarn` chooses whether to use "classic" or "berry" based on the presence
35+ // of `yarnPath` in `.yarnrc.yml`.
36+ //
37+ // To closest simulate a user's environment, set `yarnPath` and let the
38+ // global `yarn` command pick it when testing `yarnBerry`.
39+ command = command . replace ( / y a r n B e r r y / g, 'yarn' ) ;
40+
41+ extraScripts = Object . fromEntries (
42+ Object . entries ( extraScripts || { } ) . map ( ( [ scriptName , scriptCommand ] ) => [
43+ scriptName ,
44+ scriptCommand . replace ( / y a r n B e r r y / g, 'yarn' ) ,
45+ ] ) ,
46+ ) ;
47+
48+ await rig . write ( {
49+ '.yarnrc.yml' : `
50+ nodeLinker: node-modules
51+ yarnPath: ${ pathlib . join (
52+ process . cwd ( ) ,
53+ 'third_party' ,
54+ '.yarn' ,
55+ 'releases' ,
56+ 'yarn-4.0.1.cjs' ,
57+ ) }
58+ ` ,
59+ } ) ;
60+
61+ // `yarn.lock` tells `yarn` that this test is meant to be its own workspace
62+ // root, even though there are higher `package.json` files in the file tree.
63+ //
64+ // This is the `yarn.lock` you get if you initialize `yarn` in an empty
65+ // folder.
66+ await rig . write ( {
67+ 'yarn.lock' : `
68+ # This file is generated by running "yarn install" inside your project.
69+ # Manual changes might be lost - proceed with caution!
70+
71+ __metadata:
72+ version: 8
73+ cacheKey: 10c0
74+
75+ "root-workspace-0b6124@workspace:.":
76+ version: 0.0.0-use.local
77+ resolution: "root-workspace-0b6124@workspace:."
78+ languageName: unknown
79+ linkType: soft
80+ ` ,
81+ } ) ;
82+ }
83+
3284 await rig . write ( {
3385 'package.json' : {
3486 scripts : {
@@ -39,7 +91,12 @@ async function getOptionsResult(
3991 } ,
4092 } ,
4193 } ) ;
42- env = { ...env , WIREIT_DEBUG_LOG_FILE : '' } ;
94+
95+ env = {
96+ ...env ,
97+ WIREIT_DEBUG_LOG_FILE : '' ,
98+ } ;
99+
43100 assert . equal ( ( await rig . exec ( command , { env} ) . exit ) . code , 0 ) ;
44101 return JSON . parse ( await rig . read ( 'options.json' ) ) as Result < Options > ;
45102}
@@ -67,8 +124,8 @@ async function assertOptions(
67124 } ) ;
68125}
69126
70- for ( const command of [ 'npm' , 'yarn' , 'pnpm' ] as const ) {
71- const agent = command === 'yarn' ? 'yarnClassic' : command ;
127+ for ( const command of [ 'npm' , 'yarn' , 'pnpm' , 'yarnBerry' ] as const ) {
128+ const agent : Agent = command === 'yarn' ? 'yarnClassic' : command ;
72129 // eslint-disable-next-line @typescript-eslint/unbound-method
73130 const skipIfYarn = command === 'yarn' ? test . skip : test ;
74131 // eslint-disable-next-line @typescript-eslint/unbound-method
0 commit comments