aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/node/test/prerender.test.js
diff options
context:
space:
mode:
authorGravatar Happydev <81974850+MoustaphaDev@users.noreply.github.com> 2023-05-15 12:53:34 +0000
committerGravatar GitHub <noreply@github.com> 2023-05-15 08:53:34 -0400
commit2fa052f82868be804b4e2d89a1d94c722f049db8 (patch)
tree16b7eada0e18a0fd374c1a8f6693ab050f27606a /packages/integrations/node/test/prerender.test.js
parent219e1710aa680fdb645956c6eb3238181aba0175 (diff)
downloadastro-2fa052f82868be804b4e2d89a1d94c722f049db8.tar.gz
astro-2fa052f82868be804b4e2d89a1d94c722f049db8.tar.zst
astro-2fa052f82868be804b4e2d89a1d94c722f049db8.zip
Fix double prepended forward slash in certain cases (#7091)
* test: add test with no base * fix: don't always prepend a forward slash * chore: changeset * `'/' + base` ------> `prependForwardSlash(base)`
Diffstat (limited to 'packages/integrations/node/test/prerender.test.js')
-rw-r--r--packages/integrations/node/test/prerender.test.js133
1 files changed, 90 insertions, 43 deletions
diff --git a/packages/integrations/node/test/prerender.test.js b/packages/integrations/node/test/prerender.test.js
index 0ef316ed6..e72e754e2 100644
--- a/packages/integrations/node/test/prerender.test.js
+++ b/packages/integrations/node/test/prerender.test.js
@@ -9,61 +9,108 @@ describe('Prerendering', () => {
let fixture;
let server;
- before(async () => {
- process.env.ASTRO_NODE_AUTOSTART = 'disabled';
- fixture = await loadFixture({
- base: '/some-base',
- root: './fixtures/prerender/',
- output: 'server',
- adapter: nodejs({ mode: 'standalone' }),
- });
- await fixture.build();
- const { startServer } = await await load();
- let res = startServer();
- server = res.server;
- });
-
- after(async () => {
- await server.stop();
- });
-
async function load() {
const mod = await import('./fixtures/prerender/dist/server/entry.mjs');
return mod;
}
- it('Can render SSR route', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/some-base/one`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ describe('With base', () => {
+ before(async () => {
+ process.env.ASTRO_NODE_AUTOSTART = 'disabled';
+ fixture = await loadFixture({
+ base: '/some-base',
+ root: './fixtures/prerender/',
+ output: 'server',
+ adapter: nodejs({ mode: 'standalone' }),
+ });
+ await fixture.build();
+ const { startServer } = await await load();
+ let res = startServer();
+ server = res.server;
+ });
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('One');
- });
+ after(async () => {
+ await server.stop();
+ });
- it('Can render prerendered route', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/some-base/two`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ it('Can render SSR route', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/some-base/one`);
+ const html = await res.text();
+ const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
- });
+ expect(res.status).to.equal(200);
+ expect($('h1').text()).to.equal('One');
+ });
+
+ it('Can render prerendered route', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/some-base/two`);
+ const html = await res.text();
+ const $ = cheerio.load(html);
+
+ expect(res.status).to.equal(200);
+ expect($('h1').text()).to.equal('Two');
+ });
- it('Can render prerendered route with query params', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/some-base/two/?foo=bar`);
- const html = await res.text();
- const $ = cheerio.load(html);
+ it('Can render prerendered route with query params', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/some-base/two/?foo=bar`);
+ const html = await res.text();
+ const $ = cheerio.load(html);
- expect(res.status).to.equal(200);
- expect($('h1').text()).to.equal('Two');
+ expect(res.status).to.equal(200);
+ expect($('h1').text()).to.equal('Two');
+ });
+
+ it('Omitting the trailing slash results in a redirect that includes the base', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/some-base/two`, {
+ redirect: 'manual',
+ });
+ expect(res.status).to.equal(301);
+ expect(res.headers.get('location')).to.equal('/some-base/two/');
+ });
});
+ describe('Without base', () => {
+ before(async () => {
+ process.env.ASTRO_NODE_AUTOSTART = 'disabled';
+ fixture = await loadFixture({
+ root: './fixtures/prerender/',
+ output: 'server',
+ adapter: nodejs({ mode: 'standalone' }),
+ });
+ await fixture.build();
+ const { startServer } = await await load();
+ let res = startServer();
+ server = res.server;
+ });
+
+ after(async () => {
+ await server.stop();
+ });
+
+ it('Can render SSR route', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/one`);
+ const html = await res.text();
+ const $ = cheerio.load(html);
+
+ expect(res.status).to.equal(200);
+ expect($('h1').text()).to.equal('One');
+ });
+
+ it('Can render prerendered route', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/two`);
+ const html = await res.text();
+ const $ = cheerio.load(html);
+
+ expect(res.status).to.equal(200);
+ expect($('h1').text()).to.equal('Two');
+ });
+
+ it('Can render prerendered route with query params', async () => {
+ const res = await fetch(`http://${server.host}:${server.port}/two/?foo=bar`);
+ const html = await res.text();
+ const $ = cheerio.load(html);
- it('Omitting the trailing slash results in a redirect that includes the base', async () => {
- const res = await fetch(`http://${server.host}:${server.port}/some-base/two`, {
- redirect: 'manual',
+ expect(res.status).to.equal(200);
+ expect($('h1').text()).to.equal('Two');
});
- expect(res.status).to.equal(301);
- expect(res.headers.get('location')).to.equal('/some-base/two/');
});
});