Fix remaining tests
This commit is contained in:
parent
c0febd56f9
commit
e12e1e61c1
2 changed files with 44 additions and 44 deletions
|
@ -104,9 +104,10 @@ export class App {
|
||||||
if (this.#manifest.assets.has(url.pathname)) {
|
if (this.#manifest.assets.has(url.pathname)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
let hasTrailingSlash = url.pathname.endsWith('/');
|
||||||
let noBase = this.removeBase(url.pathname);
|
let noBase = this.removeBase(url.pathname);
|
||||||
let pathname: string;
|
let pathname: string;
|
||||||
if(this.#manifest.trailingSlash === 'never' && noBase === '') {
|
if(this.#manifest.trailingSlash === 'never' && noBase === '' && !hasTrailingSlash) {
|
||||||
pathname = noBase;
|
pathname = noBase;
|
||||||
} else {
|
} else {
|
||||||
pathname = prependForwardSlash(noBase);
|
pathname = prependForwardSlash(noBase);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
|
|
||||||
import { runInContainer } from '../../../dist/core/dev/index.js';
|
|
||||||
import { DevApp } from '../../../dist/core/app/dev.js';
|
import { DevApp } from '../../../dist/core/app/dev.js';
|
||||||
import { createFs, createRequestAndResponse } from '../test-utils.js';
|
import { createFs } from '../test-utils.js';
|
||||||
|
|
||||||
const root = new URL('../../fixtures/alias/', import.meta.url);
|
const root = new URL('../../fixtures/alias/', import.meta.url);
|
||||||
|
|
||||||
|
@ -26,13 +25,17 @@ describe('base configuration', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
const request = new Request(`http://localhost:8080/docs/`);
|
const request = new Request(`http://localhost:8080/docs/`);
|
||||||
const response = await app.render(request);
|
const response = await app.render(request);
|
||||||
|
|
||||||
expect(response.status).to.equal(404);
|
expect(response.status).to.equal(404);
|
||||||
|
} finally {
|
||||||
|
await app.close();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('Requests that exclude a trailing slash 200', async () => {
|
it('Requests that exclude a trailing slash 200', async () => {
|
||||||
const fs = createFs(
|
const fs = createFs(
|
||||||
{
|
{
|
||||||
'/src/pages/index.astro': `<h1>testing</h1>`,
|
'/src/pages/index.astro': `<h1>testing</h1>`,
|
||||||
|
@ -69,25 +72,23 @@ describe('base configuration', () => {
|
||||||
root
|
root
|
||||||
);
|
);
|
||||||
|
|
||||||
await runInContainer(
|
const app = new DevApp({
|
||||||
{
|
|
||||||
fs,
|
fs,
|
||||||
root,
|
root,
|
||||||
userConfig: {
|
userConfig: {
|
||||||
base: '/docs',
|
base: '/docs',
|
||||||
trailingSlash: 'never',
|
trailingSlash: 'never',
|
||||||
},
|
},
|
||||||
},
|
|
||||||
async (container) => {
|
|
||||||
const { req, res, done } = createRequestAndResponse({
|
|
||||||
method: 'GET',
|
|
||||||
url: '/docs/sub/',
|
|
||||||
});
|
});
|
||||||
container.handle(req, res);
|
|
||||||
await done;
|
try {
|
||||||
expect(res.statusCode).to.equal(404);
|
const request = new Request(`http://localhost:8080/docs/sub/`);
|
||||||
|
|
||||||
|
const response = await app.render(request);
|
||||||
|
expect(response.status).to.equal(404);
|
||||||
|
} finally {
|
||||||
|
await app.close();
|
||||||
}
|
}
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Requests that exclude a trailing slash 200', async () => {
|
it('Requests that exclude a trailing slash 200', async () => {
|
||||||
|
@ -98,25 +99,23 @@ describe('base configuration', () => {
|
||||||
root
|
root
|
||||||
);
|
);
|
||||||
|
|
||||||
await runInContainer(
|
const app = new DevApp({
|
||||||
{
|
|
||||||
fs,
|
fs,
|
||||||
root,
|
root,
|
||||||
userConfig: {
|
userConfig: {
|
||||||
base: '/docs',
|
base: '/docs',
|
||||||
trailingSlash: 'never',
|
trailingSlash: 'never',
|
||||||
},
|
},
|
||||||
},
|
|
||||||
async (container) => {
|
|
||||||
const { req, res, done } = createRequestAndResponse({
|
|
||||||
method: 'GET',
|
|
||||||
url: '/docs/sub',
|
|
||||||
});
|
});
|
||||||
container.handle(req, res);
|
|
||||||
await done;
|
try {
|
||||||
expect(res.statusCode).to.equal(200);
|
const request = new Request(`http://localhost:8080/docs/sub`);
|
||||||
|
|
||||||
|
const response = await app.render(request);
|
||||||
|
expect(response.status).to.equal(200);
|
||||||
|
} finally {
|
||||||
|
await app.close();
|
||||||
}
|
}
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue