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,13 +1,12 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('scopedStyleStrategy', () => {
describe('scopedStyleStrategy: "where"', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let stylesheet;
let fixture: Fixture;
let stylesheet: string;

before(async () => {
fixture = await loadFixture({
Expand All @@ -21,7 +20,7 @@ describe('scopedStyleStrategy', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const $link = $('link[rel=stylesheet]');
const href = $link.attr('href');
const href = $link.attr('href')!;
stylesheet = await fixture.readFile(href);
});

Expand All @@ -35,9 +34,8 @@ describe('scopedStyleStrategy', () => {
});

describe('scopedStyleStrategy: "class"', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let stylesheet;
let fixture: Fixture;
let stylesheet: string;

before(async () => {
fixture = await loadFixture({
Expand All @@ -51,7 +49,7 @@ describe('scopedStyleStrategy', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const $link = $('link[rel=stylesheet]');
const href = $link.attr('href');
const href = $link.attr('href')!;
stylesheet = await fixture.readFile(href);
});

Expand All @@ -65,9 +63,8 @@ describe('scopedStyleStrategy', () => {
});

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

before(async () => {
fixture = await loadFixture({
Expand All @@ -80,7 +77,7 @@ describe('scopedStyleStrategy', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const $link = $('link[rel=stylesheet]');
const href = $link.attr('href');
const href = $link.attr('href')!;
stylesheet = await fixture.readFile(href);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import * as cheerio from 'cheerio';
import { ServerOnlyModule } from '../dist/core/errors/errors-data.js';
import { AstroError } from '../dist/core/errors/index.js';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type App, type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('astro:config/client', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;

describe('in dev', async () => {
before(async () => {
Expand Down Expand Up @@ -90,8 +89,7 @@ describe('astro:config/client', () => {
});

describe('astro:config/client in a client script', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

describe('when build', () => {
before(async () => {
Expand All @@ -110,10 +108,9 @@ describe('astro:config/client in a client script', () => {
});

describe('astro:config/server', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let devServer;
let app;
let fixture: Fixture;
let devServer: DevServer;
let app: App;

describe('when build', () => {
before(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
// @ts-check

import { describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';
import { type App, type Fixture, loadFixture } from './test-utils.js';
import testAdapter, { selfTestAdapter } from './test-adapter.js';
import assert from 'node:assert/strict';
import fakeAdapter from './fixtures/server-entry/fake-adapter/index.js';
import { existsSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import type { AstroIntegration } from 'astro';

type FakeAdapter = (
options:
| { type: 'rollupInput'; shape: 'string' | 'object' | 'array' }
| { type: 'serverEntrypoint' },
) => AstroIntegration;

const fakeAdapter: FakeAdapter = await (async () => {
const importPath: string = './fixtures/server-entry/fake-adapter/index.js';
const mod = await import(importPath);
return mod.default;
})();

describe('Server entry', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let app;
let fixture: Fixture;
let app: App;

it('should load the custom entry when using legacy entrypoint', async () => {
fixture = await loadFixture({
Expand All @@ -23,7 +32,7 @@ describe('Server entry', () => {
},
});

await fixture.build({});
await fixture.build();
app = await fixture.loadTestAdapterApp(false);

const request = new Request('http://example.com/');
Expand All @@ -41,7 +50,7 @@ describe('Server entry', () => {
},
});

await fixture.build({});
await fixture.build();
app = await fixture.loadSelfAdapterApp(false);

const request = new Request('http://example.com/');
Expand All @@ -59,7 +68,7 @@ describe('Server entry', () => {
},
});

await fixture.build({});
await fixture.build();

assert.ok(existsSync(fileURLToPath(new URL('server/custom.mjs', fixture.config.outDir))));
});
Expand All @@ -74,7 +83,7 @@ describe('Server entry', () => {
},
});

await fixture.build({});
await fixture.build();

assert.ok(existsSync(fileURLToPath(new URL('server/custom.mjs', fixture.config.outDir))));
});
Expand All @@ -89,7 +98,7 @@ describe('Server entry', () => {
},
});

await fixture.build({});
await fixture.build();

assert.ok(existsSync(fileURLToPath(new URL('server/custom.mjs', fixture.config.outDir))));
});
Expand All @@ -104,7 +113,7 @@ describe('Server entry', () => {
},
});

await fixture.build({});
await fixture.build();

assert.ok(existsSync(fileURLToPath(new URL('server/custom.mjs', fixture.config.outDir))));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import * as cheerio from 'cheerio';

import { encryptString } from '../dist/core/encryption.js';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

// Helper to create encryption key from test key string
async function createKeyFromString(keyString) {
async function createKeyFromString(keyString: string) {
const binaryString = atob(keyString);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
Expand All @@ -30,8 +30,7 @@ async function getEncryptedComponentExport(

describe('Server islands', () => {
describe('SSR', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/server-islands/ssr',
Expand All @@ -43,7 +42,7 @@ describe('Server islands', () => {
});

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

before(async () => {
process.env.ASTRO_KEY = 'eKBaVEuI7YjfanEXHuJe/pwZKKt3LkAHeMxvTU7aR0M=';
Expand Down Expand Up @@ -167,7 +166,7 @@ describe('Server islands', () => {
const res = await fixture.fetch('/test');
assert.equal(res.status, 200);
const html = await res.text();
const fetchMatch = html.match(/fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/);
const fetchMatch = /fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/.exec(html)!;
assert.equal(fetchMatch.length, 2, 'should include props in the query string');
assert.equal(fetchMatch[1], '', 'should not include encrypted empty props');
});
Expand All @@ -176,7 +175,7 @@ describe('Server islands', () => {
const res = await fixture.fetch('/fragment');
assert.equal(res.status, 200);
const html = await res.text();
const fetchMatch = html.match(/fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/);
const fetchMatch = /fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/.exec(html)!;
assert.equal(fetchMatch.length, 2, 'should include props in the query string');
assert.equal(fetchMatch[1], '', 'should not include encrypted empty props');
});
Expand All @@ -185,7 +184,7 @@ describe('Server islands', () => {
const res = await fixture.fetch('/fragment');
assert.equal(res.status, 200);
const html = await res.text();
const fetchMatch = html.match(/fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/);
const fetchMatch = /fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/.exec(html)!;
assert.equal(fetchMatch.length, 2, 'should include props in the query string');
assert.equal(fetchMatch[1], '', 'should not include encrypted empty props');
});
Expand All @@ -195,7 +194,7 @@ describe('Server islands', () => {
assert.equal(res.status, 200);
const html = await res.text();
// Extract the island fetch URL from the page
const urlMatch = html.match(/fetch\('(\/_server-islands\/Wrapper\?[^']+)'/);
const urlMatch = /fetch\('(\/_server-islands\/Wrapper\?[^']+)'/.exec(html)!;
assert.ok(urlMatch, 'should have a server island fetch URL');
const islandRes = await fixture.fetch(urlMatch[1]);
assert.equal(islandRes.status, 200);
Expand Down Expand Up @@ -345,16 +344,15 @@ describe('Server islands', () => {
const res = await app.render(request);
assert.equal(res.status, 200);
const html = await res.text();
const fetchMatch = html.match(/fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/);
const fetchMatch = /fetch\('\/_server-islands\/Island\?[^']*p=([^&']*)/.exec(html)!;
assert.equal(fetchMatch.length, 2, 'should include props in the query string');
assert.equal(fetchMatch[1], '', 'should not include encrypted empty props');
});
});
});

describe('Hybrid mode', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/server-islands/hybrid',
Expand Down Expand Up @@ -384,7 +382,7 @@ describe('Server islands', () => {

const $ = cheerio.load(html);
const serverIslandScript = $('script').filter((_, el) =>
$(el).html().trim().startsWith('async function replaceServerIsland'),
($(el).html() ?? '').trim().startsWith('async function replaceServerIsland'),
);
assert.equal(
serverIslandScript.length,
Expand All @@ -411,7 +409,7 @@ describe('Server islands', () => {
const res = await devFixture.fetch('/');
assert.equal(res.status, 200);
const html = await res.text();
const fetchMatch = /fetch\('(\/_server-islands\/Island[^']*)/.exec(html);
const fetchMatch = /fetch\('(\/_server-islands\/Island[^']*)/.exec(html)!;
assert.ok(fetchMatch, 'should have a server island fetch URL');
const islandRes = await devFixture.fetch(fetchMatch[1]);
assert.equal(
Expand All @@ -425,7 +423,7 @@ describe('Server islands', () => {
});

describe('with no adapter', () => {
let devServer;
let devServer: DevServer;

it('Errors during the build', async () => {
try {
Expand All @@ -434,7 +432,10 @@ describe('Server islands', () => {
});
assert.equal(true, false, 'should not have succeeded');
} catch (err) {
assert.equal(err.title, 'Cannot use Server Islands without an adapter.');
assert.equal(
(err as { title: string }).title,
'Cannot use Server Islands without an adapter.',
);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Slots: Preact', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/slots-preact/' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Slots: React', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/slots-react/' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Slots: Solid', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/slots-solid/' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Slots: Svelte', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/slots-svelte/' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Slots: Vue', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/slots-vue/' });
Expand Down
Loading
Loading