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
1 change: 1 addition & 0 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"@types/html-escaper": "3.0.4",
"@types/http-cache-semantics": "^4.2.0",
"@types/js-yaml": "^4.0.9",
"@types/parse-srcset": "^1.0.0",
"@types/picomatch": "^4.0.2",
"@types/semver": "^7.7.1",
"@types/yargs-parser": "^21.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';

describe('assets dir takes the URL path inside the output directory', () => {
/** @type {URL} */
let checkDir;
let checkDir: URL;
before(async () => {
const fixture = await loadFixture({
root: './fixtures/astro-assets-dir/',
Expand All @@ -25,7 +24,7 @@ describe('assets dir takes the URL path inside the output directory', () => {
await fixture.build();
});
it('generates the assets directory as per build.assets configuration', async () => {
const removeTrailingSlash = (str) => str.replace(/\/$/, '');
const removeTrailingSlash = (str: string) => str.replace(/\/$/, '');
assert.equal(
removeTrailingSlash(new URL('./custom_dir_1', checkDir).toString()),
removeTrailingSlash(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 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 App, type Fixture, loadFixture } from './test-utils.js';

const defaultAssetsPrefixRegex = /^https:\/\/example.com\/_astro\/.*/;
const jsAssetsPrefixRegex = /^https:\/\/js\.example\.com\/_astro\/.*/;
Expand All @@ -15,7 +15,7 @@ const assetsPrefix = {

// Asset prefix for CDN support
describe('Assets Prefix Multiple CDN - Static', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand Down Expand Up @@ -44,15 +44,15 @@ describe('Assets Prefix Multiple CDN - Static', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const imgAsset = $('#image-asset');
assert.match(imgAsset.attr('src'), defaultAssetsPrefixRegex);
assert.match(imgAsset.attr('src')!, defaultAssetsPrefixRegex);
});

it('react component astro-island should import from jsAssetsPrefix', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const island = $('astro-island');
assert.match(island.attr('component-url'), jsAssetsPrefixRegex);
assert.match(island.attr('renderer-url'), jsAssetsPrefixRegex);
assert.match(island.attr('component-url')!, jsAssetsPrefixRegex);
assert.match(island.attr('renderer-url')!, jsAssetsPrefixRegex);
});

it('import.meta.env.ASSETS_PREFIX works', async () => {
Expand All @@ -75,13 +75,13 @@ describe('Assets Prefix Multiple CDN - Static', () => {
const html = await fixture.readFile('/blog/index.html');
const $ = cheerio.load(html);
const imgAsset = $('img');
assert.match(imgAsset.attr('src'), defaultAssetsPrefixRegex);
assert.match(imgAsset.attr('src')!, defaultAssetsPrefixRegex);
});
});

describe('Assets Prefix Multiple CDN, server', () => {
let app;
let fixture;
let app: App;
let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-assets-prefix',
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('Assets Prefix Multiple CDN, server', () => {
const html = await response.text();
const $ = cheerio.load(html);
const imgAsset = $('#image-asset');
assert.match(imgAsset.attr('src'), defaultAssetsPrefixRegex);
assert.match(imgAsset.attr('src')!, defaultAssetsPrefixRegex);
});

it('react component astro-island should import from assetsPrefix', async () => {
Expand All @@ -124,8 +124,8 @@ describe('Assets Prefix Multiple CDN, server', () => {
const html = await response.text();
const $ = cheerio.load(html);
const island = $('astro-island');
assert.match(island.attr('component-url'), jsAssetsPrefixRegex);
assert.match(island.attr('renderer-url'), jsAssetsPrefixRegex);
assert.match(island.attr('component-url')!, jsAssetsPrefixRegex);
assert.match(island.attr('renderer-url')!, jsAssetsPrefixRegex);
});

it('markdown optimized image src does not start with assetsPrefix in SSR', async () => {
Expand All @@ -135,6 +135,6 @@ describe('Assets Prefix Multiple CDN, server', () => {
const html = await response.text();
const $ = cheerio.load(html);
const imgAsset = $('img');
assert.doesNotMatch(imgAsset.attr('src'), defaultAssetsPrefixRegex);
assert.doesNotMatch(imgAsset.attr('src')!, defaultAssetsPrefixRegex);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 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 App, type Fixture, loadFixture } from './test-utils.js';

const assetsPrefix = 'http://localhost:4321';
const assetsPrefixRegex = /^http:\/\/localhost:4321\/_astro\/.*/;

// Asset prefix for CDN support
describe('Assets Prefix - Static', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -36,15 +36,15 @@ describe('Assets Prefix - Static', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const imgAsset = $('#image-asset');
assert.match(imgAsset.attr('src'), assetsPrefixRegex);
assert.match(imgAsset.attr('src')!, assetsPrefixRegex);
});

it('react component astro-island should import from assetsPrefix', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const island = $('astro-island');
assert.match(island.attr('component-url'), assetsPrefixRegex);
assert.match(island.attr('renderer-url'), assetsPrefixRegex);
assert.match(island.attr('component-url')!, assetsPrefixRegex);
assert.match(island.attr('renderer-url')!, assetsPrefixRegex);
});

it('import.meta.env.ASSETS_PREFIX works', async () => {
Expand All @@ -67,7 +67,7 @@ describe('Assets Prefix - Static', () => {
const html = await fixture.readFile('/blog/index.html');
const $ = cheerio.load(html);
const imgAsset = $('img');
assert.match(imgAsset.attr('src'), assetsPrefixRegex);
assert.match(imgAsset.attr('src')!, assetsPrefixRegex);
});

it('MDX content collection CSS imports should start with assetsPrefix', async () => {
Expand All @@ -82,7 +82,7 @@ describe('Assets Prefix - Static', () => {
});

describe('Assets Prefix - with path prefix', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -106,7 +106,7 @@ describe('Assets Prefix - with path prefix', () => {
});

describe('Assets Prefix, server', () => {
let app;
let app: App;

before(async () => {
const fixture = await loadFixture({
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('Assets Prefix, server', () => {
const html = await response.text();
const $ = cheerio.load(html);
const imgAsset = $('#image-asset');
assert.match(imgAsset.attr('src'), assetsPrefixRegex);
assert.match(imgAsset.attr('src')!, assetsPrefixRegex);
});

it('react component astro-island should import from assetsPrefix', async () => {
Expand All @@ -148,8 +148,8 @@ describe('Assets Prefix, server', () => {
const html = await response.text();
const $ = cheerio.load(html);
const island = $('astro-island');
assert.match(island.attr('component-url'), assetsPrefixRegex);
assert.match(island.attr('renderer-url'), assetsPrefixRegex);
assert.match(island.attr('component-url')!, assetsPrefixRegex);
assert.match(island.attr('renderer-url')!, assetsPrefixRegex);
});

it('markdown optimized image src does not start with assetsPrefix in SSR', async () => {
Expand All @@ -159,12 +159,12 @@ describe('Assets Prefix, server', () => {
const html = await response.text();
const $ = cheerio.load(html);
const imgAsset = $('img');
assert.doesNotMatch(imgAsset.attr('src'), assetsPrefixRegex);
assert.doesNotMatch(imgAsset.attr('src')!, assetsPrefixRegex);
});
});

describe('Assets Prefix, with path prefix', () => {
let app;
let app: App;

before(async () => {
const fixture = await loadFixture({
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 parseSrcset from 'parse-srcset';
import { loadFixture } from './test-utils.js';
import { type Fixture, loadFixture } from './test-utils.js';

// Asset bundling
describe('Assets', () => {
let fixture;
let fixture: Fixture;

before(async () => {
fixture = await loadFixture({
Expand All @@ -18,43 +18,43 @@ describe('Assets', () => {
it('built the base image', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const imgPath = $('img').attr('src');
const imgPath = $('img').attr('src')!;
const data = await fixture.readFile(imgPath);
assert.equal(!!data, true);
});

it('built the 2x image', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const srcset = $('img').attr('srcset');
const srcset = $('img').attr('srcset')!;
const candidates = parseSrcset(srcset);
const match = candidates.find((a) => a.d === 2);
const match = candidates.find((a) => a.d === 2)!;
const data = await fixture.readFile(match.url);
assert.equal(!!data, true);
});

it('built the 3x image', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const srcset = $('img').attr('srcset');
const srcset = $('img').attr('srcset')!;
const candidates = parseSrcset(srcset);
const match = candidates.find((a) => a.d === 3);
const match = candidates.find((a) => a.d === 3)!;
const data = await fixture.readFile(match.url);
assert.equal(!!data, true);
});

it('built image from an import specifier', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const src = $('#import-no-url').attr('src');
const src = $('#import-no-url').attr('src')!;
const data = await fixture.readFile(src);
assert.equal(!!data, true);
});

it('built image from an import specifier using ?url', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const src = $('#import-url').attr('src');
const src = $('#import-url').attr('src')!;
const data = await fixture.readFile(src);
assert.equal(!!data, true);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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 createTestPrerenderer from './test-prerenderer.js';
import { type DevServer, type Fixture, loadFixture, type PreviewServer } from './test-utils.js';

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

let previewServer;
let previewServer: PreviewServer;

before(async () => {
fixture = await loadFixture({
Expand All @@ -28,13 +27,13 @@ describe('Astro basic build', () => {
const $ = cheerio.load(html);

assert.equal($('#spread-plain').length, 1);
assert.match($('#spread-plain').attr('class'), /astro-.*/);
assert.match($('#spread-plain').attr('class')!, /astro-.*/);

assert.equal($('#spread-class').length, 1);
assert.match($('#spread-class').attr('class'), /astro-.*/);
assert.match($('#spread-class').attr('class')!, /astro-.*/);

assert.equal($('#spread-class-list').length, 1);
assert.match($('#spread-class-list').attr('class'), /astro-.*/);
assert.match($('#spread-class-list').attr('class')!, /astro-.*/);
});

it('supports special chars in filename', async () => {
Expand Down Expand Up @@ -86,7 +85,7 @@ describe('Astro basic build', () => {
it('Defines Astro.generator', async () => {
const html = await fixture.readFile('/generator/index.html');
const $ = cheerio.load(html);
assert.match($('meta[name="generator"]').attr('content'), /^Astro v/);
assert.match($('meta[name="generator"]').attr('content')!, /^Astro v/);
});

describe('preview', () => {
Expand All @@ -103,10 +102,8 @@ describe('Astro basic build', () => {
});

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

before(async () => {
fixture = await loadFixture({
Expand All @@ -124,7 +121,7 @@ describe('Astro basic development', () => {
const html = await res.text();
const $ = cheerio.load(html);
assert.equal($('h1').text(), '我的第一篇博客文章');
assert.doesNotMatch(res.headers.get('content-type'), /charset=utf-8/);
assert.doesNotMatch(res.headers.get('content-type')!, /charset=utf-8/);
assert.match(html, /<meta charset="utf-8"/);
});

Expand All @@ -145,9 +142,8 @@ describe('Astro basic development', () => {
});

describe('Astro custom prerenderer', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let testPrerenderer;
let fixture: Fixture;
let testPrerenderer: ReturnType<typeof createTestPrerenderer>;

before(async () => {
testPrerenderer = createTestPrerenderer();
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 children', () => {
let fixture;
let fixture: Fixture;

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