Skip to content

test: migrate to vitest #274

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: yarn --immutable

- name: Build and Test
run: yarn run-s test-compiled test
run: yarn run-s build test

- name: Lint
run: yarn lint
Expand Down
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import json from 'eslint-plugin-json'
import * as mdx from 'eslint-plugin-mdx'
import n from 'eslint-plugin-n'
import unicorn from 'eslint-plugin-unicorn'
import vitest from 'eslint-plugin-vitest'
import yml from 'eslint-plugin-yml'
import prettier from 'eslint-plugin-prettier/recommended'
import { createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
Expand Down Expand Up @@ -108,6 +109,10 @@ export default config(
'import-x/unambiguous': 'off',
},
},
{
files: ['test/**/*.spec.ts'],
extends: [vitest.configs.recommended],
},
{
files: ['**/*.ts'],
rules: {
Expand Down Expand Up @@ -150,7 +155,7 @@ export default config(
'**/*.d.ts',
'**/.eslintrc.js',
'eslint.config.js',
'jest.config.ts',
'vitest.config.ts',
],
rules: {
'import-x/no-extraneous-dependencies': 'off',
Expand Down
29 changes: 0 additions & 29 deletions jest.config.ts

This file was deleted.

11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
"lint:tsc": "tsc -p tsconfig.lib.json --noEmit",
"prepare": "patch-package && simple-git-hooks && yarn-berry-deduplicate || exit 0",
"release": "clean-pkg-json && changeset publish",
"test": "node --experimental-vm-modules --no-warnings=ESLintRCWarning node_modules/jest/bin/jest.js",
"test-compiled": "yarn build && TEST_COMPILED=1 yarn test",
"test": "node --no-warnings=ESLintRCWarning node_modules/vitest/vitest.mjs --run",
"update:eslint-docs": "eslint-doc-generator --rule-doc-title-format prefix-name --rule-doc-section-options false --rule-list-split meta.docs.category --ignore-config stage-0 --config-emoji recommended,☑️",
"watch": "yarn test --watch"
},
Expand Down Expand Up @@ -107,16 +106,12 @@
"@eslint/import-test-order-redirect-scoped": "link:./test/fixtures/order-redirect-scoped",
"@eslint/js": "^9.23.0",
"@pkgr/rollup": "^6.0.1",
"@swc-node/jest": "^1.8.13",
"@swc/core": "^1.11.13",
"@swc/helpers": "^0.5.15",
"@test-scope/some-module": "link:./test/fixtures/symlinked-module",
"@total-typescript/ts-reset": "^0.6.1",
"@types/debug": "^4.1.12",
"@types/eslint": "^9.6.1",
"@types/eslint8.56": "npm:@types/eslint@~8.56.12",
"@types/is-glob": "^4.0.4",
"@types/jest": "^29.5.14",
"@types/json-schema": "^7.0.15",
"@types/klaw-sync": "^6.0.5",
"@types/node": "^22.13.14",
Expand All @@ -134,18 +129,17 @@
"eslint-import-test-order-redirect": "link:./test/fixtures/order-redirect",
"eslint-plugin-eslint-plugin": "^6.4.0",
"eslint-plugin-import-x": "link:.",
"eslint-plugin-jest": "^28.11.0",
"eslint-plugin-json": "^4.0.1",
"eslint-plugin-mdx": "^3.3.1",
"eslint-plugin-n": "^17.17.0",
"eslint-plugin-prettier": "^5.2.5",
"eslint-plugin-unicorn": "^58.0.0",
"eslint-plugin-vitest": "^0.5.4",
"eslint-plugin-yml": "^1.17.0",
"eslint8.56": "npm:eslint@~8.56.0",
"eslint9": "npm:eslint@^9.23.0",
"globals": "^16.0.0",
"hermes-eslint": "^0.27.0",
"jest": "^30.0.0-alpha.7",
"klaw-sync": "^7.0.0",
"lint-staged": "^15.5.0",
"npm-run-all2": "^7.0.2",
Expand All @@ -159,6 +153,7 @@
"type-fest": "^4.38.0",
"typescript": "^5.8.2",
"typescript-eslint": "^8.28.0",
"vitest": "^3.0.9",
"yarn-berry-deduplicate": "^6.1.1",
"zod": "^3.24.2"
},
Expand Down
20 changes: 0 additions & 20 deletions patches/@swc-node+jest+1.8.13.patch

This file was deleted.

4 changes: 2 additions & 2 deletions src/rules/no-unused-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import path from 'node:path'

import { TSESTree } from '@typescript-eslint/utils'
import type { TSESLint } from '@typescript-eslint/utils'
// eslint-disable-next-line import-x/default -- incorrect types , commonjs actually
// eslint-disable-next-line import-x/default -- incorrect types, commonjs actually
import eslintUnsupportedApi from 'eslint/use-at-your-own-risk'

import type { FileExtension, RuleContext } from '../types.js'
Expand All @@ -22,7 +22,7 @@ import {
getValue,
} from '../utils/index.js'

// eslint-disable-next-line import-x/no-named-as-default-member -- incorrect types , commonjs actually
// eslint-disable-next-line import-x/no-named-as-default-member -- incorrect types, commonjs actually
const { FileEnumerator } = eslintUnsupportedApi

function listFilesToProcess(src: string[], extensions: FileExtension[]) {
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/fixtures.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`yarn pnp should just work 1`] = `
exports[`yarn pnp > should just work 1`] = `
{
"exitCode": 0,
"stderr": "",
Expand Down
54 changes: 27 additions & 27 deletions test/__snapshots__/node-resolver.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`builtin node:path => true 1`] = `
exports[`builtin > node:path => true 1`] = `
{
"expected": true,
"requireResolve": "node:path",
"source": "node:path",
}
`;

exports[`builtin node:path => true 2`] = `
exports[`builtin > node:path => true 2`] = `
{
"expected": true,
"result": {
Expand All @@ -19,15 +19,15 @@ exports[`builtin node:path => true 2`] = `
}
`;

exports[`builtin path => true 1`] = `
exports[`builtin > path => true 1`] = `
{
"expected": true,
"requireResolve": "path",
"source": "path",
}
`;

