vitest-config-silverwind 4.0.0 → 5.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 (2) hide show
  1. package/index.js +17 -10
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import {join, dirname, basename} from "node:path";
1
+ import {join, dirname, basename, relative, sep} from "node:path";
2
+ import {fileURLToPath} from "node:url";
2
3
 
3
- const test = {
4
+ const test = ({url} = {}) => ({
4
5
  include: ["**/?(*.)test.?(c|m)[jt]s?(x)"],
5
6
  testTimeout: 30000,
6
7
  pool: "forks", // https://github.com/vitest-dev/vitest/issues/2008
@@ -11,16 +12,22 @@ const test = {
11
12
  globals: true,
12
13
  watch: false,
13
14
  resolveSnapshotPath: (path, extension) => {
14
- return join(dirname(path), "snapshots", `${basename(path)}${extension}`);
15
+ if (url) { // single snapshot dir in root
16
+ const root = dirname(fileURLToPath(new URL(url)));
17
+ const file = `${relative(root, path).replaceAll(sep, ".")}${extension}`;
18
+ return join(root, "snapshots", file);
19
+ } else { // subfolder besides the file
20
+ return join(dirname(path), "snapshots", `${basename(path)}${extension}`);
21
+ }
15
22
  },
16
- };
23
+ });
17
24
 
18
- export const frontendTest = {
25
+ export const frontendTest = (...opts) => ({
19
26
  environment: "jsdom",
20
- ...test,
21
- };
27
+ ...test(...opts),
28
+ });
22
29
 
23
- export const backendTest = {
30
+ export const backendTest = (...opts) => ({
24
31
  environment: "node",
25
- ...test,
26
- };
32
+ ...test(...opts),
33
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-config-silverwind",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Shared vitest configuration",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "repository": "silverwind/vitest-config-silverwind",
@@ -16,6 +16,6 @@
16
16
  "js-yaml": "4.1.0",
17
17
  "updates": "15.0.4",
18
18
  "versions": "12.0.0",
19
- "vitest": "1.0.1"
19
+ "vitest": "1.0.4"
20
20
  }
21
21
  }