summaryrefslogtreecommitdiff
path: root/packages/integrations/node/test/prerender-404-500.test.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--packages/integrations/node/test/prerender-404-500.test.js (renamed from packages/integrations/node/test/prerender-404.test.js)144
1 files changed, 120 insertions, 24 deletions
diff --git a/packages/integrations/node/test/prerender-404.test.js b/packages/integrations/node/test/prerender-404-500.test.js
index 3a39a9470..8816ebe4c 100644
--- a/packages/integrations/node/test/prerender-404.test.js
+++ b/packages/integrations/node/test/prerender-404-500.test.js
@@ -9,10 +9,11 @@ import * as cheerio from 'cheerio';
async function load() {
const mod = await import(
- `./fixtures/prerender-404/dist/server/entry.mjs?dropcache=${Date.now()}`
+ `./fixtures/prerender-404-500/dist/server/entry.mjs?dropcache=${Date.now()}`
);
return mod;
}
+
describe('Prerender 404', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
@@ -24,8 +25,12 @@ describe('Prerender 404', () => {
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
+ site: 'https://test.dev/',
base: '/some-base',
- root: './fixtures/prerender-404/',
+ root: './fixtures/prerender-404-500/',
output: 'server',
adapter: nodejs({ mode: 'standalone' }),
});
@@ -51,13 +56,53 @@ describe('Prerender 404', () => {
});
it('Can handle prerendered 404', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/some-base/missing`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ const url = `http://${server.host}:${server.port}/some-base/missing`;
+ const res1 = await fetch(url);
+ const res2 = await fetch(url);
+ const res3 = await fetch(url);
+
+ expect(res1.status).to.equal(404);
+ expect(res2.status).to.equal(404);
+ expect(res3.status).to.equal(404);
+
+ const html1 = await res1.text();
+ const html2 = await res2.text();
+ const html3 = await res3.text();
+
+ expect(html1).to.equal(html2);
+ expect(html2).to.equal(html3);
+
+ const $ = cheerio.load(html1);
- expect(res.status).to.equal(404);
expect($('body').text()).to.equal('Page does not exist');
});
+
+ it(' Can handle prerendered 500 called indirectly', async () => {
+ const url = `http://${server.host}:${server.port}/some-base/fivehundred`;
+ const response1 = await fetch(url);
+ const response2 = await fetch(url);
+ const response3 = await fetch(url);
+
+ expect(response1.status).to.equal(500);
+
+ const html1 = await response1.text();
+ const html2 = await response2.text();
+ const html3 = await response3.text();
+
+ expect(html1).to.contain('Something went wrong');
+
+ expect(html1).to.equal(html2);
+ expect(html2).to.equal(html3);
+ });
+
+ it('prerendered 500 page includes expected styles', async () => {
+ const response = await fetch(`http://${server.host}:${server.port}/some-base/fivehundred`);
+ const html = await response.text();
+ const $ = cheerio.load(html);
+
+ // length will be 0 if the stylesheet does not get included
+ expect($('link[rel=stylesheet]')).to.have.a.lengthOf(1);
+ });
});
describe('Without base', async () => {
@@ -66,12 +111,16 @@ describe('Prerender 404', () => {
process.env.PRERENDER = true;
fixture = await loadFixture({
- root: './fixtures/prerender-404/',
+ // inconsequential config that differs between tests
+ // to bust cache and prevent modules and their state
+ // from being reused
+ site: 'https://test.info/',
+ root: './fixtures/prerender-404-500/',
output: 'server',
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
- const { startServer } = await await load();
+ const { startServer } = await load();
let res = startServer();
server = res.server;
});
@@ -92,11 +141,24 @@ describe('Prerender 404', () => {
});
it('Can handle prerendered 404', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/missing`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ const url = `http://${server.host}:${server.port}/some-base/missing`;
+ const res1 = await fetch(url);
+ const res2 = await fetch(url);
+ const res3 = await fetch(url);
+
+ expect(res1.status).to.equal(404);
+ expect(res2.status).to.equal(404);
+ expect(res3.status).to.equal(404);
+
+ const html1 = await res1.text();
+ const html2 = await res2.text();
+ const html3 = await res3.text();
+
+ expect(html1).to.equal(html2);
+ expect(html2).to.equal(html3);
+
+ const $ = cheerio.load(html1);
- expect(res.status).to.equal(404);
expect($('body').text()).to.equal('Page does not exist');
});
});
@@ -112,13 +174,17 @@ describe('Hybrid 404', () => {
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
process.env.PRERENDER = false;
fixture = await loadFixture({
+ // inconsequential config that differs between tests
+ // to bust cache and prevent modules and their state
+ // from being reused
+ site: 'https://test.com/',
base: '/some-base',
- root: './fixtures/prerender-404/',
+ root: './fixtures/prerender-404-500/',
output: 'hybrid',
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
- const { startServer } = await await load();
+ const { startServer } = await load();
let res = startServer();
server = res.server;
});
@@ -139,11 +205,24 @@ describe('Hybrid 404', () => {
});
it('Can handle prerendered 404', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/some-base/missing`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ const url = `http://${server.host}:${server.port}/some-base/missing`;
+ const res1 = await fetch(url);
+ const res2 = await fetch(url);
+ const res3 = await fetch(url);
+
+ expect(res1.status).to.equal(404);
+ expect(res2.status).to.equal(404);
+ expect(res3.status).to.equal(404);
+
+ const html1 = await res1.text();
+ const html2 = await res2.text();
+ const html3 = await res3.text();
+
+ expect(html1).to.equal(html2);
+ expect(html2).to.equal(html3);
+
+ const $ = cheerio.load(html1);
- expect(res.status).to.equal(404);
expect($('body').text()).to.equal('Page does not exist');
});
});
@@ -153,12 +232,16 @@ describe('Hybrid 404', () => {
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
process.env.PRERENDER = false;
fixture = await loadFixture({
- root: './fixtures/prerender-404/',
+ // inconsequential config that differs between tests
+ // to bust cache and prevent modules and their state
+ // from being reused
+ site: 'https://test.net/',
+ root: './fixtures/prerender-404-500/',
output: 'hybrid',
adapter: nodejs({ mode: 'standalone' }),
});
await fixture.build();
- const { startServer } = await await load();
+ const { startServer } = await load();
let res = startServer();
server = res.server;
});
@@ -179,11 +262,24 @@ describe('Hybrid 404', () => {
});
it('Can handle prerendered 404', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/missing`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ const url = `http://${server.host}:${server.port}/missing`;
+ const res1 = await fetch(url);
+ const res2 = await fetch(url);
+ const res3 = await fetch(url);
+
+ expect(res1.status).to.equal(404);
+ expect(res2.status).to.equal(404);
+ expect(res3.status).to.equal(404);
+
+ const html1 = await res1.text();
+ const html2 = await res2.text();
+ const html3 = await res3.text();
+
+ expect(html1).to.equal(html2);
+ expect(html2).to.equal(html3);
+
+ const $ = cheerio.load(html1);
- expect(res.status).to.equal(404);
expect($('body').text()).to.equal('Page does not exist');
});
});