Skip to content

Commit

Permalink
Migrate all tests to Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
textbook committed Oct 11, 2024
1 parent 8d2d596 commit 73f12c7
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 78 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [x] [React] client with [Vite]
- [x] Client-side routing with [React Router]
- [x] Linting with [ESLint] and [Prettier]
- [x] Unit and integration testing with [Vitest] and [Jest] (with [SuperTest] and [TestContainers])
- [x] Unit and integration testing with [Vitest] (with [SuperTest] and [TestContainers])
- [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 Down Expand Up @@ -35,7 +35,6 @@ commonly use:
[GitHub Actions]: https://github.com/features/actions
[Google App Engine]: https://cloud.google.com/appengine/?hl=en
[Heroku]: https://www.heroku.com/
[Jest]: https://jestjs.io/
[Morgan]: https://github.com/expressjs/morgan
[Node]: https://nodejs.org/en/
[node-postgres]: https://node-postgres.com/
Expand Down
9 changes: 0 additions & 9 deletions api/jest.config.js

This file was deleted.

7 changes: 2 additions & 5 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"scripts": {
"dev": "cross-env LOG_LEVEL=debug node --inspect --watch --watch-path . server.js",
"migration": "node-pg-migrate --config-file ./migrations/config.cjs",
"test": "cross-env DATABASE_URL=http://example.com NODE_OPTIONS='--experimental-vm-modules' jest",
"test:watch": "npm run test -- --watch"
"test": "cross-env DATABASE_URL=http://example.com vitest --run",
"test:watch": "npm run test -- --no-run"
},
"dependencies": {
"dotenv": "^16.4.5",
Expand All @@ -22,9 +22,6 @@
},
"devDependencies": {
"@testcontainers/postgresql": "^10.13.2",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-n": "^17.10.3",
"jest": "^29.7.0",
"supertest": "^7.0.0"
}
}
21 changes: 21 additions & 0 deletions api/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { coverageConfigDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
coverage: {
all: true,
exclude: [
"migrations/**",
"static/**",
...coverageConfigDefaults.exclude,
],
provider: "v8",
reporter: [["json", { file: "api.json" }], ["text"]],
reportsDirectory: "../.nyc_output",
},
environment: "node",
fileParallelism: false,
globals: true,
setupFiles: ["./setupTests.js"],
},
});
3 changes: 1 addition & 2 deletions bin/files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [x] [React] client with [Vite]
- [x] Client-side routing with [React Router]
- [x] Linting with [ESLint] and [Prettier]
- [x] Unit and integration testing with [Vitest] and [Jest] (with [SuperTest] and [TestContainers])
- [x] Unit and integration testing with [Vitest] (with [SuperTest] and [TestContainers])
- [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 Down Expand Up @@ -71,7 +71,6 @@ principles are followed:
[GitHub Actions]: https://github.com/features/actions
[Google App Engine]: https://cloud.google.com/appengine/?hl=en
[Heroku]: https://www.heroku.com/
[Jest]: https://jestjs.io/
[Morgan]: https://github.com/expressjs/morgan
[Node]: https://nodejs.org/en/
[node-postgres]: https://node-postgres.com/
Expand Down
26 changes: 17 additions & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import cyfConfig from "@codeyourfuture/eslint-config-standard";
import vitestPlugin from "@vitest/eslint-plugin";
import prettierConfig from "eslint-config-prettier";
import importPlugin from "eslint-plugin-import";
import jestPlugin from "eslint-plugin-jest";
import jestDomPlugin from "eslint-plugin-jest-dom";
import jsxA11yPlugin from "eslint-plugin-jsx-a11y";
import nodePlugin from "eslint-plugin-n";
Expand All @@ -29,8 +28,12 @@ export default [
},
},
{
files: ["api/**", "e2e/**", "web/vite.config.js"],
files: ["api/**", "e2e/**", "**/vite.config.js"],
...nodePlugin.configs["flat/recommended"],
rules: {
...nodePlugin.configs["flat/recommended"].rules,
"n/no-extraneous-import": "off",
},
},
{
files: ["api/**"],
Expand Down Expand Up @@ -62,13 +65,20 @@ export default [
},
},
{
files: ["api/**/*.test.js", "api/setupTests.js"],
...jestPlugin.configs["flat/recommended"],
files: ["**/*.test.js", "**/setupTests.js"],
languageOptions: {
globals: vitestPlugin.environments.env.globals,
},
plugins: {
vitest: vitestPlugin,
},
rules: {
...jestPlugin.configs["flat/recommended"].rules,
"jest/expect-expect": [
...vitestPlugin.configs.recommended.rules,
"vitest/expect-expect": [
"error",
{ assertFunctionNames: ["expect", "request.**.expect"] },
{
assertFunctionNames: ["expect", "request.**.expect"],
},
],
},
},
Expand Down Expand Up @@ -115,12 +125,10 @@ export default [
plugins: {
"jest-dom": jestDomPlugin,
"testing-library": testingLibraryPlugin,
vitest: vitestPlugin,
},
rules: {
...jestDomPlugin.configs.recommended.rules,
...testingLibraryPlugin.configs.react.rules,
...vitestPlugin.configs.recommended.rules,
},
},
{
Expand Down
Loading

0 comments on commit 73f12c7

Please sign in to comment.