Skip to content

Commit

Permalink
feat: ✨ use @vitest/eslint-plugin for vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Nov 5, 2024
1 parent e644b68 commit 023b2dc
Show file tree
Hide file tree
Showing 8 changed files with 559 additions and 64 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/eslint": "9.6.1",
"@typescript-eslint/parser": "^8.13.0",
"@typescript-eslint/utils": "^8.13.0",
"@vitest/eslint-plugin": "^1.1.7",
"astro-eslint-parser": "^1.0.3",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion scripts/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ const ruleDts = await flatConfigsToRulesDTS(
},
},
// @ts-expect-error TODO: config types don't seem to match
...config(),
...config({
testing: {
// TODO: remove when framework approach is removed
framework: "jest",
},
}),
],
{
includeAugmentation: false,
Expand Down
36 changes: 0 additions & 36 deletions src/configs/testing.spec.ts

This file was deleted.

26 changes: 8 additions & 18 deletions src/configs/testing.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import vitest from "@vitest/eslint-plugin";
import jest from "eslint-plugin-jest";

import type { Rules, TestingOptions } from "../types";

import { ALLOWED_VITEST_FUNCS, GLOB_E2E, GLOB_TESTS } from "../constants";
import { GLOB_E2E, GLOB_TESTS } from "../constants";
import { hasJest, hasTestingLibrary, hasVitest } from "../has-dep";
import { jestRules } from "../rules/jest";
import { vitestRules } from "../rules/vitest";
import testingLibraryConfig from "./testing-library";

const testingConfig = (
Expand All @@ -18,36 +20,22 @@ const testingConfig = (
(autoDetect && hasTestingLibrary());

return [
{
files: GLOB_TESTS,
name: "jimmy.codes/testing",
...jest.configs["flat/recommended"],
},
...(isVitest
? [
{
files: GLOB_TESTS,
...vitest.configs.recommended,
name: "jimmy.codes/testing/vitest",
...jest.configs["flat/recommended"],
rules: {
...jestRules,
"jest/no-deprecated-functions": "off",
"jest/require-hook": [
"error",
{
allowedFunctionCalls: ALLOWED_VITEST_FUNCS,
},
],
} satisfies Rules,
rules: vitestRules,
},
]
: []),
...(isJest
? [
{
files: GLOB_TESTS,
name: "jimmy.codes/testing/jest",
...jest.configs["flat/recommended"],
name: "jimmy.codes/testing/jest",
rules: jestRules,
},
]
Expand All @@ -59,6 +47,8 @@ const testingConfig = (
"jest/expect-expect": "off",
"jest/no-deprecated-functions": "off",
"jest/require-hook": "off",
"vitest/expect-expect": "off",
"vitest/require-hook": "off",
} satisfies Rules,
},
...(includeTestingLibrary ? testingLibraryConfig() : []),
Expand Down
12 changes: 3 additions & 9 deletions src/factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ describe("jimmyDotCodes", () => {
jimmyDotCodes({ autoDetect: false, testing: { framework: "jest" } }),
).toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/testing" }),
expect.objectContaining({ name: "jimmy.codes/testing/disabled" }),
expect.objectContaining({ name: "jimmy.codes/testing/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/testing/vitest" }),
Expand All @@ -73,7 +72,6 @@ describe("jimmyDotCodes", () => {
it("should create configuration w/ vitest", () => {
expect(jimmyDotCodes({ autoDetect: false, testing: true })).toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/testing" }),
expect.objectContaining({ name: "jimmy.codes/testing/disabled" }),
expect.not.objectContaining({ name: "jimmy.codes/testing/jest" }),
expect.objectContaining({ name: "jimmy.codes/testing/vitest" }),
Expand All @@ -90,7 +88,6 @@ describe("jimmyDotCodes", () => {
}),
).toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/testing" }),
expect.objectContaining({ name: "jimmy.codes/testing/disabled" }),
expect.objectContaining({ name: "jimmy.codes/testing/jest" }),
expect.objectContaining({ name: "jimmy.codes/react" }),
Expand All @@ -113,7 +110,6 @@ describe("jimmyDotCodes", () => {
}),
).toStrictEqual(
expect.arrayContaining([
expect.objectContaining({ name: "jimmy.codes/testing" }),
expect.objectContaining({ name: "jimmy.codes/testing/disabled" }),
expect.objectContaining({ name: "jimmy.codes/testing/vitest" }),
expect.objectContaining({ name: "jimmy.codes/react" }),
Expand Down Expand Up @@ -186,7 +182,6 @@ describe("jimmyDotCodes", () => {

it("should include react-query when auto detection is enabled", () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
// eslint-disable-next-line jest/no-conditional-in-test -- this condition is only for the mock.
return name === "react" || name === "@tanstack/react-query";
});

Expand All @@ -213,7 +208,7 @@ describe("jimmyDotCodes", () => {
expect(jimmyDotCodes({ autoDetect: true })).toStrictEqual(
expect.arrayContaining([
expect.not.objectContaining({ name: "jimmy.codes/typescript" }),
expect.objectContaining({ name: "jimmy.codes/testing" }),

expect.objectContaining({ name: "jimmy.codes/testing/vitest" }),
expect.not.objectContaining({ name: "jimmy.codes/testing/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/react" }),
Expand All @@ -233,7 +228,7 @@ describe("jimmyDotCodes", () => {
expect(jimmyDotCodes({ autoDetect: true })).toStrictEqual(
expect.arrayContaining([
expect.not.objectContaining({ name: "jimmy.codes/typescript" }),
expect.objectContaining({ name: "jimmy.codes/testing" }),

expect.not.objectContaining({ name: "jimmy.codes/testing/vitest" }),
expect.objectContaining({ name: "jimmy.codes/testing/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/react" }),
Expand All @@ -247,14 +242,13 @@ describe("jimmyDotCodes", () => {

it("should include test-library when auto detection is enabled", () => {
vi.mocked(isPackageExists).mockImplementation((name) => {
// eslint-disable-next-line jest/no-conditional-in-test -- this condition is only for the mock.
return name === "@testing-library/react" || name === "vitest";
});

expect(jimmyDotCodes({ autoDetect: true })).toStrictEqual(
expect.arrayContaining([
expect.not.objectContaining({ name: "jimmy.codes/typescript" }),
expect.objectContaining({ name: "jimmy.codes/testing" }),

expect.objectContaining({ name: "jimmy.codes/testing/vitest" }),
expect.not.objectContaining({ name: "jimmy.codes/testing/jest" }),
expect.not.objectContaining({ name: "jimmy.codes/react" }),
Expand Down
Loading

0 comments on commit 023b2dc

Please sign in to comment.