From 19ba181cbb5ef24a8c121213757d3b359b778840 Mon Sep 17 00:00:00 2001 From: jimmy-guzman Date: Fri, 22 Nov 2024 18:53:29 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20make=20`jest/expect-expec?= =?UTF-8?q?t`=20an=20error=20instead=20of=20warn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configs/testing.spec.ts | 2 +- src/configs/testing.ts | 50 +++++++++++---------- src/rules/__snapshots__/jest.spec.ts.snap | 2 +- src/rules/__snapshots__/vitest.spec.ts.snap | 2 +- src/rules/jest.ts | 1 + 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/configs/testing.spec.ts b/src/configs/testing.spec.ts index 896876c..d12fc28 100644 --- a/src/configs/testing.spec.ts +++ b/src/configs/testing.spec.ts @@ -3,7 +3,7 @@ import { testingConfig } from "./testing"; describe("testingConfig", () => { it("should create default config w/ vitest overrides", async () => { - const [vitest] = await testingConfig({}, false); + const [, vitest] = await testingConfig({}, false); expect(vitest?.rules).toStrictEqual( expect.objectContaining({ diff --git a/src/configs/testing.ts b/src/configs/testing.ts index e8dbba6..1ad2039 100644 --- a/src/configs/testing.ts +++ b/src/configs/testing.ts @@ -1,4 +1,4 @@ -import type { Rules, TestingOptions } from "../types"; +import type { Rules, TestingOptions, TypedConfigItem } from "../types"; import { GLOB_E2E, GLOB_TESTS } from "../constants"; import { hasJest, hasVitest } from "../has-dep"; @@ -10,32 +10,10 @@ export const testingConfig = async ( { framework = "vitest" }: TestingOptions = {}, autoDetect = true, ) => { - const jestPlugin = await interopDefault(import("eslint-plugin-jest")); - const isVitest = autoDetect ? hasVitest() : framework === "vitest"; const isJest = framework === "jest" || (autoDetect && hasJest()); - return [ - ...(isVitest - ? [ - { - files: GLOB_TESTS, - name: "jimmy.codes/vitest", - ...jestPlugin.configs["flat/recommended"], - rules: await vitestRules(), - }, - ] - : []), - ...(isJest - ? [ - { - files: GLOB_TESTS, - name: "jimmy.codes/jest", - ...jestPlugin.configs["flat/recommended"], - rules: await jestRules(), - }, - ] - : []), + const configs: TypedConfigItem[] = [ { files: GLOB_E2E, name: "jimmy.codes/e2e", @@ -46,4 +24,28 @@ export const testingConfig = async ( } satisfies Rules, }, ]; + + if (isVitest) { + const jestPlugin = await interopDefault(import("eslint-plugin-jest")); + + configs.push({ + files: GLOB_TESTS, + ...jestPlugin.configs["flat/recommended"], + name: "jimmy.codes/vitest", + rules: await vitestRules(), + }); + } + + if (isJest) { + const jestPlugin = await interopDefault(import("eslint-plugin-jest")); + + configs.push({ + files: GLOB_TESTS, + ...jestPlugin.configs["flat/recommended"], + name: "jimmy.codes/jest", + rules: await jestRules(), + }); + } + + return configs; }; diff --git a/src/rules/__snapshots__/jest.spec.ts.snap b/src/rules/__snapshots__/jest.spec.ts.snap index c1ec795..a258f7f 100644 --- a/src/rules/__snapshots__/jest.spec.ts.snap +++ b/src/rules/__snapshots__/jest.spec.ts.snap @@ -9,7 +9,7 @@ exports[`should create jest rules 1`] = ` "withinDescribe": "it", }, ], - "jest/expect-expect": "warn", + "jest/expect-expect": "error", "jest/no-alias-methods": "error", "jest/no-commented-out-tests": "error", "jest/no-conditional-expect": "error", diff --git a/src/rules/__snapshots__/vitest.spec.ts.snap b/src/rules/__snapshots__/vitest.spec.ts.snap index f5ad4e0..5533b32 100644 --- a/src/rules/__snapshots__/vitest.spec.ts.snap +++ b/src/rules/__snapshots__/vitest.spec.ts.snap @@ -9,7 +9,7 @@ exports[`should create vitest rules 1`] = ` "withinDescribe": "it", }, ], - "jest/expect-expect": "warn", + "jest/expect-expect": "error", "jest/no-alias-methods": "error", "jest/no-commented-out-tests": "error", "jest/no-conditional-expect": "error", diff --git a/src/rules/jest.ts b/src/rules/jest.ts index 49826eb..6663d90 100644 --- a/src/rules/jest.ts +++ b/src/rules/jest.ts @@ -15,6 +15,7 @@ export const jestRules = async () => { withinDescribe: "it", }, ], + "jest/expect-expect": "error", "jest/no-alias-methods": "error", "jest/no-commented-out-tests": "error", "jest/no-conditional-in-test": "error",