Skip to content

Commit

Permalink
Cleanups some tests (#6388)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
arcanis authored Jul 29, 2024
1 parent d463ea4 commit dca729d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const execPromise = promisify(exec);
interface Options {
cwd: PortablePath;
env?: Record<string, string>;
stdin?: string;
}

export type ExecResult = {
Expand All @@ -25,7 +26,7 @@ export const execFile = (
options: Options,
): Promise<ExecResult> => {
return new Promise((resolve, reject) => {
cp.execFile(path, args, {
const process = cp.execFile(path, args, {
...options,
cwd: options.cwd ? npath.fromPortablePath(options.cwd) : undefined,
}, (error, stdout, stderr) => {
Expand All @@ -50,6 +51,11 @@ export const execFile = (
});
}
});

if (typeof options.stdin !== `undefined`) {
process.stdin?.write(options.stdin);
process.stdin?.end();
}
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mte = generatePkgDriver({
async runDriver(
path,
[command, ...args],
{cwd, execArgv = [], projectFolder, registryUrl, env, ...config},
{cwd, execArgv = [], projectFolder, registryUrl, env, stdin, ...config},
) {
const rcEnv: Record<string, any> = {};
for (const [key, value] of Object.entries(config))
Expand All @@ -32,6 +32,7 @@ const mte = generatePkgDriver({

const res = await execFile(process.execPath, [...execArgv, yarnBinary, ...cwdArgs, command, ...args], {
cwd: cwd || path,
stdin,
env: {
[`HOME`]: nativeHomePath,
[`USERPROFILE`]: nativeHomePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface RunDriverOptions extends Record<string, any> {
projectFolder?: PortablePath;
registryUrl: string;
env?: Record<string, string | undefined>;
stdin?: string;
}

export type PackageRunDriver = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ describe(`Node_Modules`, () => {
},
});

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

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

0 comments on commit dca729d

Please sign in to comment.