Skip to content

Commit ae2b5a8

Browse files
committed
test: check a module's false/false pair and the lazy page's stylesheet
1 parent da40454 commit ae2b5a8

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

‎examples/start-ssr/test/run.mjs‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6142,6 +6142,7 @@ async function runNonceMode() {
61426142
[{}, 'an empty object', 'keys []'],
61436143
[{ script: 'a' }, 'a pair without style', '["script"]'],
61446144
[{ script: 'a', style: 1 }, 'a pair with a number', '["script","style"]'],
6145+
[{ script: '', style: 'a' }, 'a pair with an empty script', '["script","style"]'],
61456146
]) {
61466147
let rejection = '';
61476148
try {
@@ -6232,6 +6233,18 @@ async function runNonceMode() {
62326233
).text(),
62336234
),
62346235
);
6236+
record(
6237+
mode,
6238+
'module',
6239+
'a module returning { script: false, style: false } sends the page without one',
6240+
carriesNone(
6241+
await (
6242+
await handler.handleRequest(
6243+
page({ 'x-csp-nonce-json': '{"script":false,"style":false}' }),
6244+
)
6245+
).text(),
6246+
),
6247+
);
62356248
const viaAsync = await (
62366249
await handler.handleRequest(page({ 'x-csp-nonce': 'async-nonce', 'x-csp-nonce-async': '1' }))
62376250
).text();
@@ -6346,7 +6359,14 @@ async function runNonceMode() {
63466359
env: { ...process.env, SSR_DEVTOOLS: '0', ...moduleEnv },
63476360
});
63486361
await waitForHttp(devOrigin + '/src/api.ts', 30000);
6349-
for (const route of ['/', '/extra-input']) {
6362+
// The lazy page must render its content and its own stylesheet, or the
6363+
// check would pass on App.css alone.
6364+
const pageChecks = {
6365+
'/': () => true,
6366+
'/extra-input': (html, styles) =>
6367+
html.includes('EXTRA-INPUT-PAGE') && styles.some((tag) => tag.includes('ExtraInput.css')),
6368+
};
6369+
for (const [route, pageCheck] of Object.entries(pageChecks)) {
63506370
const res = await fetch(devOrigin + route, {
63516371
headers: {
63526372
accept: 'text/html',
@@ -6369,7 +6389,11 @@ async function runNonceMode() {
63696389
mode,
63706390
'dev-server',
63716391
`${route}: every <style> takes the style nonce, every <script> the script nonce`,
6372-
res.status === 200 && styles.length >= 1 && scripts.length >= 3 && off.length === 0,
6392+
res.status === 200 &&
6393+
pageCheck(html, styles) &&
6394+
styles.length >= 1 &&
6395+
scripts.length >= 3 &&
6396+
off.length === 0,
63736397
`status ${res.status}, ${styles.length} styles, ${scripts.length} scripts, off: ${off.join(' ').slice(0, 300)}`,
63746398
);
63756399
}

0 commit comments

Comments
 (0)