exports[`builtin path => true 2`] = `
exports[`builtin > path => true 2`] = `
{
"expected": true,
"result": {
Expand All @@ -38,15 +38,15 @@ exports[`builtin path => true 2`] = `
}
`;

exports[`modules @sukka/does-not-exists => false 1`] = `
exports[`modules > @sukka/does-not-exists => false 1`] = `
{
"expected": false,
"requireResolve": undefined,
"source": "@sukka/does-not-exists",
}
`;

exports[`modules @sukka/does-not-exists => false 2`] = `
exports[`modules > @sukka/does-not-exists => false 2`] = `
{
"expected": false,
"result": {
Expand All @@ -56,34 +56,34 @@ exports[`modules @sukka/does-not-exists => false 2`] = `
}
`;

exports[`modules jest => true 1`] = `
exports[`modules > vitest => true 1`] = `
{
"expected": true,
"requireResolve": "<ROOT>/node_modules/jest/build/index.js",
"source": "jest",
"requireResolve": "<ROOT>/node_modules/vitest/index.cjs",
"source": "vitest",
}
`;

exports[`modules jest => true 2`] = `
exports[`modules > vitest => true 2`] = `
{
"expected": true,
"result": {
"found": true,
"path": "<ROOT>/node_modules/jest/build/index.js",
"path": "<ROOT>/node_modules/vitest/dist/index.js",
},
"source": "jest",
"source": "vitest",
}
`;

exports[`relative ../.github/dependabot.yml => false 1`] = `
exports[`relative > ../.github/dependabot.yml => false 1`] = `
{
"expected": false,
"requireResolve": undefined,
"source": "../.github/dependabot.yml",
}
`;

exports[`relative ../.github/dependabot.yml => false 2`] = `
exports[`relative > ../.github/dependabot.yml => false 2`] = `
{
"expected": false,
"result": {
Expand All @@ -93,15 +93,15 @@ exports[`relative ../.github/dependabot.yml => false 2`] = `
}
`;

exports[`relative ../babel.config.cjs => babel.config.cjs 1`] = `
exports[`relative > ../babel.config.cjs => babel.config.cjs 1`] = `
{
"expected": "babel.config.cjs",
"requireResolve": "<ROOT>/babel.config.cjs",
"source": "../babel.config.cjs",
}
`;

exports[`relative ../babel.config.cjs => babel.config.cjs 2`] = `
exports[`relative > ../babel.config.cjs => babel.config.cjs 2`] = `
{
"expected": "babel.config.cjs",
"result": {
Expand All @@ -112,15 +112,15 @@ exports[`relative ../babel.config.cjs => babel.config.cjs 2`] = `
}
`;

exports[`relative ../inexistent.js => false 1`] = `
exports[`relative > ../inexistent.js => false 1`] = `
{
"expected": false,
"requireResolve": undefined,
"source": "../inexistent.js",
}
`;

exports[`relative ../inexistent.js => false 2`] = `
exports[`relative > ../inexistent.js => false 2`] = `
{
"expected": false,
"result": {
Expand All @@ -130,15 +130,15 @@ exports[`relative ../inexistent.js => false 2`] = `
}
`;

exports[`relative ../package.json => package.json 1`] = `
exports[`relative > ../package.json => package.json 1`] = `
{
"expected": "package.json",
"requireResolve": "<ROOT>/package.json",
"source": "../package.json",
}
`;

exports[`relative ../package.json => package.json 2`] = `
exports[`relative > ../package.json => package.json 2`] = `
{
"expected": "package.json",
"result": {
Expand All @@ -149,15 +149,15 @@ exports[`relative ../package.json => package.json 2`] = `
}
`;

exports[`relative ../test => test/index.js 1`] = `
exports[`relative > ../test => test/index.js 1`] = `
{
"expected": "test/index.js",
"requireResolve": "<ROOT>/test/index.js",
"source": "../test",
}
`;

exports[`relative ../test => test/index.js 2`] = `
exports[`relative > ../test => test/index.js 2`] = `
{
"expected": "test/index.js",
"result": {
Expand All @@ -168,15 +168,15 @@ exports[`relative ../test => test/index.js 2`] = `
}
`;

exports[`relative ../test/ => test/index.js 1`] = `
exports[`relative > ../test/ => test/index.js 1`] = `
{
"expected": "test/index.js",
"requireResolve": "<ROOT>/test/index.js",
"source": "../test/",
}
`;

exports[`relative ../test/ => test/index.js 2`] = `
exports[`relative > ../test/ => test/index.js 2`] = `
{
"expected": "test/index.js",
"result": {
Expand All @@ -187,15 +187,15 @@ exports[`relative ../test/ => test/index.js 2`] = `
}
`;

exports[`relative ../test/index.js => test/index.js 1`] = `
exports[`relative > ../test/index.js => test/index.js 1`] = `
{
"expected": "test/index.js",
"requireResolve": "<ROOT>/test/index.js",
"source": "../test/index.js",
}
`;

exports[`relative ../test/index.js => test/index.js 2`] = `
exports[`relative > ../test/index.js => test/index.js 2`] = `
{
"expected": "test/index.js",
"result": {
Expand Down
5 changes: 3 additions & 2 deletions test/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'

// eslint-disable-next-line import-x/default -- incorrect types , commonjs actually
// eslint-disable-next-line import-x/default -- incorrect types, commonjs actually
import eslintUnsupportedApi from 'eslint/use-at-your-own-risk'

import importPlugin from 'eslint-plugin-import-x'

// eslint-disable-next-line import-x/no-named-as-default-member -- incorrect types , commonjs actually
// eslint-disable-next-line import-x/no-named-as-default-member -- incorrect types, commonjs actually
const { LegacyESLint } = eslintUnsupportedApi

describe('CLI regression tests', () => {
const testDir = path.resolve(fileURLToPath(import.meta.url), '..')

describe('issue #210', () => {
// eslint-disable-next-line vitest/expect-expect
it("doesn't throw an error on gratuitous, erroneous self-reference", () => {
const eslint = new LegacyESLint({
cwd: testDir,
Expand Down
File renamed without changes.
Empty file added test/fixtures/CaseyKasem-src.js
Empty file.
2 changes: 2 additions & 0 deletions test/fixtures/deep/cache-1-lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as b from './cache-2-lib'
export { b }
Loading
Loading