2023-01-10 16:59:20 +00:00
|
|
|
import nodejs from '../dist/index.js';
|
2023-07-03 12:59:43 +00:00
|
|
|
import { loadFixture } from './test-utils.js';
|
2023-01-10 16:59:20 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
import * as cheerio from 'cheerio';
|
|
|
|
|
2023-08-01 14:52:16 +00:00
|
|
|
/**
|
|
|
|
* @typedef {import('../../../astro/test/test-utils').Fixture} Fixture
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function load() {
|
2023-08-01 14:55:54 +00:00
|
|
|
const mod = await import(
|
|
|
|
`./fixtures/node-middleware/dist/server/entry.mjs?dropcache=${Date.now()}`
|
|
|
|
);
|
2023-08-01 14:52:16 +00:00
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('behavior from middleware', () => {
|
|
|
|
/** @type {import('./test-utils').Fixture} */
|
2023-01-10 16:59:20 +00:00
|
|
|
let fixture;
|
2023-08-01 14:52:16 +00:00
|
|
|
let server;
|
|
|
|
|
2023-01-10 16:59:20 +00:00
|
|
|
before(async () => {
|
2023-08-01 14:52:16 +00:00
|
|
|
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
|
|
|
|
process.env.PRERENDER = false;
|
2023-01-10 16:59:20 +00:00
|
|
|
fixture = await loadFixture({
|
|
|
|
root: './fixtures/node-middleware/',
|
|
|
|
output: 'server',
|
|
|
|
adapter: nodejs({ mode: 'standalone' }),
|
|
|
|
});
|
|
|
|
await fixture.build();
|
2023-08-01 14:52:16 +00:00
|
|
|
const { startServer } = await load();
|
|
|
|
let res = startServer();
|
|
|
|
server = res.server;
|
2023-01-10 16:59:20 +00:00
|
|
|
});
|
|
|
|
|
2023-08-01 14:52:16 +00:00
|
|
|
after(async () => {
|
|
|
|
await server.stop();
|
|
|
|
await fixture.clean();
|
|
|
|
delete process.env.PRERENDER;
|
2023-08-01 14:55:54 +00:00
|
|
|
});
|
2023-08-01 14:52:16 +00:00
|
|
|
|
|
|
|
describe('404', async () => {
|
2023-01-10 16:59:20 +00:00
|
|
|
it('when mode is standalone', async () => {
|
2023-08-01 14:52:16 +00:00
|
|
|
const res = await fetch(`http://${server.host}:${server.port}/error-page`);
|
2023-01-10 16:59:20 +00:00
|
|
|
|
|
|
|
expect(res.status).to.equal(404);
|
|
|
|
|
|
|
|
const html = await res.text();
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
|
2023-08-01 14:52:16 +00:00
|
|
|
const body = $('body');
|
|
|
|
expect(body.text()).to.equal('Page does not exist');
|
2023-01-10 16:59:20 +00:00
|
|
|
});
|
2023-01-10 17:01:27 +00:00
|
|
|
});
|
|
|
|
});
|