Skip to content

Commit ce0ce78

Browse files
authored
chore: switch to Vitest for running all the tests (#125)
Signed-off-by: Dirk de Visser <[email protected]>
1 parent b19c9a9 commit ce0ce78

File tree

16 files changed

+981
-850
lines changed

16 files changed

+981
-850
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
4141
- name: "Test"
4242
run: |
43-
npm run test:ws
43+
npm run test
4444
4545
check-licenses:
4646
uses: lightbasenl/platforms/.github/workflows/lib-license-checker.yml@main

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ npm run build:ws
3535
npm run lint:ws
3636

3737
# Run the 'test' script for all packages in the workspace
38-
npm run test:ws
38+
# Note that we use Vitest in workspace mode, which includes all tests of sub-packages.
39+
npm run test
3940

4041
# Clean ESLint cache & dist directories in the workspace.
4142
npm run clean:ws

docs/decisions/000-template.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Title
2+
3+
## Context
4+
5+
What is the issue that we're seeing that is motivating this decision or change?
6+
7+
## Decision
8+
9+
What is the change that we're proposing and/or doing?
10+
11+
## Consequences
12+
13+
What becomes easier or more challenging to do because of this change?
14+
15+
---
16+
17+
[//]:
18+
#
19+
"Put references and URL's here. Using the [title][1] syntax above, with [1]: foo.com here"

docs/decisions/001-vitest.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Using Vitest
2+
3+
## Context
4+
5+
We currently test our packages with the use of the Node.js [built-in test runner][1]. This
6+
has a few downsides:
7+
8+
- We write the test files with TypeScript, so either need to use a 'loader' like `tsx` or
9+
transpile tests before running them.
10+
- The Node.js test runner just doesn't have the IDE support that we expect.
11+
12+
## Decision
13+
14+
Use [Vitest][2]. Webstorm comes with decent support. It supports on the fly transpiling of
15+
TypeScript and many more things. While staying fast, and only requiring a few lines of
16+
config.
17+
18+
Another useful feature of Vitest is the out-of-the-box support for workspaces, which means
19+
that launching tests from the root or per package works seamlessly.
20+
21+
## Consequences
22+
23+
In the future we may have the need to support JSX in certain packages and thus tests,
24+
which Vitest supports. For other scenarios, Vite(st) plugins are most likely available.
25+
26+
---
27+
28+
[1]: https://nodejs.org/api/test.html
29+
[2]: https://vitest.dev/

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
"lint:ws": "npm run lint --workspaces --if-present --include-workspace-root",
99
"lint:ci:ws": "npm run lint:ci --workspaces --if-present --include-workspace-root",
1010
"build:ws": "npm run build && npm run build --workspaces --if-present",
11-
"test:ws": "npm run test --workspaces --if-present --include-workspace-root",
11+
"clean:ws": "npm run clean --workspaces --if-present --include-workspace-root",
1212
"build": "tsc --build",
1313
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
14+
"test": "vitest",
1415
"lint:ci": "eslint .",
15-
"clean": "rm -rf ./.cache ./tsconfig.tsbuildinfo",
16-
"clean:ws": "npm run clean --workspaces --if-present --include-workspace-root"
16+
"clean": "rm -rf ./.cache ./tsconfig.tsbuildinfo"
1717
},
1818
"devDependencies": {
1919
"@types/node": "20.14.9",
2020
"@lightbase/eslint-config": "*",
2121
"@total-typescript/tsconfig": "1.0.4",
22+
"@vitest/coverage-v8": "2.0.0-beta.12",
2223
"patch-package": "8.0.0",
23-
"typescript": "5.5.2"
24+
"typescript": "5.5.2",
25+
"vitest": "2.0.0-beta.12"
2426
},
2527
"workspaces": ["packages/*", "apps/*"]
2628
}

packages/eslint-config/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"build": "tsc -p ./tsconfig.json",
2525
"lint": "eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color",
2626
"lint:ci": "eslint .",
27-
"pretest": "npm run build",
28-
"test": "node --test",
27+
"test": "vitest",
2928
"clean": "rm -rf ./.cache ./dist"
3029
},
3130
"dependencies": {

packages/eslint-config/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ interface LightbaseEslintConfigOptions {
2525
* Entrypoint for your everything included ESLint config.
2626
*/
2727
export async function defineConfig(
28-
opts: LightbaseEslintConfigOptions,
28+
opts?: LightbaseEslintConfigOptions,
2929
...userConfigs: Array<FlatConfig.Config>
3030
): Promise<Array<FlatConfig.Config>> {
3131
globUseFromUserConfig(...userConfigs);
32+
opts ??= {};
3233
opts.typescript = typescriptResolveConfig(opts.typescript);
3334

3435
// Only load React + related plugins if necessary. This adds quite the startup penalty otherwise.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from "vitest";
2+
import { defineConfig } from "../src/index.js";
3+
4+
test("returns a config if no arguments are specified", async () => {
5+
expect(await defineConfig()).toEqual(expect.arrayContaining([]));
6+
});
7+
8+
test("returns a config if TypeScript options are specified", async () => {
9+
expect(await defineConfig({ typescript: false })).toEqual(expect.arrayContaining([]));
10+
expect(await defineConfig({ typescript: true })).toEqual(expect.arrayContaining([]));
11+
expect(await defineConfig({ typescript: {} })).toEqual(expect.arrayContaining([]));
12+
});
13+
14+
test("returns a config if globals are specified", async () => {
15+
expect(await defineConfig({ globals: ["node", "es5"] })).toEqual(
16+
expect.arrayContaining([]),
17+
);
18+
});

packages/eslint-config/test/index.ts

-254
This file was deleted.

0 commit comments

Comments
 (0)