[ci] format

This commit is contained in:
matthewp 2023-06-09 04:56:15 +00:00 committed by fredkbot
parent bbcf69e7b8
commit 5c20476fd3
3 changed files with 22 additions and 14 deletions

View file

@ -161,7 +161,11 @@ function isRedirect(statusCode: number) {
}
export function throwIfRedirectNotAllowed(response: Response, config: AstroConfig) {
if (!isServerLikeOutput(config) && isRedirect(response.status) && !config.experimental.redirects) {
if (
!isServerLikeOutput(config) &&
isRedirect(response.status) &&
!config.experimental.redirects
) {
throw new AstroError(AstroErrorData.StaticRedirectNotAvailable);
}
}

View file

@ -1,7 +1,11 @@
import type { AstroSettings, RouteData } from '../@types/astro';
import { preload, type DevelopmentEnvironment, type ComponentPreload } from '../core/render/dev/index.js';
import { RedirectComponentInstance, routeIsRedirect } from '../core/redirects/index.js';
import {
preload,
type ComponentPreload,
type DevelopmentEnvironment,
} from '../core/render/dev/index.js';
import { getPrerenderStatus } from './metadata.js';
import { routeIsRedirect, RedirectComponentInstance } from '../core/redirects/index.js';
type GetSortedPreloadedMatchesParams = {
env: DevelopmentEnvironment;
@ -43,12 +47,12 @@ async function preloadAndSetPrerenderStatus({
matches.map(async (route) => {
const filePath = new URL(`./${route.component}`, settings.config.root);
if(routeIsRedirect(route)) {
if (routeIsRedirect(route)) {
const preloadedComponent: ComponentPreload = [[], RedirectComponentInstance];
return {
preloadedComponent,
route,
filePath
filePath,
};
}

View file

@ -86,37 +86,37 @@ describe('Astro.redirect', () => {
});
await fixture.build();
});
it('Includes the meta refresh tag in Astro.redirect pages', async () => {
const html = await fixture.readFile('/secret/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/login');
});
it('Includes the meta refresh tag in `redirect` config pages', async () => {
let html = await fixture.readFile('/one/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/');
html = await fixture.readFile('/two/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/');
html = await fixture.readFile('/three/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/');
});
it('Generates page for dynamic routes', async () => {
let html = await fixture.readFile('/blog/one/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/articles/one');
html = await fixture.readFile('/blog/two/index.html');
expect(html).to.include('http-equiv="refresh');
expect(html).to.include('url=/articles/two');
});
it('Generates redirect pages for redirects created by middleware', async () => {
let html = await fixture.readFile('/middleware-redirect/index.html');
expect(html).to.include('http-equiv="refresh');
@ -145,10 +145,10 @@ describe('Astro.redirect', () => {
after(async () => {
await devServer.stop();
});
it('Returns 301', async () => {
let res = await fixture.fetch('/one', {
redirect: 'manual'
redirect: 'manual',
});
expect(res.status).to.equal(301);
});