Skip to content

Commit a9b54a8

Browse files
Move yarnBerry accomodations into shared file
1 parent b5d43f5 commit a9b54a8

2 files changed

Lines changed: 54 additions & 34 deletions

File tree

src/test/cli-options.test.ts

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as assert from 'uvu/assert';
88
import * as pathlib from 'path';
99
import {Agent, Options} from '../cli-options.js';
1010
import {IS_WINDOWS} from '../util/windows.js';
11+
import {injectYarnBerryToRig} from './util/yarn-berry.js';
1112
import {Result} from '../error.js';
1213
import {WireitTestRig} from './util/test-rig.js';
1314
import {rigTest} from './util/rig-test.js';
@@ -46,40 +47,7 @@ async function getOptionsResult(
4647
]),
4748
);
4849

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-
});
50+
await injectYarnBerryToRig(rig);
8351
}
8452

8553
await rig.write({

src/test/util/yarn-berry.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import * as pathlib from 'path';
8+
import {dedent} from 'ts-dedent';
9+
import {WireitTestRig} from './test-rig.js';
10+
11+
type TestEnviron = {
12+
rig: WireitTestRig;
13+
command: string;
14+
extraScripts?: Record<string, string>;
15+
};
16+
17+
export const injectYarnBerryToRig = async (rig: WireitTestRig) => {
18+
await rig.write({
19+
'.yarnrc.yml': `
20+
nodeLinker: node-modules
21+
yarnPath: ${pathlib.join(
22+
process.cwd(),
23+
'third_party',
24+
'.yarn',
25+
'releases',
26+
'yarn-4.0.1.cjs',
27+
)}
28+
`,
29+
});
30+
31+
// `yarn.lock` tells `yarn` that this test is meant to be its own workspace
32+
// root, even though there are higher `package.json` files in the file tree.
33+
//
34+
// This is the `yarn.lock` you get if you initialize `yarn` in an empty
35+
// folder.
36+
await rig.write({
37+
'yarn.lock': dedent`
38+
# This file is generated by running "yarn install" inside your project.
39+
# Manual changes might be lost - proceed with caution!
40+
41+
__metadata:
42+
version: 8
43+
cacheKey: 10c0
44+
45+
"root-workspace-0b6124@workspace:.":
46+
version: 0.0.0-use.local
47+
resolution: "root-workspace-0b6124@workspace:."
48+
languageName: unknown
49+
linkType: soft
50+
`,
51+
});
52+
};

0 commit comments

Comments
 (0)