Skip to content

Commit 06d836e

Browse files
authored
ci: add eslint-plugin-jest (#9052)
1 parent 3e7e502 commit 06d836e

File tree

9 files changed

+104
-33
lines changed

9 files changed

+104
-33
lines changed

.eslintrc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22
"extends": ["react-app"],
33
"rules": {
44
"import/first": 0
5-
}
5+
},
6+
"overrides": [
7+
{
8+
"files": ["**/__tests__/**"],
9+
"plugins": ["jest"],
10+
"extends": ["plugin:jest/recommended"]
11+
}
12+
]
613
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"eslint-config-react-app": "^6.0.0",
7575
"eslint-plugin-flowtype": "^5.8.0",
7676
"eslint-plugin-import": "^2.23.4",
77+
"eslint-plugin-jest": "^26.5.3",
7778
"eslint-plugin-jsx-a11y": "^6.4.1",
7879
"eslint-plugin-react": "^7.24.0",
7980
"eslint-plugin-react-hooks": "next",

packages/react-router-dom/__tests__/DataBrowserRouter-test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function testDomRouter(
4747
TestDataRouter: typeof DataBrowserRouter,
4848
getWindow: (initialUrl: string, isHash?: boolean) => Window
4949
) {
50-
describe(name, () => {
50+
describe(`Router: ${name}`, () => {
5151
let consoleWarn: jest.SpyInstance;
5252
let consoleError: jest.SpyInstance;
5353
beforeEach(() => {
@@ -316,8 +316,10 @@ function testDomRouter(
316316

317317
function assertPathname(pathname) {
318318
if (name === "<DataHashRouter>") {
319+
// eslint-disable-next-line jest/no-conditional-expect
319320
expect(testWindow.location.hash).toEqual("#" + pathname);
320321
} else {
322+
// eslint-disable-next-line jest/no-conditional-expect
321323
expect(testWindow.location.pathname).toEqual(pathname);
322324
}
323325
}

packages/react-router-dom/__tests__/trailing-slashes-test.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ describe("trailing slashes", () => {
334334
describe("with a basename that does not contain a trailing slash", () => {
335335
test("never includes trailing slashes on root links (/)", () => {
336336
let window = getWindowImpl("/foo/bar");
337-
spyOn(window.history, "pushState").and.callThrough();
337+
jest.spyOn(window.history, "pushState");
338338
expect(window.location.href).toBe("https://remix.run/foo/bar");
339339

340340
act(() => {
@@ -353,7 +353,7 @@ describe("trailing slashes", () => {
353353

354354
test("never includes trailing slashes on root links (../)", () => {
355355
let window = getWindowImpl("/foo/bar");
356-
spyOn(window.history, "pushState").and.callThrough();
356+
jest.spyOn(window.history, "pushState");
357357
expect(window.location.href).toBe("https://remix.run/foo/bar");
358358

359359
act(() => {
@@ -372,7 +372,7 @@ describe("trailing slashes", () => {
372372

373373
test("allows non-root links to leave off trailing slashes", () => {
374374
let window = getWindowImpl("/foo");
375-
spyOn(window.history, "pushState").and.callThrough();
375+
jest.spyOn(window.history, "pushState");
376376

377377
expect(window.location.href).toBe("https://remix.run/foo");
378378

@@ -393,7 +393,7 @@ describe("trailing slashes", () => {
393393

394394
test("allows non-root links to include trailing slashes", () => {
395395
let window = getWindowImpl("/foo");
396-
spyOn(window.history, "pushState").and.callThrough();
396+
jest.spyOn(window.history, "pushState");
397397

398398
expect(window.location.href).toBe("https://remix.run/foo");
399399

@@ -416,7 +416,7 @@ describe("trailing slashes", () => {
416416
describe("with a basename that contains a trailing slash", () => {
417417
test("always includes trailing slashes on root links (/)", () => {
418418
let window = getWindowImpl("/foo/bar");
419-
spyOn(window.history, "pushState").and.callThrough();
419+
jest.spyOn(window.history, "pushState");
420420
expect(window.location.href).toBe("https://remix.run/foo/bar");
421421

422422
act(() => {
@@ -435,7 +435,7 @@ describe("trailing slashes", () => {
435435

436436
test("always includes trailing slashes on root links (../)", () => {
437437
let window = getWindowImpl("/foo/bar");
438-
spyOn(window.history, "pushState").and.callThrough();
438+
jest.spyOn(window.history, "pushState");
439439
expect(window.location.href).toBe("https://remix.run/foo/bar");
440440

441441
act(() => {
@@ -454,7 +454,7 @@ describe("trailing slashes", () => {
454454

455455
test("allows non-root links to leave off trailing slashes", () => {
456456
let window = getWindowImpl("/foo/");
457-
spyOn(window.history, "pushState").and.callThrough();
457+
jest.spyOn(window.history, "pushState");
458458

459459
expect(window.location.href).toBe("https://remix.run/foo/");
460460

@@ -475,7 +475,7 @@ describe("trailing slashes", () => {
475475

476476
test("allows non-root links to include trailing slashes", () => {
477477
let window = getWindowImpl("/foo/");
478-
spyOn(window.history, "pushState").and.callThrough();
478+
jest.spyOn(window.history, "pushState");
479479

480480
expect(window.location.href).toBe("https://remix.run/foo/");
481481

@@ -498,7 +498,7 @@ describe("trailing slashes", () => {
498498
describe("empty string paths", () => {
499499
it("should not add trailing slashes", () => {
500500
let window = getWindowImpl("/foo/bar");
501-
spyOn(window.history, "pushState").and.callThrough();
501+
jest.spyOn(window.history, "pushState");
502502

503503
expect(window.location.href).toBe("https://remix.run/foo/bar");
504504

@@ -519,7 +519,7 @@ describe("trailing slashes", () => {
519519

520520
it("should preserve trailing slash", () => {
521521
let window = getWindowImpl("/foo/bar/");
522-
spyOn(window.history, "pushState").and.callThrough();
522+
jest.spyOn(window.history, "pushState");
523523

524524
expect(window.location.href).toBe("https://remix.run/foo/bar/");
525525

@@ -542,7 +542,7 @@ describe("trailing slashes", () => {
542542
describe("current location '.' paths", () => {
543543
it("should not add trailing slash", () => {
544544
let window = getWindowImpl("/foo/bar");
545-
spyOn(window.history, "pushState").and.callThrough();
545+
jest.spyOn(window.history, "pushState");
546546

547547
expect(window.location.href).toBe("https://remix.run/foo/bar");
548548

@@ -570,7 +570,7 @@ describe("trailing slashes", () => {
570570

571571
it("should preserve trailing slash", () => {
572572
let window = getWindowImpl("/foo/bar/");
573-
spyOn(window.history, "pushState").and.callThrough();
573+
jest.spyOn(window.history, "pushState");
574574

575575
expect(window.location.href).toBe("https://remix.run/foo/bar/");
576576

@@ -601,7 +601,7 @@ describe("trailing slashes", () => {
601601
describe("when using setSearchParams", () => {
602602
it("should not include trailing slash via useSearchParams", () => {
603603
let window = getWindowImpl("/foo");
604-
spyOn(window.history, "pushState").and.callThrough();
604+
jest.spyOn(window.history, "pushState");
605605

606606
expect(window.location.href).toBe("https://remix.run/foo");
607607

@@ -630,7 +630,7 @@ describe("trailing slashes", () => {
630630

631631
it("should include trailing slash via useSearchParams when basename has one", () => {
632632
let window = getWindowImpl("/foo/");
633-
spyOn(window.history, "pushState").and.callThrough();
633+
jest.spyOn(window.history, "pushState");
634634

635635
expect(window.location.href).toBe("https://remix.run/foo/");
636636

packages/router/__tests__/browser-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* @jest-environment ./__tests__/custom-environment.js
33
*/
44

5+
/* eslint-disable jest/expect-expect */
6+
57
import { JSDOM } from "jsdom";
68

79
import type { BrowserHistory } from "@remix-run/router";

packages/router/__tests__/hash-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* @jest-environment ./__tests__/custom-environment.js
33
*/
44

5+
/* eslint-disable jest/expect-expect */
6+
57
import { JSDOM } from "jsdom";
68

79
import type { HashHistory } from "@remix-run/router";

packages/router/__tests__/memory-test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable jest/expect-expect */
2+
13
import type { MemoryHistory } from "@remix-run/router";
24
import { createMemoryHistory } from "@remix-run/router";
35

packages/router/__tests__/router-test.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable jest/valid-title */
12
import type {
23
ActionFunction,
34
DataRouteObject,
@@ -101,12 +102,12 @@ async function tick() {
101102
await new Promise((r) => setImmediate(r));
102103
}
103104

104-
export function invariant(value: boolean, message?: string): asserts value;
105-
export function invariant<T>(
105+
function invariant(value: boolean, message?: string): asserts value;
106+
function invariant<T>(
106107
value: T | null | undefined,
107108
message?: string
108109
): asserts value is T;
109-
export function invariant(value: any, message?: string) {
110+
function invariant(value: any, message?: string) {
110111
if (value === false || value === null || typeof value === "undefined") {
111112
console.warn("Test invariant failed:", message);
112113
throw new Error(message);
@@ -769,7 +770,9 @@ beforeEach(() => {
769770
afterEach(() => {
770771
// Cleanup any routers created using setup()
771772
if (currentRouter) {
773+
// eslint-disable-next-line jest/no-standalone-expect
772774
expect(currentRouter._internalFetchControllers.size).toBe(0);
775+
// eslint-disable-next-line jest/no-standalone-expect
773776
expect(currentRouter._internalActiveDeferreds.size).toBe(0);
774777
}
775778
currentRouter?.dispose();
@@ -1009,6 +1012,10 @@ describe("a router", () => {
10091012
},
10101013
})
10111014
);
1015+
expect(t.router.state.loaderData).toMatchObject({
1016+
root: "ROOT",
1017+
foo: { key: "value" },
1018+
});
10121019
});
10131020

10141021
it("unwraps non-redirect json Responses (json helper)", async () => {
@@ -3072,12 +3079,7 @@ describe("a router", () => {
30723079
},
30733080
});
30743081
});
3075-
});
30763082

3077-
describe(`
3078-
A) POST /foo |--|--X
3079-
B) GET /bar |-----O
3080-
`, () => {
30813083
it("forces all loaders to revalidate on interrupted submissionRedirect", async () => {
30823084
let t = initializeTmTest();
30833085
let A = await t.navigate("/foo", {
@@ -6613,12 +6615,7 @@ describe("a router", () => {
66136615
expect(t.router.state.fetchers.get(key)?.state).toBe("idle");
66146616
expect(t.router.state.fetchers.get(key)?.data).toBe("A ACTION");
66156617
});
6616-
});
66176618

6618-
describe(`
6619-
A) fetch POST /foo |--|--X
6620-
B) nav GET /bar |-----O
6621-
`, () => {
66226619
it("forces all loaders to revalidate on interrupted fetcher submissionRedirect", async () => {
66236620
let key = "key";
66246621
let t = initializeTmTest();

yarn.lock

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@
22882288
"@types/parse5" "*"
22892289
"@types/tough-cookie" "*"
22902290

2291-
"@types/json-schema@^7.0.7":
2291+
"@types/json-schema@^7.0.7", "@types/json-schema@^7.0.9":
22922292
version "7.0.11"
22932293
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
22942294
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
@@ -2480,11 +2480,24 @@
24802480
"@typescript-eslint/types" "4.33.0"
24812481
"@typescript-eslint/visitor-keys" "4.33.0"
24822482

2483+
"@typescript-eslint/[email protected]":
2484+
version "5.30.6"
2485+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.30.6.tgz#ce1b49ff5ce47f55518d63dbe8fc9181ddbd1a33"
2486+
integrity sha512-Hkq5PhLgtVoW1obkqYH0i4iELctEKixkhWLPTYs55doGUKCASvkjOXOd/pisVeLdO24ZX9D6yymJ/twqpJiG3g==
2487+
dependencies:
2488+
"@typescript-eslint/types" "5.30.6"
2489+
"@typescript-eslint/visitor-keys" "5.30.6"
2490+
24832491
"@typescript-eslint/[email protected]":
24842492
version "4.33.0"
24852493
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.33.0.tgz#a1e59036a3b53ae8430ceebf2a919dc7f9af6d72"
24862494
integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ==
24872495

2496+
"@typescript-eslint/[email protected]":
2497+
version "5.30.6"
2498+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.30.6.tgz#86369d0a7af8c67024115ac1da3e8fb2d38907e1"
2499+
integrity sha512-HdnP8HioL1F7CwVmT4RaaMX57RrfqsOMclZc08wGMiDYJBsLGBM7JwXM4cZJmbWLzIR/pXg1kkrBBVpxTOwfUg==
2500+
24882501
"@typescript-eslint/[email protected]":
24892502
version "4.33.0"
24902503
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz#0dfb51c2908f68c5c08d82aefeaf166a17c24609"
@@ -2498,6 +2511,31 @@
24982511
semver "^7.3.5"
24992512
tsutils "^3.21.0"
25002513

2514+
"@typescript-eslint/[email protected]":
2515+
version "5.30.6"
2516+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.6.tgz#a84a0d6a486f9b54042da1de3d671a2c9f14484e"
2517+
integrity sha512-Z7TgPoeYUm06smfEfYF0RBkpF8csMyVnqQbLYiGgmUSTaSXTP57bt8f0UFXstbGxKIreTwQCujtaH0LY9w9B+A==
2518+
dependencies:
2519+
"@typescript-eslint/types" "5.30.6"
2520+
"@typescript-eslint/visitor-keys" "5.30.6"
2521+
debug "^4.3.4"
2522+
globby "^11.1.0"
2523+
is-glob "^4.0.3"
2524+
semver "^7.3.7"
2525+
tsutils "^3.21.0"
2526+
2527+
"@typescript-eslint/utils@^5.10.0":
2528+
version "5.30.6"
2529+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.30.6.tgz#1de2da14f678e7d187daa6f2e4cdb558ed0609dc"
2530+
integrity sha512-xFBLc/esUbLOJLk9jKv0E9gD/OH966M40aY9jJ8GiqpSkP2xOV908cokJqqhVd85WoIvHVHYXxSFE4cCSDzVvA==
2531+
dependencies:
2532+
"@types/json-schema" "^7.0.9"
2533+
"@typescript-eslint/scope-manager" "5.30.6"
2534+
"@typescript-eslint/types" "5.30.6"
2535+
"@typescript-eslint/typescript-estree" "5.30.6"
2536+
eslint-scope "^5.1.1"
2537+
eslint-utils "^3.0.0"
2538+
25012539
"@typescript-eslint/[email protected]":
25022540
version "4.33.0"
25032541
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.33.0.tgz#2a22f77a41604289b7a186586e9ec48ca92ef1dd"
@@ -2506,6 +2544,14 @@
25062544
"@typescript-eslint/types" "4.33.0"
25072545
eslint-visitor-keys "^2.0.0"
25082546

2547+
"@typescript-eslint/[email protected]":
2548+
version "5.30.6"
2549+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.30.6.tgz#94dd10bb481c8083378d24de1742a14b38a2678c"
2550+
integrity sha512-41OiCjdL2mCaSDi2SvYbzFLlqqlm5v1ZW9Ym55wXKL/Rx6OOB1IbuFGo71Fj6Xy90gJDFTlgOS+vbmtGHPTQQA==
2551+
dependencies:
2552+
"@typescript-eslint/types" "5.30.6"
2553+
eslint-visitor-keys "^3.3.0"
2554+
25092555
"@ungap/url-search-params@^0.1.4":
25102556
version "0.1.4"
25112557
resolved "https://registry.yarnpkg.com/@ungap/url-search-params/-/url-search-params-0.1.4.tgz#727e9b4c811beaa6be6d7e4cc0516663c884cfd0"
@@ -3985,7 +4031,7 @@ [email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.6, debug@^2.6.8, debug@^2.6.
39854031
dependencies:
39864032
ms "2.0.0"
39874033

3988-
debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1:
4034+
debug@4, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.4:
39894035
version "4.3.4"
39904036
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
39914037
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
@@ -4405,6 +4451,13 @@ eslint-plugin-import@^2.23.4:
44054451
resolve "^1.22.0"
44064452
tsconfig-paths "^3.14.1"
44074453

4454+
eslint-plugin-jest@^26.5.3:
4455+
version "26.5.3"
4456+
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.5.3.tgz#a3ceeaf4a757878342b8b00eca92379b246e5505"
4457+
integrity sha512-sICclUqJQnR1bFRZGLN2jnSVsYOsmPYYnroGCIMVSvTS3y8XR3yjzy1EcTQmk6typ5pRgyIWzbjqxK6cZHEZuQ==
4458+
dependencies:
4459+
"@typescript-eslint/utils" "^5.10.0"
4460+
44084461
eslint-plugin-jsx-a11y@^6.4.1:
44094462
version "6.5.1"
44104463
resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.5.1.tgz#cdbf2df901040ca140b6ec14715c988889c2a6d8"
@@ -4480,6 +4533,11 @@ eslint-visitor-keys@^2.0.0:
44804533
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
44814534
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
44824535

4536+
eslint-visitor-keys@^3.3.0:
4537+
version "3.3.0"
4538+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
4539+
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
4540+
44834541
eslint@^7.30.0:
44844542
version "7.32.0"
44854543
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d"
@@ -5172,7 +5230,7 @@ [email protected]:
51725230
merge2 "^1.2.3"
51735231
slash "^3.0.0"
51745232

5175-
globby@^11.0.0, globby@^11.0.3:
5233+
globby@^11.0.0, globby@^11.0.3, globby@^11.1.0:
51765234
version "11.1.0"
51775235
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
51785236
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
@@ -8770,7 +8828,7 @@ [email protected]:
87708828
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
87718829
integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==
87728830

8773-
[email protected], semver@^7.2.1, semver@^7.3.2, semver@^7.3.5:
8831+
[email protected], semver@^7.2.1, semver@^7.3.2, semver@^7.3.5, semver@^7.3.7:
87748832
version "7.3.7"
87758833
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
87768834
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==

0 commit comments

Comments
 (0)