@vnejs/configs.vitest 0.1.1
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.
- package/create-config.js +88 -0
- package/package.json +26 -0
- package/setup.js +8 -0
package/create-config.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { defineConfig } from "vitest/config";
|
|
6
|
+
|
|
7
|
+
const defaultSetupFile = fileURLToPath(new URL("./setup.js", import.meta.url));
|
|
8
|
+
const monorepoRoot = fileURLToPath(new URL("../..", import.meta.url));
|
|
9
|
+
|
|
10
|
+
const packagePathToDir = (name) => {
|
|
11
|
+
const withoutScope = name.replace("@vnejs/", "");
|
|
12
|
+
|
|
13
|
+
if (withoutScope.startsWith("plugins.")) return `plugins/${withoutScope.slice("plugins.".length).replace(/\./g, "/")}`;
|
|
14
|
+
if (withoutScope.startsWith("contracts.")) return `contracts/${withoutScope.slice("contracts.".length).replace(/\./g, "/")}`;
|
|
15
|
+
if (withoutScope === "module") return "modules_extensions/base";
|
|
16
|
+
if (withoutScope.startsWith("module.")) return `modules_extensions/${withoutScope.slice("module.".length)}`;
|
|
17
|
+
if (withoutScope.startsWith("configs.")) return `configs/${withoutScope.slice("configs.".length)}`;
|
|
18
|
+
if (withoutScope === "helpers") return "helpers/base";
|
|
19
|
+
|
|
20
|
+
if (withoutScope.startsWith("helpers.")) {
|
|
21
|
+
const helperName = withoutScope.slice("helpers.".length);
|
|
22
|
+
|
|
23
|
+
for (const category of ["composites", "primitives"]) {
|
|
24
|
+
if (existsSync(join(monorepoRoot, "helpers", category, helperName, "src/index.ts"))) {
|
|
25
|
+
return `helpers/${category}/${helperName}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (withoutScope === "test-utils") return "packages/test-utils";
|
|
30
|
+
|
|
31
|
+
return `packages/${withoutScope}`;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const resolveWorkspaceSource = (source) => {
|
|
35
|
+
if (!source.startsWith("@vnejs/")) return null;
|
|
36
|
+
|
|
37
|
+
const rest = source.slice("@vnejs/".length);
|
|
38
|
+
const slashIndex = rest.indexOf("/");
|
|
39
|
+
const packagePart = slashIndex === -1 ? rest : rest.slice(0, slashIndex);
|
|
40
|
+
const subpath = slashIndex === -1 ? "" : rest.slice(slashIndex + 1);
|
|
41
|
+
const packageDir = join(monorepoRoot, packagePathToDir(`@vnejs/${packagePart}`));
|
|
42
|
+
|
|
43
|
+
if (subpath) {
|
|
44
|
+
const subpathCandidate = join(packageDir, subpath);
|
|
45
|
+
if (existsSync(subpathCandidate)) return subpathCandidate;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const entry of ["src/index.ts", "src/index.js", "index.js", "create-config.js"]) {
|
|
49
|
+
const candidate = join(packageDir, entry);
|
|
50
|
+
if (existsSync(candidate)) return candidate;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const vnejsWorkspaceResolve = () => ({
|
|
57
|
+
name: "vnejs-workspace-resolve",
|
|
58
|
+
enforce: "pre",
|
|
59
|
+
resolveId(source) {
|
|
60
|
+
const resolved = resolveWorkspaceSource(source);
|
|
61
|
+
return resolved ?? null;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {object} [options]
|
|
67
|
+
* @param {string} [options.dirname] — package root (directory with vitest.config.js)
|
|
68
|
+
* @param {string[]} [options.include]
|
|
69
|
+
* @param {string[]} [options.setupFiles] — extra setup files after the shared one
|
|
70
|
+
*/
|
|
71
|
+
export function createVitestConfig(options = {}) {
|
|
72
|
+
const { dirname: packageRoot = process.cwd(), include = ["src/**/*.test.ts"], setupFiles = [], environment = "happy-dom" } = options;
|
|
73
|
+
|
|
74
|
+
return defineConfig({
|
|
75
|
+
plugins: [vnejsWorkspaceResolve()],
|
|
76
|
+
resolve: {
|
|
77
|
+
extensions: [".ts", ".js"],
|
|
78
|
+
},
|
|
79
|
+
test: {
|
|
80
|
+
root: packageRoot,
|
|
81
|
+
environment,
|
|
82
|
+
include,
|
|
83
|
+
setupFiles: [defaultSetupFile, ...setupFiles],
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { monorepoRoot, packagePathToDir, resolveWorkspaceSource };
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/configs.vitest",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Shared Vitest config for @vnejs packages",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"create-config.js",
|
|
8
|
+
"setup.js"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
"./create-config.js": "./create-config.js",
|
|
12
|
+
"./setup.js": "./setup.js"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"vitest": "^3.0.0 || ^4.0.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"happy-dom": "~20.0.0"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
22
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
23
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
24
|
+
},
|
|
25
|
+
"license": "ISC"
|
|
26
|
+
}
|