mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Add test for astro:route:setup
hook
This commit is contained in:
parent
11ebf3bd15
commit
a6465c2a85
8 changed files with 94 additions and 0 deletions
9
packages/astro/test/fixtures/integration-route-setup/astro.config.mjs
vendored
Normal file
9
packages/astro/test/fixtures/integration-route-setup/astro.config.mjs
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { defineConfig } from 'astro/config'
|
||||
import test from './integration.js'
|
||||
import node from '@astrojs/node';
|
||||
|
||||
export default defineConfig({
|
||||
output: 'hybrid',
|
||||
adapter: node({ mode: 'standalone' }),
|
||||
integrations: [test()]
|
||||
})
|
12
packages/astro/test/fixtures/integration-route-setup/integration.js
vendored
Normal file
12
packages/astro/test/fixtures/integration-route-setup/integration.js
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
export default function () {
|
||||
const routes = (globalThis.TEST_ROUTES_OBJECTS = []);
|
||||
|
||||
return {
|
||||
name: '@astrojs/test-integration',
|
||||
hooks: {
|
||||
'astro:route:setup': ({ route }) => {
|
||||
routes.push(route);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
10
packages/astro/test/fixtures/integration-route-setup/package.json
vendored
Normal file
10
packages/astro/test/fixtures/integration-route-setup/package.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@test/integration-route-setup",
|
||||
"type": "module",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@astrojs/node": "^8.3.3",
|
||||
"astro": "workspace:*"
|
||||
}
|
||||
}
|
5
packages/astro/test/fixtures/integration-route-setup/src/pages/no-prerender.astro
vendored
Normal file
5
packages/astro/test/fixtures/integration-route-setup/src/pages/no-prerender.astro
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
export const prerender = false;
|
||||
---
|
||||
|
||||
<div></div>
|
5
packages/astro/test/fixtures/integration-route-setup/src/pages/prerender.astro
vendored
Normal file
5
packages/astro/test/fixtures/integration-route-setup/src/pages/prerender.astro
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
export const prerender = true;
|
||||
---
|
||||
|
||||
<div></div>
|
13
packages/astro/test/fixtures/integration-route-setup/src/pages/report.json.js
vendored
Normal file
13
packages/astro/test/fixtures/integration-route-setup/src/pages/report.json.js
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
const routes = (globalThis.TEST_ROUTES_OBJECTS ?? []);
|
||||
|
||||
export const GET = () => {
|
||||
// Routes are not garanteed to be loaded in any particular order
|
||||
// sort for test stability.
|
||||
routes.sort((a, b) => a.component.localeCompare(b.component));
|
||||
|
||||
return new Response(JSON.stringify(routes), {
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
});
|
||||
};
|
31
packages/astro/test/integration-route-setup.test.js
Normal file
31
packages/astro/test/integration-route-setup.test.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { before, describe, it } from 'node:test';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Integration route setup', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
let fixture;
|
||||
|
||||
before(async () => {
|
||||
fixture = await loadFixture({ root: './fixtures/integration-route-setup/' });
|
||||
await fixture.build();
|
||||
});
|
||||
|
||||
it('Adds middlewares in dev', async () => {
|
||||
const routeInfo = JSON.parse(await fixture.readFile('client/report.json'));
|
||||
|
||||
assert.deepEqual(routeInfo, [
|
||||
{
|
||||
component: 'src/pages/no-prerender.astro',
|
||||
prerender: false,
|
||||
},
|
||||
{
|
||||
component: 'src/pages/prerender.astro',
|
||||
prerender: true,
|
||||
},
|
||||
{
|
||||
component: 'src/pages/report.json.js',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -3316,6 +3316,15 @@ importers:
|
|||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/integration-route-setup:
|
||||
dependencies:
|
||||
'@astrojs/node':
|
||||
specifier: ^8.3.3
|
||||
version: 8.3.3(astro@packages+astro)
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
|
||||
packages/astro/test/fixtures/integration-server-setup:
|
||||
dependencies:
|
||||
astro:
|
||||
|
|
Loading…
Reference in a new issue