Implement tests for integrations mutating prerendering (#6957)
This commit is contained in:
parent
367e617761
commit
abcefe55cd
2 changed files with 56 additions and 0 deletions
8
packages/astro/test/fixtures/ssr-prerender/src/pages/not-prerendered.astro
vendored
Normal file
8
packages/astro/test/fixtures/ssr-prerender/src/pages/not-prerendered.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Not prerendered</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="greeting">Hello world!</h1>
|
||||
</body>
|
||||
</html>
|
48
packages/astro/test/ssr-prerender-integrations.test.js
Normal file
48
packages/astro/test/ssr-prerender-integrations.test.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { expect } from 'chai';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
|
||||
describe('Integrations can hook into the prerendering decision', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
||||
const testIntegration = {
|
||||
name: 'test prerendering integration',
|
||||
hooks: {
|
||||
['astro:build:setup']({ pages, target }) {
|
||||
if (target !== 'client') return;
|
||||
// this page has `export const prerender = true`
|
||||
pages.get('src/pages/static.astro').route.prerender = false
|
||||
|
||||
// this page does not
|
||||
pages.get('src/pages/not-prerendered.astro').route.prerender = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
root: './fixtures/ssr-prerender/',
|
||||
output: 'server',
|
||||
integrations: [testIntegration],
|
||||
adapter: testAdapter(),
|
||||
});
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('An integration can override the prerender flag', async () => {
|
||||
// test adapter only hosts dynamic routes
|
||||
// /static is expected to become dynamic
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/static');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(200);
|
||||
});
|
||||
|
||||
it('An integration can turn a normal page to a prerendered one', async () => {
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
const request = new Request('http://example.com/not-prerendered');
|
||||
const response = await app.render(request);
|
||||
expect(response.status).to.equal(404);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue