2023-01-26 12:43:39 -05:00
|
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
import { expect } from 'chai';
|
2023-05-17 08:23:20 -05:00
|
|
|
import slash from 'slash';
|
2023-01-26 12:43:39 -05:00
|
|
|
|
|
|
|
describe('Prerendering', () => {
|
|
|
|
/** @type {import('./test-utils').Fixture} */
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
before(async () => {
|
2023-05-17 08:23:20 -05:00
|
|
|
process.env.PRERENDER = true;
|
2023-01-26 12:43:39 -05:00
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/prerender/',
|
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
});
|
|
|
|
|
2023-05-17 08:23:20 -05:00
|
|
|
after(() => {
|
|
|
|
delete process.env.PRERENDER;
|
|
|
|
fixture.clean();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('includes prerendered routes in the routes.json config', async () => {
|
|
|
|
const foundRoutes = JSON.parse(await fixture.readFile('/_routes.json')).exclude.map((r) =>
|
|
|
|
slash(r)
|
|
|
|
);
|
|
|
|
const expectedExcludedRoutes = ['/_worker.js', '/one/index.html', '/one/'];
|
|
|
|
|
|
|
|
expect(foundRoutes.every((element) => expectedExcludedRoutes.includes(element))).to.be.true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Hybrid rendering', () => {
|
|
|
|
/** @type {import('./test-utils').Fixture} */
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
process.env.PRERENDER = false;
|
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/prerender/',
|
|
|
|
output: 'hybrid',
|
|
|
|
experimental: {
|
|
|
|
hybridOutput: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
delete process.env.PRERENDER;
|
|
|
|
});
|
|
|
|
|
2023-01-26 12:43:39 -05:00
|
|
|
it('includes prerendered routes in the routes.json config', async () => {
|
2023-05-17 08:23:20 -05:00
|
|
|
const foundRoutes = JSON.parse(await fixture.readFile('/_routes.json')).exclude.map((r) =>
|
|
|
|
slash(r)
|
|
|
|
);
|
|
|
|
const expectedExcludedRoutes = ['/_worker.js', '/index.html', '/'];
|
|
|
|
|
|
|
|
expect(foundRoutes.every((element) => expectedExcludedRoutes.includes(element))).to.be.true;
|
2023-01-26 12:43:39 -05:00
|
|
|
});
|
|
|
|
});
|