0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

[ci] format

This commit is contained in:
lilnasy 2023-09-28 17:19:21 +00:00 committed by astrobot-houston
parent cfd895d877
commit c4c616c0a5
2 changed files with 26 additions and 27 deletions

View file

@ -221,19 +221,19 @@ export async function handleRoute({
if (response.status === 404 && has404Route(manifestData)) { if (response.status === 404 && has404Route(manifestData)) {
const fourOhFourRoute = await matchRoute('/404', manifestData, pipeline); const fourOhFourRoute = await matchRoute('/404', manifestData, pipeline);
if (fourOhFourRoute?.route !== options.route) if (fourOhFourRoute?.route !== options.route)
return handleRoute({ return handleRoute({
...options, ...options,
matchedRoute: fourOhFourRoute, matchedRoute: fourOhFourRoute,
url: new URL(pathname, url), url: new URL(pathname, url),
status: 404, status: 404,
body, body,
origin, origin,
pipeline, pipeline,
manifestData, manifestData,
incomingRequest, incomingRequest,
incomingResponse, incomingResponse,
manifest, manifest,
}); });
} }
if (route.type === 'endpoint') { if (route.type === 'endpoint') {
await writeWebResponse(incomingResponse, response); await writeWebResponse(incomingResponse, response);

View file

@ -1,19 +1,19 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
for (const caseNumber of [ 1, 2, 3, 4 ]) { for (const caseNumber of [1, 2, 3, 4]) {
describe(`Custom 404 with implicit rerouting - Case #${caseNumber}`, () => { describe(`Custom 404 with implicit rerouting - Case #${caseNumber}`, () => {
/** @type Awaited<ReturnType<typeof loadFixture>> */ /** @type Awaited<ReturnType<typeof loadFixture>> */
let fixture; let fixture;
/** @type Awaited<ReturnType<typeof fixture['startDevServer']>> */ /** @type Awaited<ReturnType<typeof fixture['startDevServer']>> */
let devServer let devServer;
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: `./fixtures/custom-404-loop-case-${caseNumber}/`, root: `./fixtures/custom-404-loop-case-${caseNumber}/`,
site: 'http://example.com' site: 'http://example.com',
}); });
devServer = await fixture.startDevServer(); devServer = await fixture.startDevServer();
}); });
@ -31,17 +31,16 @@ for (const caseNumber of [ 1, 2, 3, 4 ]) {
expect(result).to.not.equal(timeout); expect(result).to.not.equal(timeout);
expect(result.status).to.equal(404); expect(result.status).to.equal(404);
}); });
after(async () => { after(async () => {
await devServer.stop(); await devServer.stop();
}); });
}); });
} }
/***** UTILITY FUNCTIONS *****/ /***** UTILITY FUNCTIONS *****/
const timeout = Symbol("timeout") const timeout = Symbol('timeout');
/** @template Res */ /** @template Res */
function withTimeout( function withTimeout(
@ -51,7 +50,7 @@ function withTimeout(
timeLimit timeLimit
) { ) {
/** @type Promise<typeof timeout> */ /** @type Promise<typeof timeout> */
const timeoutPromise = new Promise(resolve => setTimeout(() => resolve(timeout), timeLimit)) const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(timeout), timeLimit));
return Promise.race([ responsePromise, timeoutPromise ]); return Promise.race([responsePromise, timeoutPromise]);
} }