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,12 +1,11 @@
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('build.format', () => {
describe('directory', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/page-format/',
Expand All @@ -27,8 +26,7 @@ describe('build.format', () => {
});

describe('file', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/page-format/',
Expand Down Expand Up @@ -64,8 +62,7 @@ describe('build.format', () => {
});

describe('preserve - i18n', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
base: '/test',
Expand All @@ -91,8 +88,7 @@ describe('build.format', () => {
});

describe('preserve - i18n', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
base: '/test',
Expand Down
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 { load as cheerioLoad } from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

// Asset bundling
describe('Page-level styles', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
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('Component parallelization', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -17,10 +17,8 @@ describe('Component parallelization', () => {
let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html);

const startTimes = Array.from($('.start')).map((element) => Number(element.children[0].data));
const finishTimes = Array.from($('.finished')).map((element) =>
Number(element.children[0].data),
);
const startTimes = Array.from($('.start')).map((element) => Number($(element).text()));
const finishTimes = Array.from($('.finished')).map((element) => Number($(element).text()));

const renderStartWithin = Math.max(...startTimes) - Math.min(...startTimes);
assert.equal(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

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

before(async () => {
fixture = await loadFixture({
Expand All @@ -14,8 +13,7 @@ describe('Partials', () => {
});

describe('dev', () => {
/** @type {import('./test-utils.js').DevServer} */
let devServer;
let devServer: DevServer;

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

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

before(async () => {
fixture = await loadFixture({
Expand All @@ -14,8 +13,8 @@ describe('passthroughImageService', () => {
});

describe('dev', () => {
let $;
let devServer;
let $: cheerio.CheerioAPI;
let devServer: DevServer;

before(async () => {
devServer = await fixture.startDevServer();
Expand All @@ -35,20 +34,20 @@ describe('passthroughImageService', () => {

it('serves SVG logo with correct content type', async () => {
const $img = $('#logo img');
const src = $img.attr('src');
const src = $img.attr('src')!;

const response = await fixture.fetch(src);
const contentType = response.headers.get('content-type');

assert.ok(
contentType.includes('image/svg+xml'),
contentType!.includes('image/svg+xml'),
`Expected SVG content type, got: ${contentType}`,
);
});
});

describe('build', () => {
let $;
let $: cheerio.CheerioAPI;

before(async () => {
await fixture.build();
Expand Down Expand Up @@ -77,7 +76,7 @@ describe('passthroughImageService', () => {

it('preserves original format', () => {
const $img = $('#image img');
const src = $img.attr('src');
const src = $img.attr('src')!;
assert.ok(src.endsWith('.jpg'), `Should preserve jpg format, got: ${src}`);
});
});
Expand All @@ -95,7 +94,7 @@ describe('passthroughImageService', () => {

it('preserves original format', () => {
const $img = $('#picture img');
const src = $img.attr('src');
const src = $img.attr('src')!;
assert.ok(src.endsWith('.jpg'), `Should preserve jpg format, got: ${src}`);
});
});
Expand All @@ -108,7 +107,7 @@ describe('passthroughImageService', () => {

it('preserves SVG format', () => {
const $img = $('#logo img');
const src = $img.attr('src');
const src = $img.attr('src')!;
assert.ok(src.endsWith('.svg'), `Should preserve svg format, got: ${src}`);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import eol from 'eol';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

describe('PostCSS', () => {
let fixture;
let bundledCSS;
let fixture: Fixture;
let bundledCSS: string;
before(
async () => {
fixture = await loadFixture({
Expand All @@ -19,7 +19,7 @@ describe('PostCSS', () => {
// get bundled CSS (will be hashed, hence DOM query)
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const bundledCSSHREF = $('link[rel=stylesheet][href^=/_astro/]').attr('href');
const bundledCSSHREF = $('link[rel=stylesheet][href^=/_astro/]').attr('href')!;
bundledCSS = (await fixture.readFile(bundledCSSHREF.replace(/^\/?/, '/')))
.replace(/\s/g, '')
.replace('/n', '');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type DevServer, type Fixture, loadFixture } from './test-utils.js';

describe('Preact compat component', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -14,8 +13,7 @@ describe('Preact compat component', () => {
});

describe('Development', () => {
/** @type {import('./test-utils.js').DevServer} */
let devServer;
let devServer: DevServer;

before(async () => {
devServer = await fixture.startDevServer();
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 * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

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

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -90,14 +89,17 @@ describe('Preact component', () => {

// Grab the imports
const exp = /import\("(.+?)"\)/g;
let match, componentUrl;
let match: RegExpExecArray | null;
let componentUrl: string | undefined;
while ((match = exp.exec(html))) {
if (match[1].includes('PragmaComment.js')) {
componentUrl = match[1];
break;
}
}
// @ts-expect-error: this test is currently skipped and its type isn't worth fixing right now
const component = await fixture.fetch(componentUrl).then((res) => res.text());
// @ts-expect-error: this test is currently skipped and its type isn't worth fixing right now
const jsxRuntime = component.imports.filter((i) => i.specifier.includes('jsx-runtime'));

// test 1: preact/jsx-runtime is used for the component
Expand All @@ -109,8 +111,8 @@ describe('Preact component', () => {
const $ = cheerio.load(html);
assert.equal($('.preact-signal').length, 2);

const sigs1Raw = $($('astro-island')[0]).attr('data-preact-signals');
const sigs2Raw = $($('astro-island')[1]).attr('data-preact-signals');
const sigs1Raw = $($('astro-island')[0]).attr('data-preact-signals')!;
const sigs2Raw = $($('astro-island')[1]).attr('data-preact-signals')!;

assert.notEqual(sigs1Raw, undefined);
assert.notEqual(sigs2Raw, undefined);
Expand All @@ -128,7 +130,7 @@ describe('Preact component', () => {
const element = $('.preact-signal-array');
assert.equal(element.length, 1);

const sigs1Raw = $($('astro-island')[2]).attr('data-preact-signals');
const sigs1Raw = $($('astro-island')[2]).attr('data-preact-signals')!;

const sigs1 = JSON.parse(sigs1Raw);

Expand All @@ -150,7 +152,7 @@ describe('Preact component', () => {
const element = $('.preact-signal-object');
assert.equal(element.length, 1);

const sigs1Raw = $($('astro-island')[3]).attr('data-preact-signals');
const sigs1Raw = $($('astro-island')[3]).attr('data-preact-signals')!;

const sigs1 = JSON.parse(sigs1Raw);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import { before, describe, it } from 'node:test';
import { AstroLogger } from '../dist/core/logger/core.js';
import { loadFixture } from './test-utils.js';
import { type AstroLogMessage, AstroLogger } from '../dist/core/logger/core.js';
import { type Fixture, loadFixture } from './test-utils.js';

/**
* Dynamic vs dynamic duplication should warn by default and succeed.
Expand All @@ -11,23 +11,26 @@ import { loadFixture } from './test-utils.js';

describe('Prerender conflicts', () => {
describe('dynamic vs dynamic', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/prerender-conflict-dynamic-dynamic/' });
});

it('warns by default and succeeds', async () => {
const logs = [];
await fixture.build({
logger: new AstroLogger({
level: 'warn',
destination: {
write(chunk) {
logs.push(chunk);
},
const logs: AstroLogMessage[] = [];
const logger = new AstroLogger({
level: 'warn',
destination: {
write(chunk: AstroLogMessage) {
logs.push(chunk);
return true;
},
}),
},
});
await fixture.build({
// @ts-expect-error: logger is an internal API
logger,
});

const relevantLogs = logs
Expand All @@ -44,7 +47,7 @@ describe('Prerender conflicts', () => {
});

it('fails when prerenderConflictBehavior is set to error', async () => {
let err;
let err: unknown;
try {
await fixture.build({ prerenderConflictBehavior: 'error' });
} catch (e) {
Expand All @@ -59,23 +62,26 @@ describe('Prerender conflicts', () => {
});

describe('static vs dynamic', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/prerender-conflict-static-dynamic/' });
});

it('warns by default and succeeds', async () => {
const logs = [];
await fixture.build({
logger: new AstroLogger({
level: 'warn',
destination: {
write(chunk) {
logs.push(chunk);
},
const logs: AstroLogMessage[] = [];
const logger = new AstroLogger({
level: 'warn',
destination: {
write(chunk: AstroLogMessage) {
logs.push(chunk);
return true;
},
}),
},
});
await fixture.build({
// @ts-expect-error: logger is an internal API
logger,
});

const relevantLogs = logs
Expand All @@ -92,7 +98,7 @@ describe('Prerender conflicts', () => {
});

it('fails when prerenderConflictBehavior is set to error', async () => {
let err;
let err: unknown;
try {
await fixture.build({ prerenderConflictBehavior: 'error' });
} catch (e) {
Expand Down
Loading
Loading