Skip to content

Commit dca729d

Browse files
authored
Cleanups some tests (#6388)
## What's the problem this PR addresses? I'm reviewing our tests and came upon some of them that could be dumbed down. I prefer to make them test as little things as possible to avoid something breaking due to unrelated parts of the code changing (I'm working on switching some implementations, and limiting test dependencies make things considerably easier / more fun to work on). ## How did you fix it? No big changes - it's mostly things like using the `dependencies` rather than calling `yarn add` and avoiding to rely on cache paths to check whether something got properly installed. ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent d463ea4 commit dca729d

File tree

6 files changed

+87
-85
lines changed

6 files changed

+87
-85
lines changed

packages/acceptance-tests/pkg-tests-core/sources/utils/exec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const execPromise = promisify(exec);
88
interface Options {
99
cwd: PortablePath;
1010
env?: Record<string, string>;
11+
stdin?: string;
1112
}
1213

1314
export type ExecResult = {
@@ -25,7 +26,7 @@ export const execFile = (
2526
options: Options,
2627
): Promise<ExecResult> => {
2728
return new Promise((resolve, reject) => {
28-
cp.execFile(path, args, {
29+
const process = cp.execFile(path, args, {
2930
...options,
3031
cwd: options.cwd ? npath.fromPortablePath(options.cwd) : undefined,
3132
}, (error, stdout, stderr) => {
@@ -50,6 +51,11 @@ export const execFile = (
5051
});
5152
}
5253
});
54+
55+
if (typeof options.stdin !== `undefined`) {
56+
process.stdin?.write(options.stdin);
57+
process.stdin?.end();
58+
}
5359
});
5460
};
5561

packages/acceptance-tests/pkg-tests-core/sources/utils/makeTemporaryEnv.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const mte = generatePkgDriver({
1414
async runDriver(
1515
path,
1616
[command, ...args],
17-
{cwd, execArgv = [], projectFolder, registryUrl, env, ...config},
17+
{cwd, execArgv = [], projectFolder, registryUrl, env, stdin, ...config},
1818
) {
1919
const rcEnv: Record<string, any> = {};
2020
for (const [key, value] of Object.entries(config))
@@ -32,6 +32,7 @@ const mte = generatePkgDriver({
3232

3333
const res = await execFile(process.execPath, [...execArgv, yarnBinary, ...cwdArgs, command, ...args], {
3434
cwd: cwd || path,
35+
stdin,
3536
env: {
3637
[`HOME`]: nativeHomePath,
3738
[`USERPROFILE`]: nativeHomePath,

packages/acceptance-tests/pkg-tests-core/sources/utils/tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface RunDriverOptions extends Record<string, any> {
3838
projectFolder?: PortablePath;
3939
registryUrl: string;
4040
env?: Record<string, string | undefined>;
41+
stdin?: string;
4142
}
4243

4344
export type PackageRunDriver = (

packages/acceptance-tests/pkg-tests-specs/sources/node-modules.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ describe(`Node_Modules`, () => {
18711871
},
18721872
});
18731873

1874-
await expect(run(`install`)).resolves.toMatchObject({code: 0});
1874+
await run(`install`);
18751875

18761876
await expect(xfs.readdirPromise(ppath.join(path, Filename.nodeModules))).resolves.toEqual([
18771877
`.yarn-state.yml`,

0 commit comments

Comments
 (0)