Skip to content

feat: add Playwright test harness with SSR and CSR support#7428

Open
radium-v wants to merge 1 commit intomainfrom
users/radium-v/fast-test-harness
Open

feat: add Playwright test harness with SSR and CSR support#7428
radium-v wants to merge 1 commit intomainfrom
users/radium-v/fast-test-harness

Conversation

@radium-v
Copy link
Copy Markdown
Collaborator

Pull Request

📖 Description

Adds @microsoft/fast-test-harness, a new Playwright testing harness package for FAST web components. The harness provides shared fixtures for both client-side rendering (CSR) and server-side rendering (SSR) test workflows, a custom Express + Vite dev server, SSR rendering utilities, and support for custom assertions.

This package is intended to be consumed by component packages in the monorepo (and downstream projects like MAI) to standardize how Playwright tests are authored and run against FAST-based web components.

👩‍💻 Reviewer Notes

  • The package is currently marked private and is not published to npm.
  • SSR support depends on optional peer dependencies @microsoft/fast-html and @microsoft/fast-build.
  • The server.mjs entrypoint uses Express 5 and Vite's createServer API to handle both CSR page serving and SSR fixture generation in a single process.

📑 Test Plan

This package provides test infrastructure rather than component behavior. Validation will come from downstream adoption in component packages that use the harness fixtures. No Playwright tests are included in this package itself.

✅ Checklist

General

  • I have included a change request file using $ npm run change
  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

⏭ Next Steps

  • The wasm-renderer.ts module wraps the Rust-based fast-build WASM renderer for SSR template compilation. This may be extracted or refined as fast-build stabilizes.

() => `${preloadLinks ?? ""}${styleTags}`,
);

await fs.writeFile(filePath, html, "utf-8");
Comment on lines +117 to +136
app.use("*all", async (req, res, next) => {
// Only serve the HTML shell for navigation requests, not for
// module/asset requests that Vite's middleware didn't handle.
const accept = req.headers.accept || "";
if (!accept.includes("text/html")) {
return next();
}

try {
const url = req.originalUrl.replace(base, "");

const indexHtml = await fs.readFile(indexPath, "utf-8");
const index = await vite.transformIndexHtml(url, indexHtml);
res.status(200).set({ "Content-Type": "text/html" }).send(index);
} catch (e) {
vite?.ssrFixStacktrace?.(e);
console.log(e.stack);
res.status(500).end(e.stack);
}
});
Comment on lines +21 to +36
let processed = dsd.replace(
/(\s?)(\??)([a-zA-Z0-9-]+)="{{([a-zA-Z0-9]+)}}"/g,
(match, space, isBoolean, attrName, varName) => {
const value = templateValues[varName];

if (value === undefined) {
return "";
}

if (isBoolean === "?") {
return value ? `${space}${attrName}` : "";
}

return `${space}${attrName}="${value}"`;
},
);
}

// Directory-based scan: walk and collect.
const dir = resolve(cwd, pattern.replace(/\/\*.*$/, ""));
} catch (e) {
vite?.ssrFixStacktrace?.(e);
console.log(e.stack);
res.status(500).end(e.stack);
} catch (e) {
vite?.ssrFixStacktrace?.(e);
console.log(e.stack);
res.status(500).end(e.stack);
} catch (e) {
vite?.ssrFixStacktrace?.(e);
console.log(e.stack);
res.status(500).end(e.stack);
} catch (e) {
vite?.ssrFixStacktrace?.(e);
console.log(e.stack);
res.status(500).end(e.stack);
test.describe("Button", () => {
test.use({ tagName: "my-button", innerHTML: "Click me" });

test("should render", async ({ fastPage }) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is specifically from the @microsoft/fast-test-harness package, could this just be page instead of fastPage?

try {
// The WASM bindings are a CJS module generated by wasm-pack.
const wasmPath = require.resolve(
"@microsoft/fast-build/wasm/microsoft_fast_build.js",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this already throw some error message? should we give explicit instructions?


```bash
npm install --save-dev @microsoft/fast-test-harness
```
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this top section, can we match how it is written in the @microsoft/fast-element README.md?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants