Skip to content

Commit b3e6e19

Browse files
janechuCopilot
andcommitted
refactor: auto-discover fixtures and rename webui script
- Both build-fixtures.js and build-fixtures-with-webui.mjs now auto-discover fixture directories by scanning for entry.html, templates.html, and state.json instead of using a hardcoded array. - Renamed webui-integration-test.mjs to build-fixtures-with-webui.mjs for consistency with build-fixtures.js. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6658f25 commit b3e6e19

4 files changed

Lines changed: 40 additions & 44 deletions

File tree

packages/fast-html/DESIGN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ For fixtures that use SSR-style pre-rendered HTML, `scripts/build-fixtures.js` i
433433

434434
### WebUI Integration Tests
435435

436-
A separate integration test suite (`scripts/webui-integration-test.mjs`) validates that `@microsoft/webui` can build and render the same fixture templates that `@microsoft/fast-build` processes. For each fixture, the script:
436+
A separate integration test suite (`scripts/build-fixtures-with-webui.mjs`) validates that `@microsoft/webui` can build and render the same fixture templates that `@microsoft/fast-build` processes. For each fixture, the script:
437437

438438
1. Extracts `<f-template>` elements from `templates.html` into individual component HTML files (webui uses filename-based component discovery).
439439
2. Builds the fixture using `webui build --plugin=fast`.

packages/fast-html/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"test-server": "npx vite test/ --clearScreen false",
3737
"test:playwright": "playwright test",
3838
"test:rules": "sg test --skip-snapshot-tests",
39-
"test:webui-integration": "node scripts/webui-integration-test.mjs",
39+
"test:webui-integration": "node scripts/build-fixtures-with-webui.mjs",
4040
"test": "npm run test:playwright && npm run test:rules",
4141
"test:ui": "concurrently -k -n fast-element,fast-html,playwright \"npm run dev --workspace=@microsoft/fast-element\" \"npm:watch\" \"npx playwright test --ui\"",
4242
"watch": "npm run build:tsc -- -w --preserveWatchOutput"

packages/fast-html/scripts/webui-integration-test.mjs renamed to packages/fast-html/scripts/build-fixtures-with-webui.mjs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313
* 4. Validates the rendered HTML for expected structure and content.
1414
*/
1515

16-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
16+
import {
17+
existsSync,
18+
mkdirSync,
19+
readdirSync,
20+
readFileSync,
21+
rmSync,
22+
writeFileSync,
23+
} from "node:fs";
1724
import { dirname, join, resolve } from "node:path";
1825
import { fileURLToPath } from "node:url";
1926
import { build, render } from "@microsoft/webui";
@@ -22,25 +29,19 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
2229

2330
const fixturesDir = resolve(__dirname, "../test/fixtures");
2431

25-
// Fixtures to test — mirrors the list in build-fixtures.js
26-
const fixtures = [
27-
"attribute",
28-
"binding",
29-
"deep-merge",
30-
"event",
31-
"ref",
32-
"slotted",
33-
"when",
34-
"repeat",
35-
"repeat-event",
36-
"children",
37-
"host-bindings",
38-
"lifecycle-callbacks",
39-
"dot-syntax",
40-
"nested-elements",
41-
"performance-metrics",
42-
"observer-map",
43-
];
32+
// Auto-discover fixture directories that contain the required files.
33+
const fixtures = readdirSync(fixturesDir, { withFileTypes: true })
34+
.filter(entry => {
35+
if (!entry.isDirectory()) return false;
36+
const dir = join(fixturesDir, entry.name);
37+
return (
38+
existsSync(join(dir, "entry.html")) &&
39+
existsSync(join(dir, "templates.html")) &&
40+
existsSync(join(dir, "state.json"))
41+
);
42+
})
43+
.map(entry => entry.name)
44+
.sort();
4445

4546
/**
4647
* Extract <f-template name="X"> elements from an HTML string.

packages/fast-html/scripts/build-fixtures.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
#!/usr/bin/env node
22
import { execFileSync } from "node:child_process";
3-
import { readFileSync, writeFileSync } from "node:fs";
3+
import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
44
import { createRequire } from "node:module";
55
import { dirname, join, resolve } from "node:path";
66
import { fileURLToPath } from "node:url";
77

8-
// Builds test fixtures using @microsoft/fast-build. Add fixture names here
9-
// incrementally as each one is verified to work with the fast-build CLI.
10-
const fixtures = [
11-
"attribute",
12-
"binding",
13-
"deep-merge",
14-
"event",
15-
"ref",
16-
"slotted",
17-
"when",
18-
"repeat",
19-
"repeat-event",
20-
"children",
21-
"host-bindings",
22-
"lifecycle-callbacks",
23-
"dot-syntax",
24-
"nested-elements",
25-
"performance-metrics",
26-
"observer-map",
27-
];
28-
298
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
const fixturesDir = resolve(__dirname, "../test/fixtures");
10+
11+
// Auto-discover fixture directories that contain the required files.
12+
const fixtures = readdirSync(fixturesDir, { withFileTypes: true })
13+
.filter(entry => {
14+
if (!entry.isDirectory()) return false;
15+
const dir = join(fixturesDir, entry.name);
16+
return (
17+
existsSync(join(dir, "entry.html")) &&
18+
existsSync(join(dir, "templates.html")) &&
19+
existsSync(join(dir, "state.json"))
20+
);
21+
})
22+
.map(entry => entry.name)
23+
.sort();
24+
3025
const require = createRequire(import.meta.url);
3126
const fastBin = require.resolve("@microsoft/fast-build/bin/fast.js");
3227

0 commit comments

Comments
 (0)