Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to node:test #357

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions babel.config.js

This file was deleted.

Empty file removed global.d.ts
Empty file.
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
"license": "MIT",
"packageManager": "[email protected]+sha256.825003a0f561ad09a3b1ac4a3b3ea6207af2796d54f62a9420520915721f5186",
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/plugin-transform-modules-commonjs": "^7.14.0",
"@babel/preset-typescript": "^7.13.0",
"@jest/globals": "^29.0.0",
"@types/debug": "^4.1.5",
"@types/jest": "^29.0.0",
"@types/node": "^20.4.6",
"@types/semver": "^7.1.0",
"@types/tar": "^6.0.0",
Expand All @@ -33,32 +28,30 @@
"@yarnpkg/eslint-config": "^1.0.0",
"@yarnpkg/fslib": "^3.0.0-rc.48",
"@zkochan/cmd-shim": "^6.0.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"clipanion": "^3.0.1",
"debug": "^4.1.1",
"esbuild": "0.19.5",
"eslint": "^8.0.0",
"eslint-plugin-arca": "^0.16.0",
"jest": "^29.0.0",
"nock": "^13.0.4",
"proxy-agent": "^6.2.2",
"semver": "^7.5.2",
"supports-color": "^9.0.0",
"tar": "^6.0.1",
"ts-node": "^10.0.0",
"tsx": "^4.7.0",
"typescript": "^5.0.4",
"v8-compile-cache": "^2.3.0",
"which": "^4.0.0"
},
"scripts": {
"build": "rm -rf dist shims && run build:bundle && ts-node ./mkshims.ts",
"build": "rm -rf dist shims && run build:bundle && tsx ./mkshims.ts",
"build:bundle": "esbuild ./sources/_lib.ts --bundle --platform=node --target=node18.17.0 --external:corepack --outfile='./dist/lib/corepack.cjs' --resolve-extensions='.ts,.mjs,.js'",
"corepack": "ts-node ./sources/_cli.ts",
"corepack": "tsx ./sources/_cli.ts",
"lint": "eslint .",
"prepack": "yarn build",
"postpack": "rm -rf dist shims",
"typecheck": "tsc --noEmit",
"test": "jest"
"test": "node --test --import tsx --import ./tests/setupTests.ts"
},
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion tests/Disable.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';

import {Engine} from '../sources/Engine';
import {SupportedPackageManagerSetWithoutNpm} from '../sources/types';
Expand Down Expand Up @@ -29,7 +29,7 @@
const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`disable`])).resolves.toMatchObject({

Check failure on line 32 in tests/Disable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
exitCode: 0,
});
} finally {
Expand All @@ -40,7 +40,7 @@
return entries.sort();
});

await expect(sortedEntries).resolves.toEqual([

Check failure on line 43 in tests/Disable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
ppath.basename(corepackBin),
ppath.basename(dontRemoveBin),
]);
Expand All @@ -56,11 +56,11 @@
for (const variant of getBinaryNames(binName))
await makeBin(cwd, variant as Filename, {ignorePlatform: true});

