vitest-config-silverwind 7.0.2 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/index.js +49 -34
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -2,4 +2,11 @@
2
2
 
3
3
  Shared Vitest configuration
4
4
 
5
+ ```js
6
+ import {defineConfig} from "vitest/dist/config.js";
7
+ import {backend} from "vitest-config-silverwind";
8
+
9
+ export default defineConfig(backend({url: import.meta.url}));
10
+ ```
11
+
5
12
  © [silverwind](https://github.com/silverwind), distributed under BSD licence.
package/index.js CHANGED
@@ -1,43 +1,58 @@
1
1
  import {join, dirname, basename, relative, sep} from "node:path";
2
2
  import {fileURLToPath} from "node:url";
3
+ import {stringPlugin} from "vite-string-plugin";
3
4
 
4
- const base = ({url, setupFiles = []} = {}) => ({
5
- include: [
6
- "**/?(*.)test.?(c|m)[jt]s?(x)",
7
- ],
8
- exclude: [
9
- "**/{node_modules,dist,e2e,snapshots}/**",
10
- "**/.{air,git,github,gitea,swc,ruff_cache,venv,vscode}/**",
11
- ],
12
- setupFiles: [
13
- fileURLToPath(new URL("vitest.setup.js", import.meta.url)),
14
- ...setupFiles,
15
- ],
16
- testTimeout: 30000,
17
- pool: "forks", // https://github.com/vitest-dev/vitest/issues/2008
18
- cache: false, // https://github.com/vitest-dev/vitest/issues/2008
19
- open: false,
20
- allowOnly: true,
21
- passWithNoTests: true,
22
- globals: true,
23
- watch: false,
24
- resolveSnapshotPath: (path, extension) => {
25
- if (url) { // single snapshot dir in root
26
- const root = dirname(fileURLToPath(new URL(url)));
27
- const file = `${relative(root, path).replaceAll(sep, ".")}${extension}`;
28
- return join(root, "snapshots", file);
29
- } else { // subfolder besides the file
30
- return join(dirname(path), "snapshots", `${basename(path)}${extension}`);
31
- }
5
+ const base = ({url, test = {}, plugins = [], ...other} = {}) => ({
6
+ test: {
7
+ include: [
8
+ "**/?(*.)test.?(c|m)[jt]s?(x)",
9
+ ],
10
+ exclude: [
11
+ "**/{node_modules,dist,e2e,snapshots}/**",
12
+ "**/.{air,git,github,gitea,swc,ruff_cache,venv,vscode}/**",
13
+ ],
14
+ setupFiles: [
15
+ fileURLToPath(new URL("vitest.setup.js", import.meta.url)),
16
+ ...(test.setupFiles || []),
17
+ ],
18
+ testTimeout: 30000,
19
+ pool: "forks", // https://github.com/vitest-dev/vitest/issues/2008
20
+ cache: false, // https://github.com/vitest-dev/vitest/issues/2008
21
+ open: false,
22
+ allowOnly: true,
23
+ passWithNoTests: true,
24
+ globals: true,
25
+ watch: false,
26
+ resolveSnapshotPath: (path, extension) => {
27
+ if (url) { // single snapshot dir in root
28
+ const root = dirname(fileURLToPath(new URL(url)));
29
+ const file = `${relative(root, path).replaceAll(sep, ".")}${extension}`;
30
+ return join(root, "snapshots", file);
31
+ } else { // subfolder besides the file
32
+ return join(dirname(path), "snapshots", `${basename(path)}${extension}`);
33
+ }
34
+ },
35
+ ...test,
32
36
  },
37
+ plugins: [
38
+ stringPlugin,
39
+ ...plugins,
40
+ ],
41
+ ...other,
33
42
  });
34
43
 
35
- export const frontendTest = opts => ({
36
- environment: "happy-dom",
37
- ...base(opts),
44
+ export const frontend = ({test = {}, ...other} = {}) => base({
45
+ test: {
46
+ environment: "happy-dom",
47
+ ...test,
48
+ },
49
+ ...other,
38
50
  });
39
51
 
40
- export const backendTest = opts => ({
41
- environment: "node",
42
- ...base(opts),
52
+ export const backend = ({test = {}, ...other} = {}) => base({
53
+ test: {
54
+ environment: "node",
55
+ ...test,
56
+ },
57
+ ...other,
43
58
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-config-silverwind",
3
- "version": "7.0.2",
3
+ "version": "8.0.0",
4
4
  "description": "Shared vitest configuration",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/vitest-config-silverwind",
@@ -12,7 +12,8 @@
12
12
  "vitest.setup.js"
13
13
  ],
14
14
  "dependencies": {
15
- "jest-extended": "4.0.2"
15
+ "jest-extended": "4.0.2",
16
+ "vite-string-plugin": "1.1.5"
16
17
  },
17
18
  "devDependencies": {
18
19
  "eslint": "8.57.0",