Skip to content

Commit

Permalink
chore: start converting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jan 14, 2024
1 parent 39c57cd commit 969cc7e
Show file tree
Hide file tree
Showing 4 changed files with 814 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"semver": "^7.5.2",
"supports-color": "^9.0.0",
"tar": "^6.0.1",
"tsx": "^4.7.0",
"typescript": "^5.0.4",
"v8-compile-cache": "^2.3.0",
"which": "^4.0.0"
Expand Down
7 changes: 4 additions & 3 deletions tests/Use.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import assert from 'node:assert';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';

Expand All @@ -15,15 +16,15 @@ describe(`UseCommand`, () => {
await xfs.writeJsonPromise(ppath.join(cwd, `package.json`), {
});

await expect(runCli(cwd, [`use`, `[email protected]`])).resolves.toMatchObject({
assert.deepStrictEqual(await runCli(cwd, [`use`, `[email protected]`]), {
exitCode: 0,
});

await expect(xfs.readJsonPromise(ppath.join(cwd, `package.json`))).resolves.toMatchObject({
assert.deepStrictEqual(await xfs.readJsonPromise(ppath.join(cwd, `package.json`)), {
packageManager: `[email protected]+sha256.bc5316aa110b2f564a71a3d6e235be55b98714660870c5b6b2d2d3f12587fb58`,
});

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
assert.deepStrictEqual(await runCli(cwd, [`yarn`, `--version`]), {
exitCode: 0,
stdout: `1.22.4\n`,
});
Expand Down
20 changes: 11 additions & 9 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Filename, ppath, xfs, npath, PortablePath} from '@yarnpkg/fslib';
import assert from 'node:assert/strict';
import process from 'node:process';
import {beforeEach, it} from 'node:test';

Expand Down Expand Up @@ -549,13 +550,13 @@ it(`should support running package managers with bin array`, async () => {
packageManager: `[email protected]`,
});

await expect(runCli(cwd, [`yarnpkg`, `--version`])).resolves.toMatchObject({
assert.deepEqual(await runCli(cwd, [`yarnpkg`, `--version`]), {
stdout: `2.2.2\n`,
stderr: ``,
exitCode: 0,
});

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
assert.deepEqual(await runCli(cwd, [`yarn`, `--version`]), {
stdout: `2.2.2\n`,
stderr: ``,
exitCode: 0,
Expand All @@ -569,11 +570,11 @@ it(`should handle parallel installs`, async () => {
packageManager: `[email protected]`,
});

await expect(Promise.all([
assert.deepEqual(await Promise.all([
runCli(cwd, [`yarn`, `--version`]),
runCli(cwd, [`yarn`, `--version`]),
runCli(cwd, [`yarn`, `--version`]),
])).resolves.toMatchObject([
]), [
{
stdout: `2.2.2\n`,
stderr: ``,
Expand Down Expand Up @@ -607,7 +608,7 @@ it(`should not override the package manager exit code`, async () => {
process.exitCode = 42;
`);

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
assert.deepEqual(await runCli(cwd, [`yarn`, `--version`]), {
exitCode: 42,
stdout: ``,
stderr: ``,
Expand All @@ -633,11 +634,12 @@ it(`should not preserve the process.exitCode when a package manager throws`, asy
throw new Error('foo');
`);

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
const result = await runCli(cwd, [`yarn`, `--version`]);
assert.deepEqual(result, {
exitCode: 1,
stdout: ``,
stderr: expect.stringContaining(`foo`),
});
assert.match(result.stderr, /foo/);
});
});

Expand All @@ -659,7 +661,7 @@ it(`should not set the exit code after successfully launching the package manage
});
`);

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
assert.deepEqual(await runCli(cwd, [`yarn`, `--version`]), {
exitCode: 42,
stdout: ``,
stderr: ``,
Expand All @@ -686,7 +688,7 @@ it(`should support package managers in ESM format`, async () => {
type: `module`,
});

await expect(runCli(cwd, [`yarn`, `--version`])).resolves.toMatchObject({
assert.deepEqual(await runCli(cwd, [`yarn`, `--version`]), {
exitCode: 0,
stdout: `42\n`,
stderr: ``,
Expand Down
Loading

0 comments on commit 969cc7e

Please sign in to comment.