17c02925c5
* wip: config migration * fix: formatting * refactor: projectRoot -> root * refactor: pageUrlFormat -> format * refactor: buildOptions.site -> site * refactor: public -> publicDir * refactor: dist -> outDir * refactor: styleOptions -> style * fix: some dist tests -> outDir * refactor: remove legacyBuild (with TODOs) * refactor: more legacyBuild cleanup * refactor: server host and port * fix: remove experimentalStaticBuild CLI flag * refactor: src -> srcDir * refactor: devOptions.trailing -> trailing * refactor: remove sitemap + related flags * refactor: experimentalSSR -> experimental.ssr * fix: last devOptions * refactor: drafts -> markdown.drafts * fix: TS error on port as const * refactor: remove pages * refactor: more --project-root updates * refactor: markdownOptions -> markdown * fix: remaining type errors * feat: update AstroUserConfig * refactor: update CLI flag mapper + server mapper * fix: loadFixture projectRoot * fix: merge CLI flags before validating / transforming * wip: attempt to fix bad createRouteManifest config * refactor: combine config.base and config.site * fix: skip route manifest test for now * fix: site and base handling * refactor: update failing config testes * fix: build failure * feat: update config types with migration help * chore: update types * fix(deno): update deno fixture * chore: remove config migration logic * chore: remove logLevel * chore: clean-up config types * chore: update config warning * chore: add changeset * Sitemap Integration (#2965) * feat: add sitemap filter config option * feat: add canonicalURL sitemap config option * docs: update sitemap README * fix: update for new config * fix: filter not being applied * chore: changeset Co-authored-by: bholmesdev <hey@bholmes.dev> * fred pass * fix: Astro.resolve typo * fix: public => publicDir Co-authored-by: bholmesdev <hey@bholmes.dev> Co-authored-by: Fred K. Schott <fkschott@gmail.com>
425 lines
12 KiB
JavaScript
425 lines
12 KiB
JavaScript
import { expect } from 'chai';
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
describe('Preview Routing', () => {
|
|
describe('build format: directory', () => {
|
|
describe('Subpath without trailing slash and trailingSlash: never', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4000/', import.meta.url),
|
|
build: {
|
|
format: 'directory',
|
|
},
|
|
trailingSlash: 'never',
|
|
server: {
|
|
port: 4000,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath root with trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog/');
|
|
expect(response.status).to.equal(200);
|
|
expect(response.redirected).to.equal(false);
|
|
});
|
|
|
|
it('404 when loading subpath root without trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('404 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
|
|
describe('Subpath without trailing slash and trailingSlash: always', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4001/', import.meta.url),
|
|
trailingSlash: 'always',
|
|
server: {
|
|
port: 4001,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath root with trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading subpath root without trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading another page with subpath not used', async () => {
|
|
const response = await fixture.fetch('/blog/another');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
|
|
describe('Subpath without trailing slash and trailingSlash: ignore', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4002/', import.meta.url),
|
|
trailingSlash: 'ignore',
|
|
server: {
|
|
port: 4002,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath root with trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading subpath root without trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('200 when loading another page with subpath not used', async () => {
|
|
const response = await fixture.fetch('/blog/another');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('build format: file', () => {
|
|
describe('Subpath without trailing slash and trailingSlash: never', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4003/', import.meta.url),
|
|
build: {
|
|
format: 'file',
|
|
},
|
|
trailingSlash: 'never',
|
|
server: {
|
|
port: 4003,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath root with trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog/');
|
|
expect(response.status).to.equal(200);
|
|
expect(response.redirected).to.equal(false);
|
|
});
|
|
|
|
it('404 when loading subpath root without trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('404 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
|
|
describe('Subpath without trailing slash and trailingSlash: always', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4004/', import.meta.url),
|
|
build: {
|
|
format: 'file',
|
|
},
|
|
trailingSlash: 'always',
|
|
server: {
|
|
port: 4004,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath root with trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading subpath root without trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading another page with subpath not used', async () => {
|
|
const response = await fixture.fetch('/blog/another');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
|
|
describe('Subpath without trailing slash and trailingSlash: ignore', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4005/', import.meta.url),
|
|
build: {
|
|
format: 'file',
|
|
},
|
|
trailingSlash: 'ignore',
|
|
server: {
|
|
port: 4005,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath root with trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading subpath root without trailing slash', async () => {
|
|
const response = await fixture.fetch('/blog');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('200 when loading another page with subpath not used', async () => {
|
|
const response = await fixture.fetch('/blog/another');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1/');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
|
|
describe('Exact file path', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
/** @type {import('./test-utils').PreviewServer} */
|
|
let previewServer;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/with-subpath-no-trailing-slash/',
|
|
base: '/blog',
|
|
outDir: new URL('./fixtures/with-subpath-no-trailing-slash/dist-4006/', import.meta.url),
|
|
build: {
|
|
format: 'file',
|
|
},
|
|
trailingSlash: 'ignore',
|
|
server: {
|
|
port: 4006,
|
|
},
|
|
});
|
|
await fixture.build();
|
|
previewServer = await fixture.preview();
|
|
});
|
|
|
|
after(async () => {
|
|
await previewServer.stop();
|
|
});
|
|
|
|
it('404 when loading /', async () => {
|
|
const response = await fixture.fetch('/');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
|
|
it('200 when loading subpath with index.html', async () => {
|
|
const response = await fixture.fetch('/blog/index.html');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('200 when loading another page with subpath used', async () => {
|
|
const response = await fixture.fetch('/blog/another.html');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('200 when loading dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/1.html');
|
|
expect(response.status).to.equal(200);
|
|
});
|
|
|
|
it('404 when loading invalid dynamic route', async () => {
|
|
const response = await fixture.fetch('/blog/2.html');
|
|
expect(response.status).to.equal(404);
|
|
});
|
|
});
|
|
});
|
|
});
|