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,15 +1,14 @@
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';

// Regression test for https://github.com/withastro/astro/issues/16036
// Using the <Picture> component on a prerendered page combined with render()
// on content collection entries caused a TDZ error during build:
// "ReferenceError: Cannot access '$$Picture' before initialization"
describe('Content collection with Picture component and render()', () => {
/** @type {import("./test-utils.js").Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/content-collection-picture-render/' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import type { CheerioAPI } from 'cheerio';
import * as cheerio from 'cheerio';
import { fixLineEndings, loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, fixLineEndings, loadFixture } from './test-utils.js';

type EntryRef = { id: string; collection: string };

type BlogEntry = {
id: string;
collection: string;
body: string;
filePath: string;
digest: string;
data: {
title: string;
banner: EntryRef;
author: EntryRef;
relatedPosts?: EntryRef[];
};
};

type BannerEntry = {
id: string;
collection: string;
filePath: string;
digest: string;
data: {
alt: string;
src: { src: string; width: number; height: number; format: string };
};
};

type AuthorEntry = {
id: string;
collection: string;
filePath: string;
digest: string;
data: { name: string; twitter: string };
};

type WelcomeData = {
welcomePost: BlogEntry;
banner: BannerEntry;
author: AuthorEntry;
relatedPosts: BlogEntry[];
};

describe('Content Collections - references', () => {
let fixture;
let devServer;
let fixture: Fixture;
let devServer: DevServer;
before(async () => {
fixture = await loadFixture({ root: './fixtures/content-collection-references/' });
});
Expand All @@ -30,7 +73,7 @@ describe('Content Collections - references', () => {
});

describe(`JSON result`, () => {
let json;
let json: WelcomeData;
before(async () => {
if (mode === 'prod') {
const rawJson = await fixture.readFile('/welcome-data.json');
Expand Down Expand Up @@ -113,7 +156,7 @@ describe('Content Collections - references', () => {
});

describe(`Render result`, () => {
let $;
let $: CheerioAPI;
before(async () => {
if (mode === 'prod') {
const html = await fixture.readFile('/welcome/index.html');
Expand All @@ -128,7 +171,7 @@ describe('Content Collections - references', () => {
it('Renders `banner` data', () => {
const banner = $('img[data-banner]');
assert.equal(banner.length, 1);
assert.ok(banner.attr('src').includes('the-future'));
assert.ok(banner.attr('src')!.includes('the-future'));
assert.equal(
banner.attr('alt'),
'Futuristic landscape with chrome buildings and blue skies',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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';

// Regression test for https://github.com/withastro/astro/issues/15575
// SVG images in content collection image() fields combined with top-level await
// caused a circular module dependency deadlock during build.
describe('Content collection with SVG image and TLA', () => {
/** @type {import("./test-utils.js").Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/content-collection-tla-svg/' });
Expand Down Expand Up @@ -43,7 +42,7 @@ describe('Content collection with SVG image and TLA', () => {

const $svg = $('.inline-svg').first();
assert.ok($svg.length, 'Expected inline SVG element to be rendered');
assert.equal($svg.prop('tagName').toLowerCase(), 'svg');
assert.equal($svg.prop('tagName')!.toLowerCase(), 'svg');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import * as assert from 'node:assert/strict';
import { after, 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 DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('Content Collections - render()', () => {
describe('Build - SSG', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -66,8 +65,7 @@ describe('Content Collections - render()', () => {
});

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

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -112,7 +110,7 @@ describe('Content Collections - render()', () => {
const html = await response.text();
const $ = cheerio.load(html);

const set = new Set();
const set = new Set<string>();

$('link[rel=stylesheet]').each((_, linkEl) => {
const href = linkEl.attribs.href;
Expand All @@ -121,7 +119,7 @@ describe('Content Collections - render()', () => {
});

$('style').each((_, styleEl) => {
const textContent = styleEl.children[0].data;
const textContent = (styleEl.children[0] as { data: string }).data;
assert.equal(set.has(textContent), false);
set.add(textContent);
});
Expand Down Expand Up @@ -151,9 +149,8 @@ describe('Content Collections - render()', () => {
});

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

before(async () => {
fixture = await loadFixture({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// @ts-check
import assert from 'node:assert/strict';
import { execSync } from 'node:child_process';
import * as fs from 'node:fs';
import { before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('Content collection type inference', () => {
/** @type {Awaited<ReturnType<typeof loadFixture>>} */
let fixture;
/** @type {string} */
let fixtureRoot;
let fixture: Fixture;
let fixtureRoot: string;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -71,8 +68,8 @@ describe('Content collection type inference', () => {
encoding: 'utf-8',
});
} catch (err) {
const stdout = /** @type {{ stdout?: string }} */ (err).stdout ?? '';
const stderr = /** @type {{ stderr?: string }} */ (err).stderr ?? '';
const stdout = (err as { stdout?: string }).stdout ?? '';
const stderr = (err as { stderr?: string }).stderr ?? '';
assert.fail(
`TypeScript type-checking failed on fixture.\n` +
`This means the content collection type inference is broken.\n\n` +
Expand Down
Loading
Loading