add test
This commit is contained in:
parent
5b124f3b81
commit
6499c9b3da
4 changed files with 110 additions and 0 deletions
9
packages/integrations/node/test/fixtures/trailing-slash/package.json
vendored
Normal file
9
packages/integrations/node/test/fixtures/trailing-slash/package.json
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"name": "@test/nodejs-trailing-slash",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"astro": "workspace:*",
|
||||
"@astrojs/node": "workspace:*"
|
||||
}
|
||||
}
|
10
packages/integrations/node/test/fixtures/trailing-slash/src/pages/one.astro
vendored
Normal file
10
packages/integrations/node/test/fixtures/trailing-slash/src/pages/one.astro
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
---
|
||||
<html>
|
||||
<head>
|
||||
<title>One</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>One</h1>
|
||||
</body>
|
||||
</html>
|
82
packages/integrations/node/test/trailing-slash.test.js
Normal file
82
packages/integrations/node/test/trailing-slash.test.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
import nodejs from '../dist/index.js';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import { expect } from 'chai';
|
||||
/**
|
||||
* @typedef {import('astro/test/test-utils.js').Fixture} Fixture
|
||||
*/
|
||||
|
||||
async function load() {
|
||||
const mod = await import(
|
||||
`./fixtures/trailing-slash/dist/server/entry.mjs?dropcache=${Date.now()}`
|
||||
);
|
||||
return mod;
|
||||
}
|
||||
|
||||
describe('Trailing Slash In Production', () => {
|
||||
/** @type {import('./test-utils.js').Fixture} */
|
||||
let fixture;
|
||||
let server;
|
||||
|
||||
describe('By default does add the trailing slash', async () => {
|
||||
before(async () => {
|
||||
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
|
||||
process.env.PRERENDER = true;
|
||||
|
||||
fixture = await loadFixture({
|
||||
// inconsequential config that differs between tests
|
||||
// to bust cache and prevent modules and their state
|
||||
// from being reused
|
||||
output: 'hybrid',
|
||||
root: './fixtures/trailing-slash/',
|
||||
adapter: nodejs({ mode: 'standalone' }),
|
||||
});
|
||||
await fixture.build();
|
||||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server.stop();
|
||||
await fixture.clean();
|
||||
delete process.env.PRERENDER;
|
||||
});
|
||||
|
||||
it('redirects each route to have trailing slash', async () => {
|
||||
const res = await fetch(`http://${server.host}:${server.port}/one`);
|
||||
expect(res.url).to.contain('one/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Does not add trailing slash when set to never', async () => {
|
||||
before(async () => {
|
||||
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
|
||||
process.env.PRERENDER = true;
|
||||
|
||||
fixture = await loadFixture({
|
||||
// inconsequential config that differs between tests
|
||||
// to bust cache and prevent modules and their state
|
||||
// from being reused
|
||||
output: 'hybrid',
|
||||
trailingSlash: 'never',
|
||||
root: './fixtures/trailing-slash/',
|
||||
adapter: nodejs({ mode: 'standalone' }),
|
||||
});
|
||||
await fixture.build();
|
||||
const { startServer } = await load();
|
||||
let res = startServer();
|
||||
server = res.server;
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server.stop();
|
||||
await fixture.clean();
|
||||
delete process.env.PRERENDER;
|
||||
});
|
||||
|
||||
it('redirects each route to have trailing slash', async () => {
|
||||
const res = await fetch(`http://${server.host}:${server.port}/one`);
|
||||
expect(res.url).to.not.contain('one/');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -4465,6 +4465,15 @@ importers:
|
|||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
|
||||
packages/integrations/node/test/fixtures/trailing-slash:
|
||||
dependencies:
|
||||
'@astrojs/node':
|
||||
specifier: workspace:*
|
||||
version: link:../../..
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../../../../astro
|
||||
|
||||
packages/integrations/node/test/fixtures/url-protocol:
|
||||
dependencies:
|
||||
'@astrojs/node':
|
||||
|
|
Loading…
Reference in a new issue