@mica-js/testing 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +190 -2
- package/dist/cli.d.ts +22 -0
- package/dist/cli.js +156 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.js +87 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +69 -0
- package/dist/node.js +33 -0
- package/dist/node.js.map +1 -0
- package/dist/prepare-DcWr62th.js +215 -0
- package/dist/prepare-DcWr62th.js.map +1 -0
- package/dist/testbench-fpI2T0c6.js +187 -0
- package/dist/testbench-fpI2T0c6.js.map +1 -0
- package/dist/vite.d.ts +10 -0
- package/dist/vite.js +120 -0
- package/dist/vite.js.map +1 -0
- package/package.json +62 -3
package/dist/vite.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { loadProjectConfig } from "./config.js";
|
|
2
|
+
import { t as prepareTestbenches } from "./prepare-DcWr62th.js";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { createFilter, normalizePath } from "vite";
|
|
5
|
+
import { configDefaults } from "vitest/config";
|
|
6
|
+
//#region src/vite.ts
|
|
7
|
+
function mitest(options = {}) {
|
|
8
|
+
let root;
|
|
9
|
+
let server;
|
|
10
|
+
let pending = Promise.resolve();
|
|
11
|
+
let documents = /* @__PURE__ */ new Map();
|
|
12
|
+
let dependencies = /* @__PURE__ */ new Map();
|
|
13
|
+
let inputs = /* @__PURE__ */ new Set();
|
|
14
|
+
let isTest = () => false;
|
|
15
|
+
const pathKey = (file) => normalizePath(resolve(file));
|
|
16
|
+
const refresh = () => {
|
|
17
|
+
const task = pending.then(async () => {
|
|
18
|
+
const next = await loadProjectConfig({
|
|
19
|
+
root,
|
|
20
|
+
...options.config === void 0 ? {} : { config: options.config }
|
|
21
|
+
});
|
|
22
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
23
|
+
const watched = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const [name, entry] of Object.entries(next.config.testbenches)) {
|
|
25
|
+
const file = pathKey(resolve(next.root, entry.document));
|
|
26
|
+
if (bindings.has(file)) throw new Error(`Multiple testbenches configure ${file}; .sch imports require one configuration per document`);
|
|
27
|
+
bindings.set(file, normalizePath(resolve(next.root, ".mitest", "testbenches", `${name}.ts`)));
|
|
28
|
+
watched.set(file, /* @__PURE__ */ new Set([
|
|
29
|
+
pathKey(next.configFile),
|
|
30
|
+
file,
|
|
31
|
+
...Object.values(entry.devices).flatMap((directory) => [pathKey(resolve(next.root, directory, "release.json")), pathKey(resolve(next.root, directory, "package.json"))])
|
|
32
|
+
]));
|
|
33
|
+
}
|
|
34
|
+
await prepareTestbenches(next);
|
|
35
|
+
documents = bindings;
|
|
36
|
+
dependencies = watched;
|
|
37
|
+
inputs = /* @__PURE__ */ new Set([pathKey(next.configFile), ...[...watched.values()].flatMap((files) => [...files])]);
|
|
38
|
+
server?.watcher.add([...inputs]);
|
|
39
|
+
});
|
|
40
|
+
pending = task.then(() => void 0, () => void 0);
|
|
41
|
+
return task;
|
|
42
|
+
};
|
|
43
|
+
const invalidate = () => {
|
|
44
|
+
if (server === void 0) return;
|
|
45
|
+
for (const environment of Object.values(server.environments)) for (const file of documents.keys()) {
|
|
46
|
+
const modules = new Set(environment.moduleGraph.getModulesByFile(file));
|
|
47
|
+
const direct = environment.moduleGraph.getModuleById(file);
|
|
48
|
+
if (direct !== void 0) modules.add(direct);
|
|
49
|
+
for (const module of modules) environment.moduleGraph.invalidateModule(module);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
name: "mitest",
|
|
54
|
+
enforce: "pre",
|
|
55
|
+
config() {
|
|
56
|
+
return { test: { watchTriggerPatterns: [{
|
|
57
|
+
pattern: /./,
|
|
58
|
+
testsToRun(file) {
|
|
59
|
+
if (!inputs.has(pathKey(file)) || server === void 0) return [];
|
|
60
|
+
const tests = /* @__PURE__ */ new Set();
|
|
61
|
+
for (const environment of Object.values(server.environments)) {
|
|
62
|
+
const visited = /* @__PURE__ */ new Set();
|
|
63
|
+
const visit = (id) => {
|
|
64
|
+
if (visited.has(id)) return;
|
|
65
|
+
visited.add(id);
|
|
66
|
+
const module = environment.moduleGraph.getModuleById(id);
|
|
67
|
+
if (module === void 0) return;
|
|
68
|
+
if (module.file !== null && isTest(module.file)) tests.add(module.file);
|
|
69
|
+
for (const importer of module.importers) if (importer.id !== null) visit(importer.id);
|
|
70
|
+
};
|
|
71
|
+
for (const [document, files] of dependencies) if (files.has(pathKey(file))) visit(document);
|
|
72
|
+
}
|
|
73
|
+
return [...tests];
|
|
74
|
+
}
|
|
75
|
+
}] } };
|
|
76
|
+
},
|
|
77
|
+
configResolved(config) {
|
|
78
|
+
root = resolve(config.root, options.root ?? ".");
|
|
79
|
+
isTest = createFilter(config.test?.include ?? configDefaults.include, config.test?.exclude ?? configDefaults.exclude, { resolve: config.root });
|
|
80
|
+
},
|
|
81
|
+
configureServer(next) {
|
|
82
|
+
server = next;
|
|
83
|
+
const changed = (file) => {
|
|
84
|
+
if (!inputs.has(pathKey(file))) return;
|
|
85
|
+
invalidate();
|
|
86
|
+
refresh().catch((error) => {
|
|
87
|
+
next.config.logger.error(`mitest: ${error instanceof Error ? error.message : String(error)}`);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
next.watcher.on("change", changed);
|
|
91
|
+
next.watcher.on("add", changed);
|
|
92
|
+
next.watcher.on("unlink", changed);
|
|
93
|
+
next.httpServer?.once("close", () => {
|
|
94
|
+
next.watcher.off("change", changed);
|
|
95
|
+
next.watcher.off("add", changed);
|
|
96
|
+
next.watcher.off("unlink", changed);
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
async buildStart() {
|
|
100
|
+
await refresh();
|
|
101
|
+
for (const file of inputs) this.addWatchFile(file);
|
|
102
|
+
},
|
|
103
|
+
async load(id) {
|
|
104
|
+
if (!id.endsWith(".sch")) return;
|
|
105
|
+
await refresh();
|
|
106
|
+
const file = pathKey(id);
|
|
107
|
+
const target = documents.get(file);
|
|
108
|
+
if (target === void 0) throw new Error(`Schematic ${file} is not configured in mitest.config.ts`);
|
|
109
|
+
for (const dependency of dependencies.get(file) ?? []) this.addWatchFile(dependency);
|
|
110
|
+
return `export { createTestbench as default } from ${JSON.stringify(target)};`;
|
|
111
|
+
},
|
|
112
|
+
async closeBundle() {
|
|
113
|
+
await pending;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
export { mitest };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { normalizePath, createFilter, type Plugin, type ViteDevServer } from 'vite';\nimport { configDefaults, type ViteUserConfig as UserConfig } from 'vitest/config';\nimport { loadProjectConfig } from './config';\nimport { prepareTestbenches } from './prepare';\n\nexport interface MitestPluginOptions {\n readonly root?: string;\n readonly config?: string;\n}\n\nexport function mitest(options: MitestPluginOptions = {}): Plugin {\n let root: string;\n let server: ViteDevServer | undefined;\n let pending: Promise<void> = Promise.resolve();\n let documents = new Map<string, string>();\n let dependencies = new Map<string, Set<string>>();\n let inputs = new Set<string>();\n let isTest: (file: string) => boolean = () => false;\n const pathKey = (file: string): string => normalizePath(resolve(file));\n\n const refresh = (): Promise<void> => {\n const task = pending.then(async () => {\n const next = await loadProjectConfig({\n root,\n ...(options.config === undefined ? {} : { config: options.config }),\n });\n const bindings = new Map<string, string>();\n const watched = new Map<string, Set<string>>();\n for (const [name, entry] of Object.entries(next.config.testbenches)) {\n const file = pathKey(resolve(next.root, entry.document));\n if (bindings.has(file))\n throw new Error(\n `Multiple testbenches configure ${file}; .sch imports require one configuration per document`,\n );\n bindings.set(\n file,\n normalizePath(resolve(next.root, '.mitest', 'testbenches', `${name}.ts`)),\n );\n watched.set(\n file,\n new Set([\n pathKey(next.configFile),\n file,\n ...Object.values(entry.devices).flatMap((directory) => [\n pathKey(resolve(next.root, directory, 'release.json')),\n pathKey(resolve(next.root, directory, 'package.json')),\n ]),\n ]),\n );\n }\n await prepareTestbenches(next);\n documents = bindings;\n dependencies = watched;\n inputs = new Set([\n pathKey(next.configFile),\n ...[...watched.values()].flatMap((files) => [...files]),\n ]);\n server?.watcher.add([...inputs]);\n });\n // The caller receives failures; keep later watch refreshes able to recover.\n pending = task.then(\n () => undefined,\n () => undefined,\n );\n return task;\n };\n\n const invalidate = (): void => {\n if (server === undefined) return;\n for (const environment of Object.values(server.environments)) {\n for (const file of documents.keys()) {\n const modules = new Set(environment.moduleGraph.getModulesByFile(file));\n const direct = environment.moduleGraph.getModuleById(file);\n if (direct !== undefined) modules.add(direct);\n for (const module of modules) environment.moduleGraph.invalidateModule(module);\n }\n }\n };\n\n return {\n name: 'mitest',\n enforce: 'pre',\n config(): UserConfig {\n return {\n test: {\n watchTriggerPatterns: [\n {\n pattern: /./,\n testsToRun(file) {\n if (!inputs.has(pathKey(file)) || server === undefined) return [];\n const tests = new Set<string>();\n for (const environment of Object.values(server.environments)) {\n const visited = new Set<string>();\n const visit = (id: string): void => {\n if (visited.has(id)) return;\n visited.add(id);\n const module = environment.moduleGraph.getModuleById(id);\n if (module === undefined) return;\n if (module.file !== null && isTest(module.file)) tests.add(module.file);\n for (const importer of module.importers)\n if (importer.id !== null) visit(importer.id);\n };\n for (const [document, files] of dependencies)\n if (files.has(pathKey(file))) visit(document);\n }\n return [...tests];\n },\n },\n ],\n },\n };\n },\n configResolved(config) {\n root = resolve(config.root, options.root ?? '.');\n isTest = createFilter(\n config.test?.include ?? configDefaults.include,\n config.test?.exclude ?? configDefaults.exclude,\n { resolve: config.root },\n );\n },\n configureServer(next) {\n server = next;\n const changed = (file: string): void => {\n if (!inputs.has(pathKey(file))) return;\n invalidate();\n void refresh().catch((error: unknown) => {\n next.config.logger.error(\n `mitest: ${error instanceof Error ? error.message : String(error)}`,\n );\n });\n };\n next.watcher.on('change', changed);\n next.watcher.on('add', changed);\n next.watcher.on('unlink', changed);\n next.httpServer?.once('close', () => {\n next.watcher.off('change', changed);\n next.watcher.off('add', changed);\n next.watcher.off('unlink', changed);\n });\n },\n async buildStart() {\n await refresh();\n for (const file of inputs) this.addWatchFile(file);\n },\n async load(id) {\n if (!id.endsWith('.sch')) return;\n await refresh();\n const file = pathKey(id);\n const target = documents.get(file);\n if (target === undefined)\n throw new Error(`Schematic ${file} is not configured in mitest.config.ts`);\n for (const dependency of dependencies.get(file) ?? []) this.addWatchFile(dependency);\n return `export { createTestbench as default } from ${JSON.stringify(target)};`;\n },\n async closeBundle() {\n await pending;\n },\n };\n}\n"],"mappings":";;;;;;AAWA,SAAgB,OAAO,UAA+B,CAAC,GAAW;CAChE,IAAI;CACJ,IAAI;CACJ,IAAI,UAAyB,QAAQ,QAAQ;CAC7C,IAAI,4BAAY,IAAI,IAAoB;CACxC,IAAI,+BAAe,IAAI,IAAyB;CAChD,IAAI,yBAAS,IAAI,IAAY;CAC7B,IAAI,eAA0C;CAC9C,MAAM,WAAW,SAAyB,cAAc,QAAQ,IAAI,CAAC;CAErE,MAAM,gBAA+B;EACnC,MAAM,OAAO,QAAQ,KAAK,YAAY;GACpC,MAAM,OAAO,MAAM,kBAAkB;IACnC;IACA,GAAI,QAAQ,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;GACnE,CAAC;GACD,MAAM,2BAAW,IAAI,IAAoB;GACzC,MAAM,0BAAU,IAAI,IAAyB;GAC7C,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,OAAO,WAAW,GAAG;IACnE,MAAM,OAAO,QAAQ,QAAQ,KAAK,MAAM,MAAM,QAAQ,CAAC;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UAAU,OAAO;GACjC,KAAK,YAAY,KAAK,eAAe;IACnC,KAAK,QAAQ,IAAI,UAAU,OAAO;IAClC,KAAK,QAAQ,IAAI,OAAO,OAAO;IAC/B,KAAK,QAAQ,IAAI,UAAU,OAAO;GACpC,CAAC;EACH;EACA,MAAM,aAAa;GACjB,MAAM,QAAQ;GACd,KAAK,MAAM,QAAQ,QAAQ,KAAK,aAAa,IAAI;EACnD;EACA,MAAM,KAAK,IAAI;GACb,IAAI,CAAC,GAAG,SAAS,MAAM,GAAG;GAC1B,MAAM,QAAQ;GACd,MAAM,OAAO,QAAQ,EAAE;GACvB,MAAM,SAAS,UAAU,IAAI,IAAI;GACjC,IAAI,WAAW,KAAA,GACb,MAAM,IAAI,MAAM,aAAa,KAAK,uCAAuC;GAC3E,KAAK,MAAM,cAAc,aAAa,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,aAAa,UAAU;GACnF,OAAO,8CAA8C,KAAK,UAAU,MAAM,EAAE;EAC9E;EACA,MAAM,cAAc;GAClB,MAAM;EACR;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mica-js/testing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Runner-independent testbenches for Mica device simulation",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/x-botlab/mica-js.git",
|
|
9
|
+
"directory": "packages/testing"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"bin": {
|
|
14
|
+
"mitest": "./dist/cli.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./node": {
|
|
22
|
+
"types": "./dist/node.d.ts",
|
|
23
|
+
"import": "./dist/node.js"
|
|
24
|
+
},
|
|
25
|
+
"./vite": {
|
|
26
|
+
"types": "./dist/vite.d.ts",
|
|
27
|
+
"import": "./dist/vite.js"
|
|
28
|
+
},
|
|
29
|
+
"./config": {
|
|
30
|
+
"types": "./dist/config.d.ts",
|
|
31
|
+
"import": "./dist/config.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@mica-js/core": "0.7.0",
|
|
42
|
+
"@mica-js/document": "0.3.0",
|
|
43
|
+
"@mica-js/sdk": "0.4.0",
|
|
44
|
+
"vite": "^8.3.4"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"vitest": "^5.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"vitest": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/node": "^24.19.2",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"vite-plugin-dts": "^5.1.2",
|
|
58
|
+
"vitest": "^5.0.5"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "vite build",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"test": "vitest run"
|
|
64
|
+
}
|
|
6
65
|
}
|