File tree 16 files changed +981
-850
lines changed
16 files changed +981
-850
lines changed Original file line number Diff line number Diff line change 40
40
41
41
- name : " Test"
42
42
run : |
43
- npm run test:ws
43
+ npm run test
44
44
45
45
check-licenses :
46
46
uses : lightbasenl/platforms/.github/workflows/lib-license-checker.yml@main
Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ npm run build:ws
35
35
npm run lint:ws
36
36
37
37
# 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
39
40
40
41
# Clean ESLint cache & dist directories in the workspace.
41
42
npm run clean:ws
Original file line number Diff line number Diff line change
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"
Original file line number Diff line number Diff line change
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/
Original file line number Diff line number Diff line change 8
8
"lint:ws" : " npm run lint --workspaces --if-present --include-workspace-root" ,
9
9
"lint:ci:ws" : " npm run lint:ci --workspaces --if-present --include-workspace-root" ,
10
10
"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" ,
12
12
"build" : " tsc --build" ,
13
13
"lint" : " eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color" ,
14
+ "test" : " vitest" ,
14
15
"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"
17
17
},
18
18
"devDependencies" : {
19
19
"@types/node" : " 20.14.9" ,
20
20
"@lightbase/eslint-config" : " *" ,
21
21
"@total-typescript/tsconfig" : " 1.0.4" ,
22
+ "@vitest/coverage-v8" : " 2.0.0-beta.12" ,
22
23
"patch-package" : " 8.0.0" ,
23
- "typescript" : " 5.5.2"
24
+ "typescript" : " 5.5.2" ,
25
+ "vitest" : " 2.0.0-beta.12"
24
26
},
25
27
"workspaces" : [" packages/*" , " apps/*" ]
26
28
}
Original file line number Diff line number Diff line change 24
24
"build" : " tsc -p ./tsconfig.json" ,
25
25
"lint" : " eslint . --fix --cache --cache-strategy content --cache-location .cache/eslint/ --color" ,
26
26
"lint:ci" : " eslint ." ,
27
- "pretest" : " npm run build" ,
28
- "test" : " node --test" ,
27
+ "test" : " vitest" ,
29
28
"clean" : " rm -rf ./.cache ./dist"
30
29
},
31
30
"dependencies" : {
Original file line number Diff line number Diff line change @@ -25,10 +25,11 @@ interface LightbaseEslintConfigOptions {
25
25
* Entrypoint for your everything included ESLint config.
26
26
*/
27
27
export async function defineConfig (
28
- opts : LightbaseEslintConfigOptions ,
28
+ opts ? : LightbaseEslintConfigOptions ,
29
29
...userConfigs : Array < FlatConfig . Config >
30
30
) : Promise < Array < FlatConfig . Config > > {
31
31
globUseFromUserConfig ( ...userConfigs ) ;
32
+ opts ??= { } ;
32
33
opts . typescript = typescriptResolveConfig ( opts . typescript ) ;
33
34
34
35
// Only load React + related plugins if necessary. This adds quite the startup penalty otherwise.
Original file line number Diff line number Diff line change
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
+ } ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments