298dbb89f2
* fix(app): refactor 404 and 500 approach * chore: refactor logic * fix: always treat error as page * test: migrate ssr-prerender-404 to node adapter * feat: merge original response metadata with error response * chore: update lockfile * chore: trigger ci * chore(lint): fix lint issue * fix: ensure merged request has proper status * fix(node): prerender test * chore: update test label * fix(node): improve 404 behavior in middleware mode * fix(vercel): improve 404 behavior * fix(netlify): improve 404 behavior * chore: update test labels * chore: force ci * chore: fix lint * fix: avoid infinite loops * test: fix failing test in Node 18 * chore: remove volta
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import nodejs from '../dist/index.js';
|
|
import { loadFixture } from './test-utils.js';
|
|
import { expect } from 'chai';
|
|
import * as cheerio from 'cheerio';
|
|
|
|
/**
|
|
* @typedef {import('../../../astro/test/test-utils').Fixture} Fixture
|
|
*/
|
|
|
|
async function load() {
|
|
const mod = await import(`./fixtures/node-middleware/dist/server/entry.mjs?dropcache=${Date.now()}`);
|
|
return mod;
|
|
}
|
|
|
|
describe('behavior from middleware', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
let server;
|
|
|
|
before(async () => {
|
|
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
|
|
process.env.PRERENDER = false;
|
|
fixture = await loadFixture({
|
|
root: './fixtures/node-middleware/',
|
|
output: 'server',
|
|
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;
|
|
})
|
|
|
|
describe('404', async () => {
|
|
it('when mode is standalone', async () => {
|
|
const res = await fetch(`http://${server.host}:${server.port}/error-page`);
|
|
|
|
expect(res.status).to.equal(404);
|
|
|
|
const html = await res.text();
|
|
const $ = cheerio.load(html);
|
|
|
|
const body = $('body');
|
|
expect(body.text()).to.equal('Page does not exist');
|
|
});
|
|
});
|
|
});
|