import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; import { expect } from 'chai'; import * as cheerio from 'cheerio'; import { fetch } from 'undici'; /** * @typedef {import('../../../astro/test/test-utils').Fixture} Fixture */ async function load() { const mod = await import(`./fixtures/prerender/dist/server/entry.mjs?dropcache=${Date.now()}`); return mod; } describe('Prerendering', () => { /** @type {import('./test-utils').Fixture} */ let fixture; let server; describe('With base', async () => { before(async () => { process.env.ASTRO_NODE_AUTOSTART = 'disabled'; process.env.PRERENDER = true; fixture = await loadFixture({ base: '/some-base', root: './fixtures/prerender/', 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; }); 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('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 redirect and 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'); }); 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'); }); 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', async () => { before(async () => { process.env.ASTRO_NODE_AUTOSTART = 'disabled'; process.env.PRERENDER = true; 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(); await fixture.clean(); delete process.env.PRERENDER; }); 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 redirect and query params', async () => { const res = await fetch(`http://${server.host}:${server.port}/two?foo=bar`); 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); expect(res.status).to.equal(200); expect($('h1').text()).to.equal('Two'); }); }); }); describe('Hybrid rendering', () => { /** @type {import('./test-utils').Fixture} */ let fixture; let server; describe('With base', async () => { before(async () => { process.env.ASTRO_NODE_AUTOSTART = 'disabled'; process.env.PRERENDER = false; fixture = await loadFixture({ base: '/some-base', root: './fixtures/prerender/', output: 'hybrid', adapter: nodejs({ mode: 'standalone' }), }); await fixture.build(); const { startServer } = await await load(); let res = startServer(); server = res.server; }); after(async () => { await server.stop(); await fixture.clean(); delete process.env.PRERENDER; }); it('Can render SSR 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', 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('One'); }); it('Can render prerendered route with redirect and query params', async () => { const res = await fetch(`http://${server.host}:${server.port}/some-base/one?foo=bar`); 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 with query params', async () => { const res = await fetch(`http://${server.host}:${server.port}/some-base/one/?foo=bar`); const html = await res.text(); const $ = cheerio.load(html); expect(res.status).to.equal(200); expect($('h1').text()).to.equal('One'); }); 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/one`, { redirect: 'manual', }); expect(res.status).to.equal(301); expect(res.headers.get('location')).to.equal('/some-base/one/'); }); }); describe('Without base', async () => { before(async () => { process.env.ASTRO_NODE_AUTOSTART = 'disabled'; process.env.PRERENDER = false; fixture = await loadFixture({ root: './fixtures/prerender/', output: 'hybrid', adapter: nodejs({ mode: 'standalone' }), }); await fixture.build(); const { startServer } = await await load(); let res = startServer(); server = res.server; }); after(async () => { await server.stop(); await fixture.clean(); delete process.env.PRERENDER; }); it('Can render SSR 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', 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 with redirect and query params', async () => { const res = await fetch(`http://${server.host}:${server.port}/one?foo=bar`); 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 with query params', async () => { const res = await fetch(`http://${server.host}:${server.port}/one/?foo=bar`); const html = await res.text(); const $ = cheerio.load(html); expect(res.status).to.equal(200); expect($('h1').text()).to.equal('One'); }); }); }); -transform Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/.gitpod (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-04-26[ci] formatGravatar matthewp 1-1/+1
2022-04-26fix(vercel): `trailingSlash` fix for non-html pages (#3185)Gravatar Juan Martín Seery 2-29/+42
2022-04-26Prevent watcher from running during the build (#3207)Gravatar Matthew Phillips 2-0/+9
2022-04-26Fix lockfile (#3210)Gravatar Juan Martín Seery 1-6/+0
2022-04-26Add missing is:raw in AstroBuiltinAttributes (#3209)Gravatar Erika 2-0/+6
2022-04-26Feat: support `astro add` without npm installing (#3183)Gravatar Ben Holmes 6-30/+49
2022-04-26Add Astro attributes to svg elements (#3205)Gravatar Erika 2-1/+9
2022-04-26[ci] formatGravatar bholmesdev 2-9/+9
2022-04-26Feat: `create astro` add install step (#3190)Gravatar Ben Holmes 7-162/+299
2022-04-26[ci] collect statsGravatar FredKSchott 1-0/+1
2022-04-25fix(markdown): file.url fixes (#3198)Gravatar Juan Martín Seery 11-10/+149
2022-04-25[ci] collect statsGravatar FredKSchott 1-0/+1
2022-04-24add vite to licenseGravatar Fred K. Schott 2-24/+29
2022-04-24feat(markdown): Improved types (#3191)Gravatar Juan Martín Seery 3-6/+47
2022-04-24[ci] collect statsGravatar FredKSchott 1-0/+1
2022-04-23[ci] collect statsGravatar FredKSchott 1-0/+1