Skip to content

Commit

Permalink
Consistent API for client and server tests
Browse files Browse the repository at this point in the history
- Now using Jest as runner for the backend tests
- Enable Vitest globals to reduce the differences
  • Loading branch information
textbook committed Jan 11, 2024
1 parent c44fe63 commit 8ead843
Show file tree
Hide file tree
Showing 11 changed files with 3,811 additions and 1,001 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- [x] [React] client with [Vite]
- [ ] Client-side routing with [React Router]
- [x] Linting with [ESLint] and [Prettier]
- [x] Unit and integration testing with [Vitest] and [`node:test`][node-test] (with [SuperTest])
- [x] Unit and integration testing with [Vitest] and [Jest] (with [SuperTest])
- [x] E2E testing with [Playwright]
- [x] Dev mode (watch modes for client and server, proxy to avoid CORS issues)
- [x] Production build (single deployment artifact)
Expand All @@ -33,12 +33,14 @@ commonly use:
[Express]: https://expressjs.com/
[GitHub Actions]: https://github.com/features/actions
[Heroku]: https://www.heroku.com/
[Jest]: https://jestjs.io/
[Morgan]: https://github.com/expressjs/morgan
[Node]: https://nodejs.org/en/
[node-test]: https://nodejs.org/api/test.html
[Playwright]: https://playwright.dev/
[Prettier]: https://prettier.io/
[React]: https://reactjs.org/
[React Router]: https://reactrouter.com/en/main
[Render]: https://render.com/
[SuperTest]: https://github.com/visionmedia/supertest
[Vite]: https://vitejs.dev/
Expand Down
3 changes: 2 additions & 1 deletion client/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
],
"overrides": [
{
"files": ["src/**/*.test.jsx"],
"files": ["src/**/*.test.jsx", "src/setupTests.js"],
"env": { "vitest/env": true },
"extends": ["plugin:testing-library/react", "plugin:vitest/recommended"]
}
],
Expand Down
1 change: 0 additions & 1 deletion client/src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { http, HttpResponse } from "msw";
import { beforeEach, describe, expect, it } from "vitest";

import App from "./App.jsx";
import { server } from "./setupTests.js";
Expand Down
6 changes: 1 addition & 5 deletions client/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import "@testing-library/jest-dom/vitest";
import { cleanup } from "@testing-library/react";
import "@testing-library/jest-dom";
import { setupServer } from "msw/node";
import { setGlobalOrigin } from "undici";
import { afterAll, afterEach, beforeAll, beforeEach } from "vitest";

export const server = setupServer();

Expand All @@ -12,6 +10,4 @@ beforeAll(() => server.listen());

beforeEach(() => server.resetHandlers());

afterEach(cleanup);

afterAll(() => server.close());
1 change: 1 addition & 0 deletions client/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineConfig({
},
test: {
environment: "jsdom",
globals: true,
setupFiles: ["src/setupTests.js"],
},
});
Loading

0 comments on commit 8ead843

Please sign in to comment.