@design-embed/target-vanjs 1.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.
- package/LICENSE +9 -0
- package/README.md +18 -0
- package/dist/design-embed/src/core/diagnostics/diagnostic.d.mts +16 -0
- package/dist/design-embed/src/core/nodes.d.mts +63 -0
- package/dist/design-embed/src/core/plugins/pluginApi.d.mts +41 -0
- package/dist/design-embed/src/core/types.d.mts +98 -0
- package/dist/index.d.mts +20 -0
- package/dist/index.mjs +926 -0
- package/dist/index.test.d.mts +1 -0
- package/dist/index.test.mjs +84 -0
- package/package.json +32 -0
- package/src/index.ts +1565 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { VanJsTarget, emitVanJsView, vanJsTestGenerator } from "./index.mjs";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { describe, test } from "node:test";
|
|
4
|
+
//#region packages/target-vanjs/src/index.test.ts
|
|
5
|
+
describe("VanJS target", () => {
|
|
6
|
+
test("emits a VanJS view from design nodes", () => {
|
|
7
|
+
assert.equal(emitVanJsView([{
|
|
8
|
+
kind: "element",
|
|
9
|
+
tagName: "section",
|
|
10
|
+
attributes: { "data-testid": "hero" },
|
|
11
|
+
styles: { width: "120px" },
|
|
12
|
+
children: [{
|
|
13
|
+
kind: "text",
|
|
14
|
+
text: "Hello"
|
|
15
|
+
}]
|
|
16
|
+
}], "HeroView"), `import van from "vanjs-core";
|
|
17
|
+
|
|
18
|
+
const { section } = van.tags;
|
|
19
|
+
|
|
20
|
+
export function HeroView() {
|
|
21
|
+
return (
|
|
22
|
+
section({ "data-testid": "hero", style: "width: 120px;" },
|
|
23
|
+
"Hello",
|
|
24
|
+
)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
test("emits deterministic VanJS visual regression tests", () => {
|
|
30
|
+
const result = vanJsTestGenerator.generateTests({
|
|
31
|
+
html: "<section style=\"width: 120px\">Hello</section>",
|
|
32
|
+
config: {
|
|
33
|
+
output: {
|
|
34
|
+
target: new VanJsTarget(),
|
|
35
|
+
viewName: "GeneratedCard",
|
|
36
|
+
viewsDir: "src/generated/views"
|
|
37
|
+
},
|
|
38
|
+
tests: {
|
|
39
|
+
outputDir: "tests/generated",
|
|
40
|
+
viewports: [{
|
|
41
|
+
name: "mobile",
|
|
42
|
+
width: 390,
|
|
43
|
+
height: 844
|
|
44
|
+
}],
|
|
45
|
+
states: [{
|
|
46
|
+
name: "hovered",
|
|
47
|
+
hover: "section"
|
|
48
|
+
}],
|
|
49
|
+
assertions: {
|
|
50
|
+
screenshot: true,
|
|
51
|
+
layout: true,
|
|
52
|
+
layoutTolerance: 1,
|
|
53
|
+
selectors: ["section"]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
assert.deepEqual(result.diagnostics, []);
|
|
59
|
+
assert.deepEqual(result.files.map((file) => file.path), [
|
|
60
|
+
"tests/generated/GeneratedCard.reference.html",
|
|
61
|
+
"tests/generated/GeneratedCard.visual.spec.ts",
|
|
62
|
+
"src/generated/views/GeneratedCard.mount.entry.ts"
|
|
63
|
+
]);
|
|
64
|
+
assert.equal(result.files[0]?.contents, "<section style=\"width: 120px\">Hello</section>\n");
|
|
65
|
+
assert.match(result.files[1]?.contents ?? "", /await page\.goto\("file:\/\/" \+ mountHtmlPath\);/);
|
|
66
|
+
assert.match(result.files[1]?.contents ?? "", /const layoutTolerance = 1;/);
|
|
67
|
+
assert.match(result.files[1]?.contents ?? "", /await page\.hover\(state\.hover\);/);
|
|
68
|
+
assert.equal(result.files[2]?.contents, "import van from \"vanjs-core\";\nimport { GeneratedCard } from \"./GeneratedCard.view\";\nvan.add(document.body, GeneratedCard());\n");
|
|
69
|
+
});
|
|
70
|
+
test("reports unsupported VanJS test runners", () => {
|
|
71
|
+
const result = vanJsTestGenerator.generateTests({
|
|
72
|
+
html: "<main></main>",
|
|
73
|
+
config: { tests: { runner: "vitest" } }
|
|
74
|
+
});
|
|
75
|
+
assert.deepEqual(result.files, []);
|
|
76
|
+
assert.deepEqual(result.diagnostics, [{
|
|
77
|
+
code: "TEST_RUNNER_UNSUPPORTED",
|
|
78
|
+
message: "Unsupported test runner: vitest",
|
|
79
|
+
severity: "error"
|
|
80
|
+
}]);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
//#endregion
|
|
84
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@design-embed/target-vanjs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public",
|
|
8
|
+
"provenance": true
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./src/index.ts",
|
|
13
|
+
"development": "./src/index.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src",
|
|
20
|
+
"!src/**/*.test.ts",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"design-embed": "*"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"design-embed": "0.2.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "node --conditions=development --test src/**/*.test.ts"
|
|
31
|
+
}
|
|
32
|
+
}
|