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,11 +1,11 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import type { Plugin } from 'vite';
import { viteID } from '../dist/core/util.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Integration buildConfig hook', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -23,6 +23,7 @@ describe('Integration buildConfig hook', () => {
vite: {
plugins: [
{
name: 'my-ssr-plugin',
resolveId: {
filter: {
id: /^(astro\/app|@my-ssr)$/,
Expand All @@ -42,7 +43,7 @@ describe('Integration buildConfig hook', () => {
return `import { App } from 'astro/app';export function createExports(manifest) { return { manifest, createApp: () => new App(manifest) }; }`;
},
},
},
} satisfies Plugin,
],
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import net from 'node:net';
import { after, before, describe, it } from 'node:test';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import {
type App,
type AstroInlineConfig,
type DevServer,
type Fixture,
loadFixture,
} from './test-utils.js';

describe('API routes in SSR', () => {
const config = {
const config: AstroInlineConfig = {
root: './fixtures/ssr-api-route/',
output: 'server',
site: 'https://mysite.dev/subsite/',
Expand All @@ -20,8 +27,7 @@ describe('API routes in SSR', () => {
};

describe('Build', () => {
/** @type {import('./test-utils.js').App} */
let app;
let app: App;
before(async () => {
const fixture = await loadFixture(config);
await fixture.build();
Expand Down Expand Up @@ -94,10 +100,8 @@ describe('API routes in SSR', () => {
});

describe('Dev', () => {
/** @type {import('./test-utils.js').DevServer} */
let devServer;
/** @type {import('./test-utils.js').Fixture} */
let fixture;
let devServer: DevServer;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture(config);
devServer = await fixture.startDevServer();
Expand Down Expand Up @@ -145,7 +149,7 @@ describe('API routes in SSR', () => {
});

it('Can set multiple headers of the same type', async () => {
const response = await new Promise((resolve) => {
const response = await new Promise<string>((resolve) => {
let { port } = devServer.address;
let host = 'localhost';
let socket = new net.Socket();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('SSR Assets', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -20,7 +19,6 @@ describe('SSR Assets', () => {

it('Do not have to implement getStaticPaths', async () => {
const app = await fixture.loadTestAdapterApp();
/** @type {Set<string>} */
const assets = app.manifest.assets;
assert.equal(assets.size, 1);
assert.equal(Array.from(assets)[0].endsWith('.css'), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Dynamic pages in SSR', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
const root = './fixtures/ssr-dynamic/';
Expand Down Expand Up @@ -47,21 +46,21 @@ describe('Dynamic pages in SSR', () => {
await fixture.build();
});

async function matchRoute(path) {
async function matchRoute(path: string) {
const app = await fixture.loadTestAdapterApp();
const request = new Request('https://example.com' + path);
return app.match(request);
}

async function fetchHTML(path) {
async function fetchHTML(path: string) {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com' + path);
const response = await app.render(request);
const html = await response.text();
return html;
}

async function fetchJSON(path) {
async function fetchJSON(path: string) {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com' + path);
const response = await app.render(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('SSR with Large Array and client rendering', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Using the Partytown integration in SSR', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import assert from 'node:assert/strict';
import { after, afterEach, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import type { Plugin } from 'vite';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('Prerender', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
describe('output: "server"', () => {
describe('getStaticPaths - build calls', () => {
before(async () => {
Expand All @@ -26,7 +26,7 @@ describe('Prerender', () => {

afterEach(() => {
// reset the flag used by [...calledTwiceTest].astro between each test
globalThis.isCalledOnce = false;
(globalThis as any).isCalledOnce = false;
});

it('is only called once during build', () => {
Expand All @@ -44,16 +44,16 @@ describe('Prerender', () => {
});

describe('getStaticPaths - dev calls', () => {
let devServer;
let devServer: DevServer;

before(async () => {
globalThis.isCalledOnce = false;
(globalThis as any).isCalledOnce = false;
devServer = await fixture.startDevServer();
});

afterEach(() => {
// reset the flag used by [...calledTwiceTest].astro between each test
globalThis.isCalledOnce = false;
(globalThis as any).isCalledOnce = false;
});

after(async () => {
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Prerender', () => {

afterEach(() => {
// reset the flag used by [...calledTwiceTest].astro between each test
globalThis.isCalledOnce = false;
(globalThis as any).isCalledOnce = false;
});

it('is only called once during build', () => {
Expand All @@ -163,16 +163,16 @@ describe('Prerender', () => {
});

describe('getStaticPaths - dev calls', () => {
let devServer;
let devServer: DevServer;

before(async () => {
globalThis.isCalledOnce = false;
(globalThis as any).isCalledOnce = false;
devServer = await fixture.startDevServer();
});

afterEach(() => {
// reset the flag used by [...calledTwiceTest].astro between each test
globalThis.isCalledOnce = false;
(globalThis as any).isCalledOnce = false;
});

after(async () => {
Expand Down Expand Up @@ -238,11 +238,9 @@ describe('Prerender', () => {
});
});

/** @returns {import('vite').Plugin} */
function vitePluginRemovePrerenderExport() {
function vitePluginRemovePrerenderExport(): Plugin {
const EXTENSIONS = ['.astro', '.ts'];
/** @type {import('vite').Plugin} */
const plugin = {
const plugin: Plugin = {
name: 'remove-prerender-export',
transform(code, id) {
if (!EXTENSIONS.some((ext) => id.endsWith(ext))) return;
Expand All @@ -252,6 +250,7 @@ function vitePluginRemovePrerenderExport() {
return {
name: 'remove-prerender-export-injector',
configResolved(resolved) {
// @ts-expect-error: `resolved.plugins` is typed as `ReadonlyArray<Plugin>`
resolved.plugins.unshift(plugin);
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import type { AstroIntegration } from 'astro';
import * as cheerio from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('SSR: prerender', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -30,7 +30,6 @@ describe('SSR: prerender', () => {

it('includes prerendered pages in the asset manifest', async () => {
const app = await fixture.loadTestAdapterApp();
/** @type {Set<string>} */
const assets = app.manifest.assets;
assert.equal(assets.has('/static/index.html'), true);
});
Expand Down Expand Up @@ -112,19 +111,18 @@ describe('SSR: prerender', () => {
// is not always guaranteed to run. If we want to support this feature, we may want to only allow
// editing `route.prerender` on the `astro:build:done` hook.
describe.skip('Integrations can hook into the prerendering decision', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

const testIntegration = {
const testIntegration: AstroIntegration = {
name: 'test prerendering integration',
hooks: {
['astro:build:setup']({ pages, target }) {
if (target !== 'client') return;
// this page has `export const prerender = true`
pages.get('src/pages/static.astro').route.prerender = false;
pages.get('src/pages/static.astro')!.route.prerender = false;

// this page does not
pages.get('src/pages/not-prerendered.astro').route.prerender = true;
pages.get('src/pages/not-prerendered.astro')!.route.prerender = true;
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { before, describe, it } from 'node:test';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('SSR Preview', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -16,7 +15,6 @@ describe('SSR Preview', () => {
});

it('preview server works', async () => {
/** @type {import('./test-utils').PreviewServer} */
const previewServer = await fixture.preview();
await previewServer.stop();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('SSR renderers with static framework pages', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Using Astro.request in SSR', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -56,7 +55,7 @@ describe('Using Astro.request in SSR', () => {
const html = await response.text();
const $ = cheerioLoad(html);

const linkHref = $('link').attr('href');
const linkHref = $('link').attr('href')!;
assert.equal(linkHref.startsWith('/subpath/'), true);

request = new Request('http://example.com' + linkHref);
Expand All @@ -76,7 +75,7 @@ describe('Using Astro.request in SSR', () => {
const $ = cheerioLoad(html);

for (const el of $('script')) {
const scriptSrc = $(el).attr('src');
const scriptSrc = $(el).attr('src')!;
assert.equal(scriptSrc.startsWith('/subpath/'), true);
request = new Request('http://example.com' + scriptSrc);
response = await app.render(request);
Expand Down
Loading
Loading