Skip to content

Commit

Permalink
fix: πŸ› make jest/expect-expect an error instead of warn
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Nov 23, 2024
1 parent 4d266e4 commit 19ba181
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/configs/testing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
50 changes: 26 additions & 24 deletions src/configs/testing.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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",
Expand All @@ -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;
};
2 changes: 1 addition & 1 deletion src/rules/__snapshots__/jest.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/rules/__snapshots__/vitest.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/rules/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 19ba181

Please sign in to comment.