Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import type { SSRManifest } from '../../../dist/core/app/types.js';
import {
getFirstForwardedValue,
validateForwardedHeaders,
} from '../../../dist/core/app/validate-headers.js';

/**
* Mirrors the URL construction logic in AstroServerApp.handleRequest so that
* the protocol and host derivation can be exercised in isolation.
*
* @param {object} opts
* @param {Record<string, string>} opts.headers - Incoming request headers
* @param {boolean} [opts.isHttps=false] - Whether Vite itself is running TLS
* @param {import('../../../dist/core/app/types.js').SSRManifest['allowedDomains']} [opts.allowedDomains]
* @param {string} [opts.requestUrl='/']
* @returns {URL}
*/
function buildDevUrl({ headers, isHttps = false, allowedDomains, requestUrl = '/' }) {
function buildDevUrl({
headers,
isHttps = false,
allowedDomains,
requestUrl = '/',
}: {
headers: Record<string, string>;
isHttps?: boolean;
allowedDomains?: SSRManifest['allowedDomains'];
requestUrl?: string;
}): URL {
const validated = validateForwardedHeaders(
getFirstForwardedValue(headers['x-forwarded-proto']),
getFirstForwardedValue(headers['x-forwarded-host']),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { addAttribute } from '../../../dist/runtime/server/render/util.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import {
Expand Down Expand Up @@ -86,8 +85,8 @@ describe('unescapeHTML', () => {
yield '<li>1</li>';
yield '<li>2</li>';
}
const result = unescapeHTML(gen());
const chunks = [];
const result = unescapeHTML(gen()) as AsyncIterable<unknown>;
const chunks: string[] = [];
for await (const chunk of result) {
chunks.push(String(chunk));
}
Expand All @@ -100,8 +99,8 @@ describe('unescapeHTML', () => {
yield '<li>a</li>';
yield '<li>b</li>';
}
const result = unescapeHTML(gen());
const chunks = [];
const result = unescapeHTML(gen()) as AsyncIterable<unknown>;
const chunks: string[] = [];
for await (const chunk of result) {
chunks.push(String(chunk));
}
Expand All @@ -110,8 +109,8 @@ describe('unescapeHTML', () => {

it('can take a Response', async () => {
const response = new Response('<p>hello</p>', { headers: { 'content-type': 'text/html' } });
const result = unescapeHTML(response);
const chunks = [];
const result = unescapeHTML(response) as AsyncIterable<unknown>;
const chunks: string[] = [];
const dec = new TextDecoder();
for await (const chunk of result) {
chunks.push(chunk instanceof Uint8Array ? dec.decode(chunk) : String(chunk));
Expand All @@ -126,8 +125,8 @@ describe('unescapeHTML', () => {
controller.close();
},
});
const result = unescapeHTML(stream);
const chunks = [];
const result = unescapeHTML(stream) as AsyncIterable<unknown>;
const chunks: string[] = [];
for await (const chunk of result) {
chunks.push(String(chunk));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { extractDirectives } from '../../../dist/runtime/server/hydration.js';
Expand Down Expand Up @@ -138,9 +137,9 @@ describe('extractDirectives', () => {
it('throws for an invalid hydration directive', () => {
assert.throws(
() => extractDirectives({ 'client:unknown': '' }, clientDirectives),
(err) => {
assert.ok(err.message.includes('invalid hydration directive'));
assert.ok(err.message.includes('client:unknown'));
(err: unknown) => {
assert.ok((err as Error).message.includes('invalid hydration directive'));
assert.ok((err as Error).message.includes('client:unknown'));
return true;
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
// @ts-check
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import type { RouteData } from '../../../dist/types/public/internal.js';
import { hasNonPrerenderedRoute } from '../../../dist/core/routing/helpers.js';

function route(overrides: Partial<RouteData>): RouteData {
return overrides as RouteData;
}

describe('hasNonPrerenderedRoute', () => {
it('returns true when a non-prerendered project page exists', () => {
const routes = [{ type: 'page', origin: 'project', prerender: false }];
const routes = [route({ type: 'page', origin: 'project', prerender: false })];
assert.equal(hasNonPrerenderedRoute(routes), true);
});

it('returns false when all project pages are prerendered', () => {
const routes = [{ type: 'page', origin: 'project', prerender: true }];
const routes = [route({ type: 'page', origin: 'project', prerender: true })];
assert.equal(hasNonPrerenderedRoute(routes), false);
});

it('excludes endpoints when includeEndpoints is false', () => {
const routes = [{ type: 'endpoint', origin: 'project', prerender: false }];
const routes = [route({ type: 'endpoint', origin: 'project', prerender: false })];
assert.equal(hasNonPrerenderedRoute(routes, { includeEndpoints: false }), false);
assert.equal(hasNonPrerenderedRoute(routes, { includeEndpoints: true }), true);
});

it('returns true for injected (external) non-prerendered pages when includeExternal is true', () => {
const routes = [{ type: 'page', origin: 'external', prerender: false }];
const routes = [route({ type: 'page', origin: 'external', prerender: false })];
assert.equal(hasNonPrerenderedRoute(routes, { includeExternal: true }), true);
assert.equal(hasNonPrerenderedRoute(routes), false);
});
Expand Down
Loading