0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/vercel/test/isr.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.3 KiB
JavaScript
Raw Normal View History

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:37:44 -05:00
describe('ISR', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
2024-02-07 08:37:44 -05:00
root: './fixtures/isr/',
});
await fixture.build();
});
2024-02-07 08:37:44 -05:00
it('generates expected prerender config', async () => {
const vcConfig = JSON.parse(
2024-02-07 08:37:44 -05:00
await fixture.readFile('../.vercel/output/functions/_isr.prerender-config.json')
);
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:37:44 -05:00
it('generates expected routes', async () => {
const deploymentConfig = JSON.parse(await fixture.readFile('../.vercel/output/config.json'));
// the first two are /_astro/*, and filesystem routes
assert.deepEqual(deploymentConfig.routes.slice(2), [
{
2024-02-07 08:37:44 -05:00
src: '^/two$',
dest: '_render',
},
{
src: '^/excluded/([^/]+?)$',
2024-03-28 13:17:46 -05:00
dest: '_render',
},
{
2024-02-07 08:37:44 -05:00
src: '^\\/_image$',
dest: '_render',
},
{
src: '^\\/excluded\\/([^/]+?)\\/?$',
dest: '/_isr?x_astro_path=$0',
},
{
2024-02-07 08:37:44 -05:00
src: '^\\/one\\/?$',
dest: '/_isr?x_astro_path=$0',
},
{
2024-02-07 08:37:44 -05:00
src: '^\\/two\\/?$',
dest: '/_isr?x_astro_path=$0',
},
]);
});
});