2024-02-13 08:23:07 -05:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { before, describe, it } from 'node:test';
|
2024-02-07 08:37:44 -05:00
|
|
|
import { loadFixture } from './test-utils.js';
|
2024-02-07 08:36:37 -05:00
|
|
|
|
2024-02-07 08:37:44 -05:00
|
|
|
describe('ISR', () => {
|
2024-02-07 08:36:37 -05:00
|
|
|
/** @type {import('./test-utils.js').Fixture} */
|
|
|
|
let fixture;
|
|
|
|
|
|
|
|
before(async () => {
|
|
|
|
fixture = await loadFixture({
|
2024-02-07 08:37:44 -05:00
|
|
|
root: './fixtures/isr/',
|
2024-02-07 08:36:37 -05:00
|
|
|
});
|
|
|
|
await fixture.build();
|
|
|
|
});
|
|
|
|
|
2024-02-07 08:37:44 -05:00
|
|
|
it('generates expected prerender config', async () => {
|
2024-02-07 08:36:37 -05:00
|
|
|
const vcConfig = JSON.parse(
|
2024-02-07 08:37:44 -05:00
|
|
|
await fixture.readFile('../.vercel/output/functions/_isr.prerender-config.json')
|
2024-02-07 08:36:37 -05:00
|
|
|
);
|
2024-02-13 08:23:07 -05:00
|
|
|
assert.deepEqual(vcConfig, {
|
2024-02-07 08:37:44 -05:00
|
|
|
expiration: 120,
|
|
|
|
bypassToken: '1c9e601d-9943-4e7c-9575-005556d774a8',
|
|
|
|
allowQuery: ['x_astro_path'],
|
|
|
|
passQuery: true,
|
|
|
|
});
|
|
|
|
});
|
2024-02-07 08:36:37 -05:00
|
|
|
|
2024-02-07 08:37:44 -05:00
|
|
|
it('generates expected routes', async () => {
|
|
|
|
const deploymentConfig = JSON.parse(await fixture.readFile('../.vercel/output/config.json'));
|
2024-02-07 08:36:37 -05:00
|
|
|
// the first two are /_astro/*, and filesystem routes
|
2024-02-13 08:23:07 -05:00
|
|
|
assert.deepEqual(deploymentConfig.routes.slice(2), [
|
2024-02-07 08:36:37 -05:00
|
|
|
{
|
2024-02-07 08:37:44 -05:00
|
|
|
src: '^/two$',
|
|
|
|
dest: '_render',
|
2024-02-07 08:36:37 -05:00
|
|
|
},
|
|
|
|
{
|
2024-02-07 08:37:44 -05:00
|
|
|
src: '^\\/_image$',
|
|
|
|
dest: '_render',
|
2024-02-07 08:36:37 -05:00
|
|
|
},
|
|
|
|
{
|
2024-02-07 08:37:44 -05:00
|
|
|
src: '^\\/one\\/?$',
|
|
|
|
dest: '/_isr?x_astro_path=$0',
|
2024-02-07 08:36:37 -05:00
|
|
|
},
|
|
|
|
{
|
2024-02-07 08:37:44 -05:00
|
|
|
src: '^\\/two\\/?$',
|
|
|
|
dest: '/_isr?x_astro_path=$0',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|