Skip to content

Commit fccbd09

Browse files
authored
test: setup the testing environment (#121)
* test: setup testing environment with vitest * ci: setup test on CI * fix: ignore type errors * test: add test settings for swr-devtools * fix: action name
1 parent 77e5a58 commit fccbd09

File tree

16 files changed

+1323
-29
lines changed

16 files changed

+1323
-29
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [14.x, 16.x, 18.x]
19+
node-version: [18.x]
2020
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2121

2222
steps:

.github/workflows/test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: test
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
lint:
14+
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
matrix:
19+
node-version: [14.x, 16.x, 18.x]
20+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v2
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
cache: 'yarn'
29+
- run: yarn install
30+
- run: yarn build
31+
- run: yarn test

examples/swr-devtools-demo/pages/_document.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class MyDocument extends Document {
1010
ctx.renderPage = () =>
1111
originalRenderPage({
1212
enhanceApp: (App) => (props) =>
13+
// @ts-expect-error
1314
sheet.collectStyles(<App {...props} />),
1415
});
1516

examples/swr-v1-devtools-demo/pages/_document.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class MyDocument extends Document {
1010
ctx.renderPage = () =>
1111
originalRenderPage({
1212
enhanceApp: (App) => (props) =>
13+
// @ts-expect-error
1314
sheet.collectStyles(<App {...props} />),
1415
});
1516

examples/swr-v1-legacy-devtools-demo/pages/_app.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const fetcher = async (url) => {
1313

1414
function MyApp({ Component, pageProps }) {
1515
return (
16-
// @ts-expect-error
1716
<SWRConfig value={{ fetcher }}>
1817
<SWRDevTools>
1918
<Component {...pageProps} />

examples/swr-v1-legacy-devtools-demo/pages/_document.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class MyDocument extends Document {
1010
ctx.renderPage = () =>
1111
originalRenderPage({
1212
enhanceApp: (App) => (props) =>
13+
// @ts-expect-error
1314
sheet.collectStyles(<App {...props} />),
1415
});
1516

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
"v1-legacy": "yarn workspace swr-v1-legacy-devtools-demo dev",
2424
"lint:eslint": "eslint '**/pages/**/*' '**/src/**/*'",
2525
"lint:tsc": "yarn workspaces run lint",
26-
"lint": "run-p -l lint:*"
26+
"lint": "run-p -l lint:*",
27+
"test": "run-p -l test:*",
28+
"test:panel": "yarn workspace swr-devtools-panel test",
29+
"test:devtools": "yarn workspace swr-devtools test"
2730
},
2831
"repository": "ssh://git@github.com/koba04/swr-devtools.git",
2932
"author": "Toru Kobayashi <koba0004@gmail.com>",

packages/swr-devtools-panel/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,27 @@
2828
"build": "run-p build:*",
2929
"build:esm": "tsc",
3030
"build:cjs": "tsc -p tsconfig.cjs.json",
31-
"lint": "tsc --noEmit"
31+
"lint": "tsc --noEmit",
32+
"test": "vitest run",
33+
"test:watch": "vitest"
3234
},
3335
"peerDependencies": {
3436
"react": ">=17.0.2",
3537
"styled-components": "^5.3.0",
3638
"swr": ">=1.0.0"
3739
},
3840
"devDependencies": {
41+
"@testing-library/jest-dom": "^5.16.5",
42+
"@testing-library/react": "^14.0.0",
3943
"@types/react": "^18.0.20",
4044
"@types/styled-components": "^5.1.26",
45+
"jsdom": "^21.1.1",
4146
"react": "^18.2.0",
4247
"styled-components": "^5.3.5",
4348
"swr": "^2.0.0",
44-
"typescript": "^4.8.3"
49+
"typescript": "^4.8.3",
50+
"vite": "^4.2.0",
51+
"vitest": "^0.29.3"
4552
},
4653
"dependencies": {
4754
"react-json-tree": "^0.17.0",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
import { vi, describe, it, expect } from "vitest";
3+
import { render, screen } from "@testing-library/react";
4+
import matchers from "@testing-library/jest-dom/matchers";
5+
import { SWRDevToolPanel } from "../src";
6+
import { EventEmitter } from "swr-devtools/lib/createSWRDevTools";
7+
8+
expect.extend(matchers);
9+
vi.stubGlobal("matchMedia", () => ({
10+
matches: false,
11+
}));
12+
13+
describe("SWRDevToolPanel", () => {
14+
it("should be able to render SWRDevToolPanel", () => {
15+
render(<SWRDevToolPanel cache={new Map()} events={new EventEmitter()} />);
16+
expect(screen.getByRole("heading")).toHaveTextContent("SWR");
17+
});
18+
});

packages/swr-devtools-panel/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@
6666
/* Advanced Options */
6767
"skipLibCheck": true, /* Skip type checking of declaration files. */
6868
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
69-
}
69+
},
70+
"include": ["src/"]
7071
}

0 commit comments

Comments
 (0)