-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
test.js
43 lines (35 loc) · 1.39 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from 'fs';
import * as assert from 'uvu/assert';
import { run } from './utils.js';
run('prerendered', (test) => {
test('generates HTML files', ({ cwd }) => {
assert.ok(fs.existsSync(`${cwd}/build/index.html`));
});
test('prerenders content', async ({ base, page }) => {
await page.goto(base);
assert.equal(await page.textContent('h1'), 'This page was prerendered');
});
});
run('spa', (test) => {
test('generates a fallback page', async ({ base, cwd, page }) => {
assert.ok(fs.existsSync(`${cwd}/build/200.html`));
await page.goto(`${base}/fallback/a/b/c`);
assert.equal(await page.textContent('h1'), 'the fallback page was rendered');
});
test('does not prerender pages without prerender=true', ({ cwd }) => {
assert.ok(!fs.existsSync(`${cwd}/build/index.html`));
});
test('prerenders page with prerender=true', ({ cwd }) => {
assert.ok(fs.existsSync(`${cwd}/build/about.html`));
});
test('renders content in fallback page when JS runs', async ({ base, page }) => {
await page.goto(base);
assert.equal(await page.textContent('h1'), 'This page was not prerendered');
});
test('renders error page for missing page', async ({ base, page }) => {
await page.goto(`${base}/nosuchpage`);
assert.equal(await page.textContent('h1'), '404');
await page.waitForLoadState('networkidle', { timeout: 1000 });
assert.equal(await page.textContent('h2'), 'count: 1');
});
});