@microsoft/fast-test-harness 0.1.0 → 0.3.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/README.md +25 -19
- package/dist/dts/build/generate-templates.d.ts +35 -0
- package/dist/dts/build/generate-templates.d.ts.map +1 -1
- package/dist/dts/build/generate-webui-templates.d.ts +14 -1
- package/dist/dts/build/generate-webui-templates.d.ts.map +1 -1
- package/dist/dts/fixtures/csr-fixture.d.ts +28 -0
- package/dist/dts/fixtures/csr-fixture.d.ts.map +1 -1
- package/dist/dts/fixtures/ssr-fixture.d.ts +19 -0
- package/dist/dts/fixtures/ssr-fixture.d.ts.map +1 -1
- package/dist/dts/ssr/render.d.ts +11 -16
- package/dist/dts/ssr/render.d.ts.map +1 -1
- package/dist/esm/build/generate-templates.js +62 -2
- package/dist/esm/build/generate-webui-templates.js +9 -26
- package/dist/esm/fixtures/ssr-fixture.js +19 -1
- package/dist/esm/ssr/render.js +48 -104
- package/package.json +26 -15
- package/dist/dts/build/dom-shim.test.d.ts +0 -2
- package/dist/dts/build/dom-shim.test.d.ts.map +0 -1
- package/dist/dts/build/generate-stylesheets.test.d.ts +0 -2
- package/dist/dts/build/generate-stylesheets.test.d.ts.map +0 -1
- package/dist/dts/build/generate-templates.test.d.ts +0 -2
- package/dist/dts/build/generate-templates.test.d.ts.map +0 -1
- package/dist/dts/build/generate-webui-templates.test.d.ts +0 -2
- package/dist/dts/build/generate-webui-templates.test.d.ts.map +0 -1
- package/dist/dts/fixtures/csr-fixture.pw.spec.d.ts +0 -2
- package/dist/dts/fixtures/csr-fixture.pw.spec.d.ts.map +0 -1
- package/dist/dts/fixtures/ssr-fixture.pw.spec.d.ts +0 -2
- package/dist/dts/fixtures/ssr-fixture.pw.spec.d.ts.map +0 -1
- package/dist/dts/ssr/render.test.d.ts +0 -2
- package/dist/dts/ssr/render.test.d.ts.map +0 -1
- package/dist/esm/build/dom-shim.test.js +0 -202
- package/dist/esm/build/generate-stylesheets.test.js +0 -74
- package/dist/esm/build/generate-templates.test.js +0 -231
- package/dist/esm/build/generate-webui-templates.test.js +0 -179
- package/dist/esm/fixtures/csr-fixture.pw.spec.js +0 -137
- package/dist/esm/fixtures/ssr-fixture.pw.spec.js +0 -189
- package/dist/esm/ssr/render.test.js +0 -236
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@microsoft/fast-test-harness";
|
|
2
|
-
test.describe("SSR: setTemplate", () => {
|
|
3
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
4
|
-
test("should navigate to the SSR fixture page", async ({ fastPage, page }) => {
|
|
5
|
-
await fastPage.setTemplate();
|
|
6
|
-
const url = new URL(page.url());
|
|
7
|
-
expect(url.pathname).toMatch(/^\/ssr-.*\.html$/);
|
|
8
|
-
expect(url.pathname).toContain("should_navigate_to_the_ssr_fixture_page");
|
|
9
|
-
});
|
|
10
|
-
test("should render the element with default options", async ({ fastPage }) => {
|
|
11
|
-
await fastPage.setTemplate();
|
|
12
|
-
await expect(fastPage.element).toHaveCount(1);
|
|
13
|
-
});
|
|
14
|
-
test("should render with innerHTML", async ({ fastPage }) => {
|
|
15
|
-
await fastPage.setTemplate({ innerHTML: "<span>child</span>" });
|
|
16
|
-
await expect(fastPage.element).toHaveCount(1);
|
|
17
|
-
await expect(fastPage.element).toContainText("child");
|
|
18
|
-
});
|
|
19
|
-
test("should render with attributes", async ({ fastPage }) => {
|
|
20
|
-
await fastPage.setTemplate({
|
|
21
|
-
attributes: { label: "Hello", size: "large" },
|
|
22
|
-
});
|
|
23
|
-
await expect(fastPage.element).toHaveAttribute("label", "Hello");
|
|
24
|
-
await expect(fastPage.element).toHaveAttribute("size", "large");
|
|
25
|
-
});
|
|
26
|
-
test("should render with boolean attribute", async ({ fastPage }) => {
|
|
27
|
-
await fastPage.setTemplate({ attributes: { disabled: true } });
|
|
28
|
-
await expect(fastPage.element).toHaveAttribute("disabled");
|
|
29
|
-
});
|
|
30
|
-
test("should render with a raw HTML string", async ({ fastPage }) => {
|
|
31
|
-
await fastPage.setTemplate(`<test-widget label="raw">raw content</test-widget>`);
|
|
32
|
-
await expect(fastPage.element).toHaveAttribute("label", "raw");
|
|
33
|
-
await expect(fastPage.element).toContainText("raw content");
|
|
34
|
-
});
|
|
35
|
-
test("should replace the previous template on subsequent calls", async ({ fastPage, }) => {
|
|
36
|
-
await fastPage.setTemplate({ attributes: { label: "first" } });
|
|
37
|
-
await expect(fastPage.element).toHaveAttribute("label", "first");
|
|
38
|
-
await fastPage.setTemplate({ attributes: { label: "second" } });
|
|
39
|
-
await expect(fastPage.element).toHaveAttribute("label", "second");
|
|
40
|
-
await expect(fastPage.element).toHaveCount(1);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
test.describe("SSR: updateTemplate", () => {
|
|
44
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
45
|
-
test("should update attributes on an existing element", async ({ fastPage }) => {
|
|
46
|
-
await fastPage.setTemplate({ attributes: { label: "before" } });
|
|
47
|
-
await expect(fastPage.element).toHaveAttribute("label", "before");
|
|
48
|
-
await fastPage.updateTemplate("test-widget", {
|
|
49
|
-
attributes: { label: "after" },
|
|
50
|
-
});
|
|
51
|
-
await expect(fastPage.element).toHaveAttribute("label", "after");
|
|
52
|
-
});
|
|
53
|
-
test("should remove an attribute when set to false", async ({ fastPage }) => {
|
|
54
|
-
await fastPage.setTemplate({ attributes: { disabled: true } });
|
|
55
|
-
await expect(fastPage.element).toHaveAttribute("disabled");
|
|
56
|
-
await fastPage.updateTemplate("test-widget", {
|
|
57
|
-
attributes: { disabled: false },
|
|
58
|
-
});
|
|
59
|
-
await expect(fastPage.element).not.toHaveAttribute("disabled");
|
|
60
|
-
});
|
|
61
|
-
test("should update innerHTML", async ({ fastPage }) => {
|
|
62
|
-
await fastPage.setTemplate({ innerHTML: "original" });
|
|
63
|
-
await fastPage.updateTemplate("test-widget", {
|
|
64
|
-
innerHTML: "updated",
|
|
65
|
-
});
|
|
66
|
-
await expect(fastPage.element).toContainText("updated");
|
|
67
|
-
});
|
|
68
|
-
test("should accept a Locator", async ({ fastPage }) => {
|
|
69
|
-
await fastPage.setTemplate({ attributes: { label: "loc" } });
|
|
70
|
-
await fastPage.updateTemplate(fastPage.element, {
|
|
71
|
-
attributes: { label: "via-locator" },
|
|
72
|
-
});
|
|
73
|
-
await expect(fastPage.element).toHaveAttribute("label", "via-locator");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
test.describe("SSR: applyTokens", () => {
|
|
77
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
78
|
-
test("should set CSS custom properties on the body", async ({ fastPage }) => {
|
|
79
|
-
await fastPage.setTemplate();
|
|
80
|
-
await fastPage.applyTokens({
|
|
81
|
-
"color-primary": "#0078d4",
|
|
82
|
-
"spacing-m": "8px",
|
|
83
|
-
});
|
|
84
|
-
const value = await fastPage.page.evaluate(() => document.body.style.getPropertyValue("--color-primary"));
|
|
85
|
-
expect(value).toBe("#0078d4");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
test.describe("SSR: waitForCustomElement", () => {
|
|
89
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
90
|
-
test("should resolve for a registered element", async ({ fastPage }) => {
|
|
91
|
-
await fastPage.setTemplate();
|
|
92
|
-
await fastPage.waitForCustomElement("test-widget");
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
test.describe("SSR: toHaveCustomState", () => {
|
|
96
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
97
|
-
test("should pass when element has the custom state", async ({ fastPage }) => {
|
|
98
|
-
await fastPage.setTemplate({ attributes: { disabled: true } });
|
|
99
|
-
await expect(fastPage.element).toHaveCustomState("disabled");
|
|
100
|
-
});
|
|
101
|
-
test("should fail (negated) when element does not have the state", async ({ fastPage, }) => {
|
|
102
|
-
await fastPage.setTemplate();
|
|
103
|
-
await expect(fastPage.element).not.toHaveCustomState("disabled");
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
test.describe("SSR: element locator", () => {
|
|
107
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
108
|
-
test("should locate the element by tag name", async ({ fastPage }) => {
|
|
109
|
-
await fastPage.setTemplate();
|
|
110
|
-
await expect(fastPage.element).toHaveCount(1);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
test.describe("SSR: declarative shadow DOM", () => {
|
|
114
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
115
|
-
test("should have a shadow root after SSR render", async ({ fastPage }) => {
|
|
116
|
-
await fastPage.setTemplate({ attributes: { label: "DSD" } });
|
|
117
|
-
const hasShadow = await fastPage.element.evaluate(el => el.shadowRoot !== null);
|
|
118
|
-
expect(hasShadow).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
test.describe("SSR: template placeholder replacement", () => {
|
|
122
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
123
|
-
test("should replace the fixture placeholder with rendered component HTML", async ({ fastPage, page, }) => {
|
|
124
|
-
await fastPage.setTemplate({ attributes: { label: "test" } });
|
|
125
|
-
const bodyHtml = await page.locator("body").innerHTML();
|
|
126
|
-
expect(bodyHtml).not.toContain("<!--fixture-->");
|
|
127
|
-
expect(bodyHtml).toContain("<test-widget");
|
|
128
|
-
});
|
|
129
|
-
test("should replace the title placeholder with the test title", async ({ fastPage, page, }) => {
|
|
130
|
-
await fastPage.setTemplate();
|
|
131
|
-
const title = await page.title();
|
|
132
|
-
expect(title).not.toBe("<!--fixturetitle-->");
|
|
133
|
-
expect(title.length).toBeGreaterThan(0);
|
|
134
|
-
});
|
|
135
|
-
test("should replace the templates placeholder with template content", async ({ fastPage, page, }) => {
|
|
136
|
-
await fastPage.setTemplate();
|
|
137
|
-
const bodyHtml = await page.locator("body").innerHTML();
|
|
138
|
-
expect(bodyHtml).not.toContain("<!--templates-->");
|
|
139
|
-
});
|
|
140
|
-
test("should replace the stylespreload placeholder with preload links", async ({ fastPage, page, }) => {
|
|
141
|
-
await fastPage.setTemplate();
|
|
142
|
-
const headHtml = await page.locator("head").innerHTML();
|
|
143
|
-
expect(headHtml).not.toContain("<!--stylespreload-->");
|
|
144
|
-
expect(headHtml).toContain("/test-theme.css");
|
|
145
|
-
});
|
|
146
|
-
test("should not contain any unreplaced placeholder comments", async ({ fastPage, page, }) => {
|
|
147
|
-
await fastPage.setTemplate();
|
|
148
|
-
const fullHtml = await page.content();
|
|
149
|
-
expect(fullHtml).not.toContain("<!--fixture-->");
|
|
150
|
-
expect(fullHtml).not.toContain("<!--fixturetitle-->");
|
|
151
|
-
expect(fullHtml).not.toContain("<!--templates-->");
|
|
152
|
-
expect(fullHtml).not.toContain("<!--stylespreload-->");
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
test.describe("SSR: addStyleTag buffering", () => {
|
|
156
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
157
|
-
test("should include buffered styles in the SSR page", async ({ fastPage, page }) => {
|
|
158
|
-
await fastPage.addStyleTag({
|
|
159
|
-
content: "test-widget { outline: 3px solid blue; }",
|
|
160
|
-
});
|
|
161
|
-
await fastPage.setTemplate();
|
|
162
|
-
const hasStyle = await page.evaluate(() => {
|
|
163
|
-
const styles = document.querySelectorAll("style");
|
|
164
|
-
return Array.from(styles).some(s => s.textContent?.includes("outline: 3px solid blue"));
|
|
165
|
-
});
|
|
166
|
-
expect(hasStyle).toBe(true);
|
|
167
|
-
});
|
|
168
|
-
test("should pass through addStyleTag calls after setTemplate", async ({ fastPage, page, }) => {
|
|
169
|
-
await fastPage.setTemplate();
|
|
170
|
-
await fastPage.addStyleTag({
|
|
171
|
-
content: "test-widget { margin: 99px; }",
|
|
172
|
-
});
|
|
173
|
-
const hasStyle = await page.evaluate(() => {
|
|
174
|
-
const styles = document.querySelectorAll("style");
|
|
175
|
-
return Array.from(styles).some(s => s.textContent?.includes("margin: 99px"));
|
|
176
|
-
});
|
|
177
|
-
expect(hasStyle).toBe(true);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
test.describe("SSR: multiple elements", () => {
|
|
181
|
-
test.use({ tagName: "test-widget", ssr: true });
|
|
182
|
-
test("should handle templates with multiple instances", async ({ fastPage }) => {
|
|
183
|
-
await fastPage.setTemplate(`
|
|
184
|
-
<test-widget label="first">one</test-widget>
|
|
185
|
-
<test-widget label="second">two</test-widget>
|
|
186
|
-
`);
|
|
187
|
-
await expect(fastPage.element).toHaveCount(2);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert/strict";
|
|
2
|
-
import { test } from "node:test";
|
|
3
|
-
import { buildEntryHtml, buildState, createSSRRenderer, parseDefaultValue, renderTemplate, } from "@microsoft/fast-test-harness/ssr/render.js";
|
|
4
|
-
test.describe("parseDefaultValue", () => {
|
|
5
|
-
test("should return empty string for empty input", () => {
|
|
6
|
-
assert.strictEqual(parseDefaultValue(""), "");
|
|
7
|
-
});
|
|
8
|
-
test("should return empty string for 'undefined'", () => {
|
|
9
|
-
assert.strictEqual(parseDefaultValue("undefined"), "");
|
|
10
|
-
});
|
|
11
|
-
test("should return empty string for 'null'", () => {
|
|
12
|
-
assert.strictEqual(parseDefaultValue("null"), "");
|
|
13
|
-
});
|
|
14
|
-
test("should return true for 'true'", () => {
|
|
15
|
-
assert.strictEqual(parseDefaultValue("true"), true);
|
|
16
|
-
});
|
|
17
|
-
test("should return false for 'false'", () => {
|
|
18
|
-
assert.strictEqual(parseDefaultValue("false"), false);
|
|
19
|
-
});
|
|
20
|
-
test("should strip single quotes from strings", () => {
|
|
21
|
-
assert.strictEqual(parseDefaultValue("'img'"), "img");
|
|
22
|
-
});
|
|
23
|
-
test("should strip double quotes from strings", () => {
|
|
24
|
-
assert.strictEqual(parseDefaultValue('"hello"'), "hello");
|
|
25
|
-
});
|
|
26
|
-
test("should parse integers", () => {
|
|
27
|
-
assert.strictEqual(parseDefaultValue("42"), 42);
|
|
28
|
-
});
|
|
29
|
-
test("should parse floats", () => {
|
|
30
|
-
assert.strictEqual(parseDefaultValue("3.14"), 3.14);
|
|
31
|
-
});
|
|
32
|
-
test("should parse zero", () => {
|
|
33
|
-
assert.strictEqual(parseDefaultValue("0"), 0);
|
|
34
|
-
});
|
|
35
|
-
test("should parse JSON arrays", () => {
|
|
36
|
-
assert.deepStrictEqual(parseDefaultValue("[1,2,3]"), [1, 2, 3]);
|
|
37
|
-
});
|
|
38
|
-
test("should parse JSON objects", () => {
|
|
39
|
-
assert.deepStrictEqual(parseDefaultValue('{"a":1}'), { a: 1 });
|
|
40
|
-
});
|
|
41
|
-
test("should return empty string for unparseable values", () => {
|
|
42
|
-
assert.strictEqual(parseDefaultValue("some random text"), "");
|
|
43
|
-
});
|
|
44
|
-
test("should trim whitespace", () => {
|
|
45
|
-
assert.strictEqual(parseDefaultValue(" true "), true);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
test.describe("renderTemplate", () => {
|
|
49
|
-
test("should replace {{styles}} with a link tag", () => {
|
|
50
|
-
const result = renderTemplate("<template>{{styles}}<div>hi</div></template>", "/styles.css");
|
|
51
|
-
assert.ok(result.includes('<link rel="stylesheet" href="/styles.css">'));
|
|
52
|
-
assert.ok(!result.includes("{{styles}}"));
|
|
53
|
-
});
|
|
54
|
-
test("should inject link after <template> if {{styles}} is absent", () => {
|
|
55
|
-
const result = renderTemplate("<template><div>hi</div></template>", "/styles.css");
|
|
56
|
-
assert.ok(result.includes('<link rel="stylesheet" href="/styles.css">'));
|
|
57
|
-
assert.ok(result.indexOf("<link") > result.indexOf("<template>"));
|
|
58
|
-
});
|
|
59
|
-
test("should remove {{styles}} marker when styles URL is empty", () => {
|
|
60
|
-
const input = "<template>{{styles}}<div>hi</div></template>";
|
|
61
|
-
const result = renderTemplate(input, "");
|
|
62
|
-
assert.strictEqual(result, "<template><div>hi</div></template>");
|
|
63
|
-
assert.ok(!result.includes('<link rel="stylesheet"'));
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
test.describe("buildEntryHtml", () => {
|
|
67
|
-
test("should return raw html when 'html' key is present", () => {
|
|
68
|
-
const result = buildEntryHtml({ html: "<div>raw</div>" });
|
|
69
|
-
assert.strictEqual(result, "<div>raw</div>");
|
|
70
|
-
});
|
|
71
|
-
test("should build a custom element tag from tagName", () => {
|
|
72
|
-
const result = buildEntryHtml({ tagName: "my-el" });
|
|
73
|
-
assert.strictEqual(result, "<my-el></my-el>");
|
|
74
|
-
});
|
|
75
|
-
test("should include innerHTML", () => {
|
|
76
|
-
const result = buildEntryHtml({
|
|
77
|
-
tagName: "my-el",
|
|
78
|
-
innerHTML: "content",
|
|
79
|
-
});
|
|
80
|
-
assert.strictEqual(result, "<my-el>content</my-el>");
|
|
81
|
-
});
|
|
82
|
-
test("should serialize attributes", () => {
|
|
83
|
-
const result = buildEntryHtml({
|
|
84
|
-
tagName: "my-el",
|
|
85
|
-
attributes: JSON.stringify({ role: "button", size: "large" }),
|
|
86
|
-
});
|
|
87
|
-
assert.ok(result.includes('role="button"'));
|
|
88
|
-
assert.ok(result.includes('size="large"'));
|
|
89
|
-
});
|
|
90
|
-
test("should handle boolean true attributes", () => {
|
|
91
|
-
const result = buildEntryHtml({
|
|
92
|
-
tagName: "my-el",
|
|
93
|
-
attributes: JSON.stringify({ disabled: true }),
|
|
94
|
-
});
|
|
95
|
-
assert.ok(result.includes("disabled"));
|
|
96
|
-
assert.ok(!result.includes('disabled="'));
|
|
97
|
-
});
|
|
98
|
-
test("should return empty string when no tagName or html", () => {
|
|
99
|
-
assert.strictEqual(buildEntryHtml({}), "");
|
|
100
|
-
});
|
|
101
|
-
test("should handle invalid JSON in attributes gracefully", () => {
|
|
102
|
-
const result = buildEntryHtml({
|
|
103
|
-
tagName: "my-el",
|
|
104
|
-
attributes: "not-json",
|
|
105
|
-
});
|
|
106
|
-
assert.strictEqual(result, "<my-el></my-el>");
|
|
107
|
-
});
|
|
108
|
-
test("should omit attributes with false, null, or undefined values", () => {
|
|
109
|
-
const result = buildEntryHtml({
|
|
110
|
-
tagName: "my-el",
|
|
111
|
-
attributes: JSON.stringify({ disabled: false, hidden: null, role: "button" }),
|
|
112
|
-
});
|
|
113
|
-
assert.ok(!result.includes("disabled"), `should not include disabled: ${result}`);
|
|
114
|
-
assert.ok(!result.includes("hidden"), `should not include hidden: ${result}`);
|
|
115
|
-
assert.ok(result.includes('role="button"'), `should include role: ${result}`);
|
|
116
|
-
});
|
|
117
|
-
test("should escape special characters in attribute values", () => {
|
|
118
|
-
const result = buildEntryHtml({
|
|
119
|
-
tagName: "my-el",
|
|
120
|
-
attributes: JSON.stringify({ title: 'a&b<c>"d' }),
|
|
121
|
-
});
|
|
122
|
-
assert.ok(result.includes("a&b<c>"d"), `got: ${result}`);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
test.describe("buildState", () => {
|
|
126
|
-
test("should extract attributes into state", () => {
|
|
127
|
-
const state = buildState({
|
|
128
|
-
attributes: JSON.stringify({ size: "large", active: true }),
|
|
129
|
-
});
|
|
130
|
-
assert.strictEqual(state.size, "large");
|
|
131
|
-
assert.strictEqual(state.active, true);
|
|
132
|
-
});
|
|
133
|
-
test("should add hyphen-stripped variants", () => {
|
|
134
|
-
const state = buildState({
|
|
135
|
-
attributes: JSON.stringify({ "aria-label": "Close" }),
|
|
136
|
-
});
|
|
137
|
-
assert.strictEqual(state["aria-label"], "Close");
|
|
138
|
-
assert.strictEqual(state["arialabel"], "Close");
|
|
139
|
-
});
|
|
140
|
-
test("should return empty state for missing attributes", () => {
|
|
141
|
-
const state = buildState({});
|
|
142
|
-
assert.deepStrictEqual(state, {});
|
|
143
|
-
});
|
|
144
|
-
test("should handle invalid JSON gracefully", () => {
|
|
145
|
-
const state = buildState({ attributes: "broken" });
|
|
146
|
-
assert.deepStrictEqual(state, {});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
test.describe("createSSRRenderer", () => {
|
|
150
|
-
test("should return a render function when @microsoft/fast-build is installed", () => {
|
|
151
|
-
const renderer = createSSRRenderer({
|
|
152
|
-
tagPrefix: "test",
|
|
153
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
154
|
-
});
|
|
155
|
-
assert.ok(typeof renderer.render === "function");
|
|
156
|
-
});
|
|
157
|
-
test("should return a RenderResult from render()", () => {
|
|
158
|
-
const { render } = createSSRRenderer({
|
|
159
|
-
tagPrefix: "test",
|
|
160
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
161
|
-
});
|
|
162
|
-
const result = render({ tagName: "test-widget", innerHTML: "hello" });
|
|
163
|
-
assert.ok("template" in result, "result should have template");
|
|
164
|
-
assert.ok("fixture" in result, "result should have fixture");
|
|
165
|
-
assert.ok("preloadLinks" in result, "result should have preloadLinks");
|
|
166
|
-
});
|
|
167
|
-
test("should render a custom element tag in the fixture", () => {
|
|
168
|
-
const { render } = createSSRRenderer({
|
|
169
|
-
tagPrefix: "test",
|
|
170
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
171
|
-
});
|
|
172
|
-
const result = render({ tagName: "test-widget", innerHTML: "content" });
|
|
173
|
-
assert.ok(result.fixture.includes("<test-widget"), `fixture should include element, got: ${result.fixture}`);
|
|
174
|
-
assert.ok(result.fixture.includes("content"), `fixture should include innerHTML, got: ${result.fixture}`);
|
|
175
|
-
});
|
|
176
|
-
test("should include attributes in the rendered fixture", () => {
|
|
177
|
-
const { render } = createSSRRenderer({
|
|
178
|
-
tagPrefix: "test",
|
|
179
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
180
|
-
});
|
|
181
|
-
const result = render({
|
|
182
|
-
tagName: "test-widget",
|
|
183
|
-
attributes: JSON.stringify({ label: "Test", disabled: true }),
|
|
184
|
-
});
|
|
185
|
-
assert.ok(result.fixture.includes("label="), `fixture should include label attr, got: ${result.fixture}`);
|
|
186
|
-
assert.ok(result.fixture.includes("disabled"), `fixture should include disabled attr, got: ${result.fixture}`);
|
|
187
|
-
});
|
|
188
|
-
test("should include theme stylesheet in preloadLinks", () => {
|
|
189
|
-
const { render } = createSSRRenderer({
|
|
190
|
-
tagPrefix: "test",
|
|
191
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
192
|
-
themeStylesheet: "/theme.css",
|
|
193
|
-
});
|
|
194
|
-
const result = render({ tagName: "test-widget" });
|
|
195
|
-
assert.ok(result.preloadLinks.includes("/theme.css"), `preloadLinks should include theme URL, got: ${result.preloadLinks}`);
|
|
196
|
-
});
|
|
197
|
-
test("should return empty preloadLinks without a theme", () => {
|
|
198
|
-
const { render } = createSSRRenderer({
|
|
199
|
-
tagPrefix: "test",
|
|
200
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
201
|
-
});
|
|
202
|
-
const result = render({ tagName: "test-widget" });
|
|
203
|
-
assert.strictEqual(result.preloadLinks, "");
|
|
204
|
-
});
|
|
205
|
-
test("should handle raw HTML via the html key", () => {
|
|
206
|
-
const { render } = createSSRRenderer({
|
|
207
|
-
tagPrefix: "test",
|
|
208
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
209
|
-
});
|
|
210
|
-
const result = render({
|
|
211
|
-
html: "<test-widget>raw html</test-widget>",
|
|
212
|
-
});
|
|
213
|
-
assert.ok(result.fixture.includes("raw html"), `fixture should contain raw html content, got: ${result.fixture}`);
|
|
214
|
-
});
|
|
215
|
-
test("should return empty fixture for empty query", () => {
|
|
216
|
-
const { render } = createSSRRenderer({
|
|
217
|
-
tagPrefix: "test",
|
|
218
|
-
components: [{ name: "widget", packageName: "@microsoft/fast-test-harness" }],
|
|
219
|
-
});
|
|
220
|
-
const result = render({});
|
|
221
|
-
assert.strictEqual(result.fixture, "");
|
|
222
|
-
});
|
|
223
|
-
test("should work with monolithic packageName mode", () => {
|
|
224
|
-
// The test harness itself doesn't have component subdirectories,
|
|
225
|
-
// so the template map will be empty — but the factory should not throw.
|
|
226
|
-
const { render } = createSSRRenderer({
|
|
227
|
-
tagPrefix: "fast",
|
|
228
|
-
packageName: "@microsoft/fast-test-harness",
|
|
229
|
-
distDir: "dist/esm",
|
|
230
|
-
});
|
|
231
|
-
assert.ok(typeof render === "function");
|
|
232
|
-
const result = render({ tagName: "fast-widget", innerHTML: "hello" });
|
|
233
|
-
// Without matching templates the WASM renderer should still produce output.
|
|
234
|
-
assert.ok("fixture" in result);
|
|
235
|
-
});
|
|
236
|
-
});
|