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

test: migrate to vitest #349

Merged
merged 6 commits into from
Jul 16, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

/shims
/coverage

/node_modules
merceyz marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions .yarn/patches/clipanion-npm-3.2.1-fc9187f56c.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/lib/platform/package.json b/lib/platform/package.json
index 5ea9d43740d1bdb509612376c0e9ce91d20f8b20..08d4f7327dee5e605107a343d73b2254ed08ddb9 100644
--- a/lib/platform/package.json
+++ b/lib/platform/package.json
@@ -1,4 +1,4 @@
{
- "main": "./node",
+ "main": "./node.js",
"browser": "./browser"
}
9 changes: 0 additions & 9 deletions babel.config.js

This file was deleted.

4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
"license": "MIT",
"packageManager": "[email protected]+sha224.934d21773e22af4b69a7032a2d3b4cb38c1f7c019624777cc9916b23",
"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/proxy-from-env": "^1",
"@types/semver": "^7.1.0",
Expand All @@ -32,13 +27,11 @@
"@yarnpkg/eslint-config": "^2.0.0",
"@yarnpkg/fslib": "^3.0.0-rc.48",
"@zkochan/cmd-shim": "^6.0.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"better-sqlite3": "^10.0.0",
"clipanion": "^3.0.1",
"clipanion": "patch:clipanion@npm%3A3.2.1#~/.yarn/patches/clipanion-npm-3.2.1-fc9187f56c.patch",
"debug": "^4.1.1",
"esbuild": "^0.21.0",
"eslint": "^8.57.0",
"jest": "^29.0.0",
"proxy-from-env": "^1.1.0",
"semver": "^7.5.2",
"supports-color": "^9.0.0",
Expand All @@ -47,6 +40,7 @@
"typescript": "^5.3.3",
"undici": "^6.19.2",
"v8-compile-cache": "^2.3.0",
"vitest": "^2.0.3",
"which": "^4.0.0"
},
"resolutions": {
Expand All @@ -62,7 +56,7 @@
"postpack": "run clean",
"rimraf": "node -e 'for(let i=2;i<process.argv.length;i++)fs.rmSync(process.argv[i],{recursive:true,force:true});'",
"typecheck": "tsc --noEmit",
"test": "jest"
"test": "vitest"
},
"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, expect} from 'vitest';

import {Engine} from '../sources/Engine';
import {SupportedPackageManagerSetWithoutNpm} from '../sources/types';
Expand Down
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, expect} from 'vitest';

import {Engine} from '../sources/Engine';
import {SupportedPackageManagers, SupportedPackageManagerSetWithoutNpm} from '../sources/types';
Expand Down
2 changes: 1 addition & 1 deletion tests/Up.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import process from 'node:process';
import {describe, beforeEach, it, expect} from 'vitest';

import {runCli} from './_runCli';

Expand Down
2 changes: 1 addition & 1 deletion tests/Use.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, beforeEach, it, expect} from '@jest/globals';
import {ppath, xfs, npath} from '@yarnpkg/fslib';
import process from 'node:process';
import {describe, beforeEach, it, expect} from 'vitest';

import {runCli} from './_runCli';

Expand Down
8 changes: 4 additions & 4 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {jest, describe, it, expect} from '@jest/globals';
import {vi, describe, it, expect} from 'vitest';

import defaultConfig from '../config.json';
import {DEFAULT_NPM_REGISTRY_URL} from '../sources/npmRegistryUtils';
import defaultConfig from '../config.json';
import {DEFAULT_NPM_REGISTRY_URL} from '../sources/npmRegistryUtils';

jest.mock(`../sources/httpUtils`);
vi.mock(`../sources/httpUtils`);

describe(`key store should be up-to-date`, () => {
it(`should contain up-to-date npm keys`, async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/corepackUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it, expect} from '@jest/globals';
import {describe, it, expect} from 'vitest';

import {shouldSkipIntegrityCheck} from '../sources/corepackUtils';

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

import config from '../config.json';
import * as folderUtils from '../sources/folderUtils';
Expand Down Expand Up @@ -48,7 +48,7 @@ it(`should refuse to download a known package manager from a URL`, async () => {
});
});

it.failing(`should refuse to download a known package manager from a URL in package.json`, async () => {
it.fails(`should refuse to download a known package manager from a URL in package.json`, async () => {
await xfs.mktempPromise(async cwd => {
// Package managers known by Corepack cannot be loaded from a URL.
await xfs.writeJsonPromise(ppath.join(cwd, `package.json` as Filename), {
Expand Down
6 changes: 3 additions & 3 deletions tests/npmRegistryUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {jest, describe, beforeEach, it, expect} from '@jest/globals';
import {Buffer} from 'node:buffer';
import process from 'node:process';
import {describe, beforeEach, it, expect, vi} from 'vitest';

import {fetchAsJson as httpFetchAsJson} from '../sources/httpUtils';
import {DEFAULT_HEADERS, DEFAULT_NPM_REGISTRY_URL, fetchAsJson} from '../sources/npmRegistryUtils';

jest.mock(`../sources/httpUtils`);
vi.mock(`../sources/httpUtils`);

describe(`npm registry utils fetchAsJson`, () => {
beforeEach(() => {
jest.resetAllMocks();
vi.resetAllMocks();
});

it(`throw usage error if COREPACK_ENABLE_NETWORK env is set to 0`, async () => {
Expand Down
7 changes: 2 additions & 5 deletions tests/setupTests.js → tests/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* global jest, beforeEach, afterAll */

const process = require(`process`);

jest.retryTimes(2, {logErrorsBeforeRetry: true});
import process from 'process';
import {beforeEach, afterAll} from 'vitest';

const OLD_ENV = process.env;
// To ensure we test the default behavior, we must remove these env vars
Expand Down
13 changes: 13 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {defineConfig} from 'vitest/config';

// eslint-disable-next-line arca/no-default-export
export default defineConfig({
test: {
setupFiles: [`./tests/setupTests.ts`],
testTimeout: 120000,
retry: 2,
},
esbuild: {
target: `node${process.versions.node}`,
},
});
Loading