isr.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { loadFixture } from './test-utils.js';
  2. import assert from 'node:assert/strict';
  3. import { before, describe, it } from 'node:test';
  4. describe('ISR', () => {
  5. /** @type {import('./test-utils.js').Fixture} */
  6. let fixture;
  7. before(async () => {
  8. fixture = await loadFixture({
  9. root: './fixtures/isr/',
  10. });
  11. await fixture.build();
  12. });
  13. it('generates expected prerender config', async () => {
  14. const vcConfig = JSON.parse(
  15. await fixture.readFile('../.vercel/output/functions/_isr.prerender-config.json')
  16. );
  17. assert.deepEqual(vcConfig, {
  18. expiration: 120,
  19. bypassToken: '1c9e601d-9943-4e7c-9575-005556d774a8',
  20. allowQuery: ['x_astro_path'],
  21. passQuery: true,
  22. });
  23. });
  24. it('generates expected routes', async () => {
  25. const deploymentConfig = JSON.parse(await fixture.readFile('../.vercel/output/config.json'));
  26. // the first two are /_astro/*, and filesystem routes
  27. assert.deepEqual(deploymentConfig.routes.slice(2), [
  28. {
  29. src: '^/two$',
  30. dest: '_render',
  31. },
  32. {
  33. src: '^\\/_image$',
  34. dest: '_render',
  35. },
  36. {
  37. src: '^\\/one\\/?$',
  38. dest: '/_isr?x_astro_path=$0',
  39. },
  40. {
  41. src: '^\\/two\\/?$',
  42. dest: '/_isr?x_astro_path=$0',
  43. },
  44. ]);
  45. });
  46. });