await expect(runCli(cwd, [`disable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({

Check failure on line 59 in tests/Disable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
exitCode: 0,
});

await expect(xfs.readdirPromise(cwd)).resolves.toEqual([

Check failure on line 63 in tests/Disable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
ppath.basename(dontRemoveBin),
]);
});
Expand All @@ -87,7 +87,7 @@
const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`disable`, `yarn`])).resolves.toMatchObject({

Check failure on line 90 in tests/Disable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
exitCode: 0,
});
} finally {
Expand All @@ -103,7 +103,7 @@
return entries.sort();
});

await expect(sortedEntries).resolves.toEqual([...binNames].sort());

Check failure on line 106 in tests/Disable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
});
});
});
2 changes: 1 addition & 1 deletion tests/Enable.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {Filename, ppath, xfs, npath} from '@yarnpkg/fslib';
import {delimiter} from 'node:path';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';

import {Engine} from '../sources/Engine';
import {SupportedPackageManagers, SupportedPackageManagerSetWithoutNpm} from '../sources/types';
Expand All @@ -24,7 +24,7 @@
const PATH = process.env.PATH;
try {
process.env.PATH = `${npath.fromPortablePath(cwd)}${delimiter}${PATH}`;
await expect(runCli(cwd, [`enable`])).resolves.toMatchObject({

Check failure on line 27 in tests/Enable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
stdout: ``,
stderr: ``,
exitCode: 0,
Expand All @@ -42,7 +42,7 @@
for (const binName of engine.getBinariesFor(packageManager))
expectedEntries.push(...getBinaryNames(binName));

await expect(sortedEntries).resolves.toEqual(expectedEntries.sort());

Check failure on line 45 in tests/Enable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
});
});

Expand All @@ -50,7 +50,7 @@
await xfs.mktempPromise(async cwd => {
const corepackBin = await makeBin(cwd, `corepack` as Filename);

await expect(runCli(cwd, [`enable`, `--install-directory`, npath.fromPortablePath(cwd)])).resolves.toMatchObject({

Check failure on line 53 in tests/Enable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
stdout: ``,
stderr: ``,
exitCode: 0,
Expand All @@ -65,7 +65,7 @@
for (const binName of engine.getBinariesFor(packageManager))
expectedEntries.push(...getBinaryNames(binName));

await expect(sortedEntries).resolves.toEqual(expectedEntries.sort());

Check failure on line 68 in tests/Enable.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Cannot find name 'expect'.
});
});

Expand Down
8 changes: 4 additions & 4 deletions tests/Up.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import process from 'node:process';
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';

import {runCli} from './_runCli';
import {runCli} from './_runCli';

beforeEach(async () => {
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
Expand Down
15 changes: 8 additions & 7 deletions tests/Use.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import process from 'node:process';
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import assert from 'node:assert';
import process from 'node:process';
import {describe, beforeEach, it} from 'node:test';

import {runCli} from './_runCli';
import {runCli} from './_runCli';

beforeEach(async () => {
process.env.COREPACK_HOME = npath.fromPortablePath(await xfs.mktempPromise());
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
6 changes: 3 additions & 3 deletions tests/httpUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {jest, describe, beforeEach, beforeAll, it, expect} from '@jest/globals';
import {describe, beforeEach, before, it} from 'node:test';

import {fetchUrlStream} from '../sources/httpUtils';
import {fetchUrlStream} from '../sources/httpUtils';


describe(`http utils fetchUrlStream`, () => {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe(`http utils fetchUrlStream`, () => {
};
});

beforeAll(() => {
before(() => {
jest.doMock(`https`, () => ({
get: httpsGetFn,
Agent: class Agent {},
Expand Down
22 changes: 12 additions & 10 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {beforeEach, it, expect} from '@jest/globals';
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';

import config from '../config.json';

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
2 changes: 1 addition & 1 deletion tests/npmRegistryUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {jest, describe, beforeEach, afterEach, it, expect} from '@jest/globals';
import {Buffer} from 'node:buffer';
import process from 'node:process';
import {describe, beforeEach, afterEach, it} from 'node:test';

import {fetchAsJson as httpFetchAsJson} from '../sources/httpUtils';
import {DEFAULT_HEADERS, DEFAULT_NPM_REGISTRY_URL, fetchAsJson} from '../sources/npmRegistryUtils';
Expand Down
14 changes: 6 additions & 8 deletions tests/setupTests.js → tests/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* global jest, expect, beforeEach, afterAll */
import crypto from 'crypto';
import {beforeEach, after} from 'node:test';

const crypto = require(`crypto`);

jest.retryTimes(2, {logErrorsBeforeRetry: true});

switch (process.env.NOCK_ENV || ``) {
case `record`:
case `replay`:
beforeEach(() => {
beforeEach(context => {
// To ensure we test the default behavior, we must remove these env vars
// in case the local machine already set these values.
delete process.env.COREPACK_DEFAULT_TO_LATEST;
Expand All @@ -20,14 +18,14 @@ switch (process.env.NOCK_ENV || ``) {
delete process.env.COREPACK_NPM_USERNAME;
delete process.env.FORCE_COLOR;

process.env.RUN_CLI_ID = 0;
process.env.RUN_CLI_ID = `0`;
process.env.NOCK_FILE_NAME = crypto
.createHash(`md5`)
.update(expect.getState().currentTestName)
.update(context.name)
.digest(`base64url`);
});

afterAll(() => {
after(() => {
delete process.env.RUN_CLI_ID;
delete process.env.NOCK_FILE_NAME;
});
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
"strict": true,
"target": "ES2022"
},
"ts-node": {
"transpileOnly": true
}
}
Loading