diff --git a/packages/astro/package.json b/packages/astro/package.json
index 42495360186f..f7f31951a4a7 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -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",
diff --git a/packages/astro/test/astro-assets-dir.test.js b/packages/astro/test/astro-assets-dir.test.ts
similarity index 89%
rename from packages/astro/test/astro-assets-dir.test.js
rename to packages/astro/test/astro-assets-dir.test.ts
index 9cf888846662..f988cd7fd92f 100644
--- a/packages/astro/test/astro-assets-dir.test.js
+++ b/packages/astro/test/astro-assets-dir.test.ts
@@ -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/',
@@ -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(
diff --git a/packages/astro/test/astro-assets-prefix-multi-cdn.test.js b/packages/astro/test/astro-assets-prefix-multi-cdn.test.ts
similarity index 85%
rename from packages/astro/test/astro-assets-prefix-multi-cdn.test.js
rename to packages/astro/test/astro-assets-prefix-multi-cdn.test.ts
index 82a36582416c..178a8da9a730 100644
--- a/packages/astro/test/astro-assets-prefix-multi-cdn.test.js
+++ b/packages/astro/test/astro-assets-prefix-multi-cdn.test.ts
@@ -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\/.*/;
@@ -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({
@@ -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 () => {
@@ -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',
@@ -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 () => {
@@ -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 () => {
@@ -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);
});
});
diff --git a/packages/astro/test/astro-assets-prefix.test.js b/packages/astro/test/astro-assets-prefix.test.ts
similarity index 89%
rename from packages/astro/test/astro-assets-prefix.test.js
rename to packages/astro/test/astro-assets-prefix.test.ts
index eab4ec9baaab..7efe0d07dfea 100644
--- a/packages/astro/test/astro-assets-prefix.test.js
+++ b/packages/astro/test/astro-assets-prefix.test.ts
@@ -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({
@@ -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 () => {
@@ -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 () => {
@@ -82,7 +82,7 @@ describe('Assets Prefix - Static', () => {
});
describe('Assets Prefix - with path prefix', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -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({
@@ -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 () => {
@@ -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 () => {
@@ -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({
diff --git a/packages/astro/test/astro-assets.test.js b/packages/astro/test/astro-assets.test.ts
similarity index 78%
rename from packages/astro/test/astro-assets.test.js
rename to packages/astro/test/astro-assets.test.ts
index b74464d2f7b5..66e38cb4dc1d 100644
--- a/packages/astro/test/astro-assets.test.js
+++ b/packages/astro/test/astro-assets.test.ts
@@ -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({
@@ -18,7 +18,7 @@ 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);
});
@@ -26,9 +26,9 @@ describe('Assets', () => {
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);
});
@@ -36,9 +36,9 @@ describe('Assets', () => {
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);
});
@@ -46,7 +46,7 @@ describe('Assets', () => {
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);
});
@@ -54,7 +54,7 @@ describe('Assets', () => {
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);
});
diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.ts
similarity index 89%
rename from packages/astro/test/astro-basic.test.js
rename to packages/astro/test/astro-basic.test.ts
index 2bd5a64a3b23..6dbe01bde7f8 100644
--- a/packages/astro/test/astro-basic.test.js
+++ b/packages/astro/test/astro-basic.test.ts
@@ -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({
@@ -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 () => {
@@ -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', () => {
@@ -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({
@@ -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, / {
});
describe('Astro custom prerenderer', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
- let testPrerenderer;
+ let fixture: Fixture;
+ let testPrerenderer: ReturnType;
before(async () => {
testPrerenderer = createTestPrerenderer();
diff --git a/packages/astro/test/astro-children.test.js b/packages/astro/test/astro-children.test.ts
similarity index 97%
rename from packages/astro/test/astro-children.test.js
rename to packages/astro/test/astro-children.test.ts
index b5457ea71cdb..5cb244880694 100644
--- a/packages/astro/test/astro-children.test.js
+++ b/packages/astro/test/astro-children.test.ts
@@ -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/' });
diff --git a/packages/astro/test/astro-client-only.test.js b/packages/astro/test/astro-client-only.test.ts
similarity index 93%
rename from packages/astro/test/astro-client-only.test.js
rename to packages/astro/test/astro-client-only.test.ts
index c0004d18401b..11cbcdc13e8e 100644
--- a/packages/astro/test/astro-client-only.test.js
+++ b/packages/astro/test/astro-client-only.test.ts
@@ -1,11 +1,10 @@
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';
describe('Client only components', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -49,7 +48,7 @@ describe('Client only components', () => {
assert.equal($('head link[rel=stylesheet]').length, 1);
- const href = $('link[rel=stylesheet]').attr('href');
+ const href = $('link[rel=stylesheet]').attr('href')!;
const css = await fixture.readFile(href);
assert.match(css, /tomato/, 'Svelte styles are added');
@@ -69,7 +68,7 @@ describe('Client only components', () => {
});
describe('Client only components subpath', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -113,7 +112,7 @@ describe('Client only components subpath', () => {
const html = await fixture.readFile('/tsx-no-extension/index.html');
const $ = cheerioLoad(html);
- const href = $('link[rel=stylesheet]').attr('href');
+ const href = $('link[rel=stylesheet]').attr('href')!;
const css = await fixture.readFile(href.replace(/\/blog/, ''));
assert.match(css, /purple/, 'Global styles from tsx component are added');
diff --git a/packages/astro/test/astro-component-bundling.test.js b/packages/astro/test/astro-component-bundling.test.ts
similarity index 92%
rename from packages/astro/test/astro-component-bundling.test.js
rename to packages/astro/test/astro-component-bundling.test.ts
index 76569c2ffc1c..b16a950481c7 100644
--- a/packages/astro/test/astro-component-bundling.test.js
+++ b/packages/astro/test/astro-component-bundling.test.ts
@@ -1,18 +1,16 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
+import { type DevServer, type Fixture, loadFixture } from './test-utils.js';
describe('Component bundling', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-component-bundling/' });
});
describe('dev', () => {
- /** @type {import('./test-utils.js').DevServer} */
- let devServer;
+ let devServer: DevServer;
before(async () => {
devServer = await fixture.startDevServer();
diff --git a/packages/astro/test/astro-component-code.test.js b/packages/astro/test/astro-component-code.test.ts
similarity index 96%
rename from packages/astro/test/astro-component-code.test.js
rename to packages/astro/test/astro-component-code.test.ts
index 3c7b7738479b..23ff788e1a71 100644
--- a/packages/astro/test/astro-component-code.test.js
+++ b/packages/astro/test/astro-component-code.test.ts
@@ -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('', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-component-code/' });
@@ -118,7 +118,7 @@ describe('', () => {
const codeEl = $('.astro-code');
assert.equal(codeEl.prop('tagName'), 'CODE');
- assert.match(codeEl.attr('style'), /background-color:/);
+ assert.match(codeEl.attr('style')!, /background-color:/);
assert.equal($('pre').length, 0);
});
diff --git a/packages/astro/test/astro-cookies.test.js b/packages/astro/test/astro-cookies.test.ts
similarity index 86%
rename from packages/astro/test/astro-cookies.test.js
rename to packages/astro/test/astro-cookies.test.ts
index e375cf1e8a74..c02b0b9869a8 100644
--- a/packages/astro/test/astro-cookies.test.js
+++ b/packages/astro/test/astro-cookies.test.ts
@@ -2,11 +2,10 @@ 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 DevServer, type Fixture, loadFixture } from './test-utils.js';
describe('Astro.cookies', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -17,8 +16,7 @@ describe('Astro.cookies', () => {
});
describe('Development', () => {
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+ let devServer: DevServer;
before(async () => {
devServer = await fixture.startDevServer();
@@ -57,36 +55,36 @@ describe('Astro.cookies', () => {
const response = await fixture.fetch('/from');
assert.equal(response.status, 200);
- assert.match(response.headers.get('set-cookie'), /my_cookie=value/);
+ assert.match(response.headers.get('set-cookie')!, /my_cookie=value/);
});
it('overwrites cookie values set in the source page with values from the target page', async () => {
const response = await fixture.fetch('/from');
assert.equal(response.status, 200);
- assert.match(response.headers.get('set-cookie'), /another=set-in-target/);
+ assert.match(response.headers.get('set-cookie')!, /another=set-in-target/);
});
it('allows cookies to be set in the source page', async () => {
const response = await fixture.fetch('/from');
assert.equal(response.status, 200);
- assert.match(response.headers.get('set-cookie'), /set-in-from=yes/);
+ assert.match(response.headers.get('set-cookie')!, /set-in-from=yes/);
});
it('can set cookies in a rewritten endpoint request', async () => {
const response = await fixture.fetch('/from-endpoint');
assert.equal(response.status, 200);
- assert.match(response.headers.get('set-cookie'), /test=value/);
+ assert.match(response.headers.get('set-cookie')!, /test=value/);
});
});
describe('Production', () => {
- let app;
+ let app: App;
before(async () => {
await fixture.build();
app = await fixture.loadTestAdapterApp();
});
- async function fetchResponse(path, requestInit) {
+ async function fetchResponse(path: string, requestInit?: RequestInit) {
const request = new Request('http://example.com' + path, requestInit);
const response = await app.render(request);
return response;
@@ -123,7 +121,7 @@ describe('Astro.cookies', () => {
assert.equal(response.status, 200);
const value = response.headers.get('Set-Cookie');
assert.equal(typeof value, 'string');
- assert.equal(value.startsWith('admin=true; Expires='), true);
+ assert.equal(value!.startsWith('admin=true; Expires='), true);
});
it('app.render can exclude the cookie from the Set-Cookie header', async () => {
@@ -171,35 +169,35 @@ describe('Astro.cookies', () => {
const response = await app.render(request, { addCookieHeader: true });
assert.equal(response.status, 200);
- assert.match(response.headers.get('Set-Cookie'), /my_cookie=value/);
+ assert.match(response.headers.get('Set-Cookie')!, /my_cookie=value/);
});
it('overwrites cookie values set in the source page with values from the target page', async () => {
const request = new Request('http://example.com/from');
const response = await app.render(request, { addCookieHeader: true });
assert.equal(response.status, 200);
- assert.match(response.headers.get('Set-Cookie'), /another=set-in-target/);
+ assert.match(response.headers.get('Set-Cookie')!, /another=set-in-target/);
});
it('allows cookies to be set in the source page', async () => {
const request = new Request('http://example.com/from');
const response = await app.render(request, { addCookieHeader: true });
assert.equal(response.status, 200);
- assert.match(response.headers.get('Set-Cookie'), /set-in-from=yes/);
+ assert.match(response.headers.get('Set-Cookie')!, /set-in-from=yes/);
});
it('can set cookies in a rewritten endpoint request', async () => {
const request = new Request('http://example.com/from-endpoint');
const response = await app.render(request, { addCookieHeader: true });
assert.equal(response.status, 200);
- assert.match(response.headers.get('Set-Cookie'), /test=value/);
+ assert.match(response.headers.get('Set-Cookie')!, /test=value/);
});
it('can set cookies in a rewritten endpoint request from middleware', async () => {
const request = new Request('http://example.com/rewrite-me');
const response = await app.render(request, { addCookieHeader: true });
assert.equal(response.status, 200);
- assert.match(response.headers.get('Set-Cookie'), /my_cookie=value/);
+ assert.match(response.headers.get('Set-Cookie')!, /my_cookie=value/);
});
});
});
diff --git a/packages/astro/test/astro-css-bundling.test.js b/packages/astro/test/astro-css-bundling.test.ts
similarity index 94%
rename from packages/astro/test/astro-css-bundling.test.js
rename to packages/astro/test/astro-css-bundling.test.ts
index 1a7c5afabe0f..c3e4427ea133 100644
--- a/packages/astro/test/astro-css-bundling.test.js
+++ b/packages/astro/test/astro-css-bundling.test.ts
@@ -1,7 +1,7 @@
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';
// note: the hashes should be deterministic, but updating the file contents will change hashes
// be careful not to test that the HTML simply contains CSS, because it always will! filename and quantity matter here (bundling).
@@ -20,8 +20,7 @@ const UNEXPECTED_CSS = [
];
describe('CSS Bundling', function () {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
describe('defaults', () => {
before(async () => {
@@ -34,7 +33,7 @@ describe('CSS Bundling', function () {
});
it('Bundles CSS', async () => {
- const builtCSS = new Set();
+ const builtCSS = new Set();
// for all HTML files…
for (const [filepath, css] of Object.entries(EXPECTED_CSS)) {
@@ -45,7 +44,7 @@ describe('CSS Bundling', function () {
for (const href of css) {
const link = $(`link[rel="stylesheet"][href^="${href}"]`);
assert.equal(link.length >= 1, true);
- const outHref = link.attr('href');
+ const outHref = link.attr('href')!;
builtCSS.add(outHref.startsWith('../') ? outHref.slice(2) : outHref);
}
diff --git a/packages/astro/test/astro-dev-headers.test.js b/packages/astro/test/astro-dev-headers.test.ts
similarity index 86%
rename from packages/astro/test/astro-dev-headers.test.js
rename to packages/astro/test/astro-dev-headers.test.ts
index 3e490ebbc44e..56181e30ca4c 100644
--- a/packages/astro/test/astro-dev-headers.test.js
+++ b/packages/astro/test/astro-dev-headers.test.ts
@@ -1,11 +1,11 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
-import { loadFixture } from './test-utils.js';
+import { type DevServer, type Fixture, loadFixture } from './test-utils.js';
describe('Astro dev headers', () => {
- let fixture;
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
const headers = {
'x-astro': 'test',
};
@@ -41,8 +41,8 @@ describe('Astro dev headers', () => {
});
describe('Astro dev with vite.base path', () => {
- let fixture;
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
const headers = {
'x-astro': 'test',
};
@@ -69,6 +69,6 @@ describe('Astro dev with vite.base path', () => {
const result = await fixture.fetch('/hello');
const html = await result.text();
const $ = cheerioLoad(html);
- assert.match($('script').attr('src'), /^\/hello\/@vite\/client$/);
+ assert.match($('script').attr('src')!, /^\/hello\/@vite\/client$/);
});
});
diff --git a/packages/astro/test/astro-dev-http2.test.js b/packages/astro/test/astro-dev-http2.test.ts
similarity index 88%
rename from packages/astro/test/astro-dev-http2.test.js
rename to packages/astro/test/astro-dev-http2.test.ts
index a4ea53b3ed70..3dc761963ebc 100644
--- a/packages/astro/test/astro-dev-http2.test.js
+++ b/packages/astro/test/astro-dev-http2.test.ts
@@ -1,11 +1,11 @@
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('Astro HTTP/2 support', () => {
- let fixture;
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.test.ts
similarity index 89%
rename from packages/astro/test/astro-directives.test.js
rename to packages/astro/test/astro-directives.test.ts
index 80b4d32d1143..cafd836dfa7f 100644
--- a/packages/astro/test/astro-directives.test.js
+++ b/packages/astro/test/astro-directives.test.ts
@@ -1,10 +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('Directives', async () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -54,11 +54,11 @@ describe('Directives', async () => {
assert.equal($('style').length, 0);
// Inject style attribute on top-level element in page
- assert.equal($('html').attr('style').toString().includes('--bg: white;'), true);
- assert.equal($('html').attr('style').toString().includes('--fg: black;'), true);
+ assert.equal($('html').attr('style')!.toString().includes('--bg: white;'), true);
+ assert.equal($('html').attr('style')!.toString().includes('--fg: black;'), true);
// Inject style attribute on top-level elements in component
- assert.equal($('h1').attr('style').toString().includes('--textColor: red;'), true);
+ assert.equal($('h1').attr('style')!.toString().includes('--textColor: red;'), true);
});
it('Properly handles define:vars on style elements with style object', async () => {
@@ -71,7 +71,7 @@ describe('Directives', async () => {
// Inject style attribute on top-level element in page
assert.equal(
$('#compound-style')
- .attr('style')
+ .attr('style')!
.toString()
.includes('color:var(--fg);--bg: white;--fg: black;'),
true,
@@ -125,8 +125,7 @@ describe('Directives', async () => {
});
describe('set:html dev', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -135,12 +134,15 @@ describe('set:html dev', () => {
});
describe('Development', () => {
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+ let devServer: DevServer;
before(async () => {
devServer = await fixture.startDevServer();
- globalThis.TEST_FETCH = (fetch, url, init) => {
+ (globalThis as any).TEST_FETCH = (
+ fetch: typeof globalThis.fetch,
+ url: string,
+ init?: RequestInit,
+ ) => {
return fetch(fixture.resolveUrl(url), init);
};
});
diff --git a/packages/astro/test/astro-doctype.test.js b/packages/astro/test/astro-doctype.test.ts
similarity index 96%
rename from packages/astro/test/astro-doctype.test.js
rename to packages/astro/test/astro-doctype.test.ts
index e2e5e525b12c..88678fc2ee5b 100644
--- a/packages/astro/test/astro-doctype.test.js
+++ b/packages/astro/test/astro-doctype.test.ts
@@ -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('Doctype', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-doctype/' });
diff --git a/packages/astro/test/astro-dynamic.test.js b/packages/astro/test/astro-dynamic.test.ts
similarity index 90%
rename from packages/astro/test/astro-dynamic.test.js
rename to packages/astro/test/astro-dynamic.test.ts
index 66240e81664c..b5d22b41ec56 100644
--- a/packages/astro/test/astro-dynamic.test.js
+++ b/packages/astro/test/astro-dynamic.test.ts
@@ -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('Dynamic components', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -35,13 +35,13 @@ describe('Dynamic components', () => {
// test 1: is empty.
assert.equal($('astro-island').html(), '');
// test 2: component url
- const href = $('astro-island').attr('component-url');
+ const href = $('astro-island').attr('component-url')!;
assert.equal(href.includes(`/PersistentCounter`), true);
});
});
describe('Dynamic components subpath', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -74,7 +74,7 @@ describe('Dynamic components subpath', () => {
// test 1: is empty.
assert.equal($('astro-island').html(), '');
// test 2: has component url
- const attr = $('astro-island').attr('component-url');
+ const attr = $('astro-island').attr('component-url')!;
assert.equal(attr.includes(`blog/_astro/PersistentCounter`), true);
});
});
diff --git a/packages/astro/test/astro-envs.test.js b/packages/astro/test/astro-envs.test.ts
similarity index 94%
rename from packages/astro/test/astro-envs.test.js
rename to packages/astro/test/astro-envs.test.ts
index 4e2787798f1c..90aa2ffa438b 100644
--- a/packages/astro/test/astro-envs.test.js
+++ b/packages/astro/test/astro-envs.test.ts
@@ -1,16 +1,14 @@
-// @ts-check
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 DevServer, type Fixture, loadFixture } from './test-utils.js';
const root = './fixtures/astro-envs/';
describe('Environment Variables', () => {
describe('Build', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
process.env.BOOLEAN_VAR = 'true';
@@ -108,10 +106,8 @@ describe('Environment Variables', () => {
});
describe('Development', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({ root });
@@ -148,8 +144,7 @@ describe('Environment Variables', () => {
});
describe('SSR', () => {
- /** @type {import('./test-utils').App} */
- let app;
+ let app: App;
before(async () => {
const fixture = await loadFixture({
diff --git a/packages/astro/test/astro-expr.test.js b/packages/astro/test/astro-expr.test.ts
similarity index 97%
rename from packages/astro/test/astro-expr.test.js
rename to packages/astro/test/astro-expr.test.ts
index 80ae53aa6357..e5ca6b475925 100644
--- a/packages/astro/test/astro-expr.test.js
+++ b/packages/astro/test/astro-expr.test.ts
@@ -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('Expressions', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-get-static-paths.test.js b/packages/astro/test/astro-get-static-paths.test.ts
similarity index 93%
rename from packages/astro/test/astro-get-static-paths.test.js
rename to packages/astro/test/astro-get-static-paths.test.ts
index 2b918e493436..8ac312d875cf 100644
--- a/packages/astro/test/astro-get-static-paths.test.js
+++ b/packages/astro/test/astro-get-static-paths.test.ts
@@ -1,14 +1,12 @@
-// @ts-check
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';
const root = new URL('./fixtures/astro-get-static-paths/', import.meta.url);
describe('getStaticPaths - build calls', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -29,10 +27,8 @@ describe('getStaticPaths - build calls', () => {
});
describe('getStaticPaths - dev calls', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({
@@ -120,8 +116,7 @@ describe('getStaticPaths - dev calls', () => {
it('warns if Astro.generator or Astro.site is accessed', async () => {
const originalWarn = console.warn;
- /** @type {Array} */
- const logs = [];
+ const logs: Array = [];
console.warn = (...args) => {
logs.push(...args);
return originalWarn(...args);
@@ -144,8 +139,7 @@ describe('getStaticPaths - dev calls', () => {
});
describe('throws if an invalid Astro property is accessed', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-global.test.js b/packages/astro/test/astro-global.test.ts
similarity index 97%
rename from packages/astro/test/astro-global.test.js
rename to packages/astro/test/astro-global.test.ts
index 21dfea26e181..cccb1dbb64d1 100644
--- a/packages/astro/test/astro-global.test.js
+++ b/packages/astro/test/astro-global.test.ts
@@ -2,10 +2,10 @@ 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 DevServer, type Fixture, loadFixture } from './test-utils.js';
describe('Astro Global', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -16,7 +16,7 @@ describe('Astro Global', () => {
});
describe('dev', () => {
- let devServer;
+ let devServer: DevServer;
before(async () => {
devServer = await fixture.startDevServer();
@@ -141,8 +141,7 @@ describe('Astro Global', () => {
});
describe('app', () => {
- /** @type {import('../dist/core/app/app.js').App} */
- let app;
+ let app: App;
before(async () => {
fixture = await loadFixture({
@@ -195,7 +194,7 @@ describe('Astro Global', () => {
});
describe('Astro Global Defaults', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -204,8 +203,8 @@ describe('Astro Global Defaults', () => {
});
describe('dev', () => {
- let devServer;
- let $;
+ let devServer: DevServer;
+ let $: cheerio.CheerioAPI;
before(async () => {
devServer = await fixture.startDevServer();
diff --git a/packages/astro/test/astro-head.test.js b/packages/astro/test/astro-head.test.ts
similarity index 90%
rename from packages/astro/test/astro-head.test.js
rename to packages/astro/test/astro-head.test.ts
index 303d74baafcd..5e2d1f38f71b 100644
--- a/packages/astro/test/astro-head.test.js
+++ b/packages/astro/test/astro-head.test.ts
@@ -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('Head in its own component', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-markdown-frontmatter-injection.test.js b/packages/astro/test/astro-markdown-frontmatter-injection.test.ts
similarity index 55%
rename from packages/astro/test/astro-markdown-frontmatter-injection.test.js
rename to packages/astro/test/astro-markdown-frontmatter-injection.test.ts
index 9818174d73ac..1c66749957c3 100644
--- a/packages/astro/test/astro-markdown-frontmatter-injection.test.js
+++ b/packages/astro/test/astro-markdown-frontmatter-injection.test.ts
@@ -1,11 +1,26 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
+import { type Fixture, loadFixture } from './test-utils.js';
const FIXTURE_ROOT = './fixtures/astro-markdown-frontmatter-injection/';
+interface FrontmatterEntry {
+ title: string;
+ description: string;
+ injectedReadingTime: {
+ text: string;
+ minutes: number;
+ time: number;
+ words: number;
+ };
+}
+
+async function readGlob(fixture: Fixture): Promise {
+ return JSON.parse(await fixture.readFile('/glob.json'));
+}
+
describe('Astro Markdown - frontmatter injection', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -15,17 +30,15 @@ describe('Astro Markdown - frontmatter injection', () => {
});
it('remark supports custom vfile data - get title', async () => {
- const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
- const titles = frontmatterByPage.map((frontmatter = {}) => frontmatter.title);
+ const frontmatterByPage = await readGlob(fixture);
+ const titles = frontmatterByPage.map((frontmatter) => frontmatter.title);
assert.ok(titles.includes('Page 1'));
assert.ok(titles.includes('Page 2'));
});
it('rehype supports custom vfile data - reading time', async () => {
- const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
- const readingTimes = frontmatterByPage.map(
- (frontmatter = {}) => frontmatter.injectedReadingTime,
- );
+ const frontmatterByPage = await readGlob(fixture);
+ const readingTimes = frontmatterByPage.map((frontmatter) => frontmatter.injectedReadingTime);
assert.ok(readingTimes.length > 0);
for (let readingTime of readingTimes) {
assert.notEqual(readingTime, null);
@@ -34,8 +47,8 @@ describe('Astro Markdown - frontmatter injection', () => {
});
it('allow user frontmatter mutation', async () => {
- const frontmatterByPage = JSON.parse(await fixture.readFile('/glob.json'));
- const descriptions = frontmatterByPage.map((frontmatter = {}) => frontmatter.description);
+ const frontmatterByPage = await readGlob(fixture);
+ const descriptions = frontmatterByPage.map((frontmatter) => frontmatter.description);
assert.ok(descriptions.includes('Processed by remarkDescription plugin: Page 1 description'));
assert.ok(descriptions.includes('Processed by remarkDescription plugin: Page 2 description'));
});
diff --git a/packages/astro/test/astro-markdown-plugins.test.js b/packages/astro/test/astro-markdown-plugins.test.ts
similarity index 90%
rename from packages/astro/test/astro-markdown-plugins.test.js
rename to packages/astro/test/astro-markdown-plugins.test.ts
index d5e0f66d2ba9..d43760dff307 100644
--- a/packages/astro/test/astro-markdown-plugins.test.js
+++ b/packages/astro/test/astro-markdown-plugins.test.ts
@@ -1,11 +1,26 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
+import type { RehypePlugin, RemarkPlugin } from '@astrojs/markdown-remark';
import * as cheerio from 'cheerio';
-import addClasses from './fixtures/astro-markdown-plugins/add-classes.mjs';
-import { loadFixture } from './test-utils.js';
+import { type AstroInlineConfig, type Fixture, loadFixture } from './test-utils.js';
-const defaultMarkdownConfig = {
+const remarkExamplePlugin: RemarkPlugin = () => {
+ return (tree) => {
+ tree.children.push({
+ type: 'paragraph',
+ children: [{ type: 'text', value: 'Remark plugin applied!' }],
+ });
+ };
+};
+
+const addClasses: RehypePlugin = await (async () => {
+ const importPath: string = './fixtures/astro-markdown-plugins/add-classes.mjs';
+ const mod = await import(importPath);
+ return mod.default;
+})();
+
+const defaultMarkdownConfig: AstroInlineConfig['markdown'] = {
gfm: true,
smartypants: true,
remarkPlugins: [
@@ -20,18 +35,9 @@ const defaultMarkdownConfig = {
],
};
-function remarkExamplePlugin() {
- return (tree) => {
- tree.children.push({
- type: 'paragraph',
- children: [{ type: 'text', value: 'Remark plugin applied!' }],
- });
- };
-}
-
describe('Astro Markdown plugins', () => {
describe('Default test plugins', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -122,7 +128,7 @@ describe('Astro Markdown plugins', () => {
});
describe('content layer plugins', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/content-layer-remark-plugins/',
@@ -216,17 +222,17 @@ describe('Astro Markdown plugins', () => {
const $ = cheerio.load(html);
// With backticks: 'all', single and double backticks are transformed
- assert.ok($('p').html().includes('“Smarty”'));
+ assert.ok($('p').html()!.includes('“Smarty”'));
});
});
});
-function testRehype(html, headingId) {
+function testRehype(html: string, headingId: string) {
const $ = cheerio.load(html);
assert.equal($(headingId).length, 1);
assert.ok($(headingId).hasClass('title'));
}
-function testRemark(html) {
+function testRemark(html: string) {
assert.ok(html.includes('Remark plugin applied!'));
}
diff --git a/packages/astro/test/astro-markdown-remarkRehype.test.js b/packages/astro/test/astro-markdown-remarkRehype.test.ts
similarity index 92%
rename from packages/astro/test/astro-markdown-remarkRehype.test.js
rename to packages/astro/test/astro-markdown-remarkRehype.test.ts
index 4725437ccf82..836b96c358a6 100644
--- a/packages/astro/test/astro-markdown-remarkRehype.test.js
+++ b/packages/astro/test/astro-markdown-remarkRehype.test.ts
@@ -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('Astro Markdown without remark-rehype config', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -21,7 +21,7 @@ describe('Astro Markdown without remark-rehype config', () => {
});
describe('Astro Markdown with remark-rehype config', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-markdown-shiki.test.js b/packages/astro/test/astro-markdown-shiki.test.ts
similarity index 83%
rename from packages/astro/test/astro-markdown-shiki.test.js
rename to packages/astro/test/astro-markdown-shiki.test.ts
index bd924c8da6ce..890f09c49f86 100644
--- a/packages/astro/test/astro-markdown-shiki.test.js
+++ b/packages/astro/test/astro-markdown-shiki.test.ts
@@ -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('Astro Markdown Shiki', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-markdown-shiki/langs/' });
@@ -22,14 +22,14 @@ describe('Astro Markdown Shiki', () => {
assert.equal($('pre').length, 2);
assert.ok($('pre').hasClass('astro-code'));
assert.equal(
- $('pre').attr().style,
+ $('pre').attr()!.style,
'background-color:#24292e;color:#e1e4e8; overflow-x: auto;',
);
});
});
describe('Languages', () => {
- let $;
+ let $: cheerio.CheerioAPI;
before(async () => {
const html = await fixture.readFile('/index.html');
@@ -38,14 +38,14 @@ describe('Astro Markdown Shiki', () => {
it('custom language', async () => {
const lang = $('.astro-code').get(0);
- const segments = $('.line', lang).get(6).children;
+ const segments = $('.line', lang).get(6)!.children as any[];
assert.equal(segments.length, 2);
assert.equal(segments[0].attribs.style, 'color:#79B8FF');
assert.equal(segments[1].attribs.style, 'color:#E1E4E8');
});
it('handles unknown languages', () => {
- const unknownLang = $('.astro-code').get(1);
+ const unknownLang = $('.astro-code').get(1)!;
assert.ok(unknownLang.attribs.style.includes('background-color:#24292e;color:#e1e4e8;'));
});
});
diff --git a/packages/astro/test/astro-markdown-url.test.js b/packages/astro/test/astro-markdown-url.test.ts
similarity index 100%
rename from packages/astro/test/astro-markdown-url.test.js
rename to packages/astro/test/astro-markdown-url.test.ts
diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.ts
similarity index 92%
rename from packages/astro/test/astro-markdown.test.js
rename to packages/astro/test/astro-markdown.test.ts
index 9c0cad34fcdc..f0d908bf82a1 100644
--- a/packages/astro/test/astro-markdown.test.js
+++ b/packages/astro/test/astro-markdown.test.ts
@@ -1,12 +1,22 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
-import { fixLineEndings, loadFixture } from './test-utils.js';
+import { type DevServer, type Fixture, fixLineEndings, loadFixture } from './test-utils.js';
const FIXTURE_ROOT = './fixtures/astro-markdown/';
+interface Heading {
+ depth: number;
+ slug: string;
+ text: string;
+}
+
+async function readHeadingsGlob(fixture: Fixture): Promise<{ headings: Heading[] }> {
+ return JSON.parse(await fixture.readFile('/headings-glob.json'));
+}
+
describe('Astro Markdown', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -110,9 +120,9 @@ describe('Astro Markdown', () => {
});
it('Exposes getHeadings() on glob imports', async () => {
- const { headings } = JSON.parse(await fixture.readFile('/headings-glob.json'));
+ const { headings } = await readHeadingsGlob(fixture);
- const headingSlugs = headings.map((heading) => heading?.slug);
+ const headingSlugs = headings.map((heading) => heading.slug);
assert.ok(headingSlugs.includes('section-1'));
assert.ok(headingSlugs.includes('section-2'));
@@ -165,7 +175,7 @@ describe('Astro Markdown', () => {
});
describe('dev', () => {
- let devServer;
+ let devServer: DevServer;
before(async () => {
devServer = await fixture.startDevServer();
diff --git a/packages/astro/test/astro-mode.test.js b/packages/astro/test/astro-mode.test.ts
similarity index 93%
rename from packages/astro/test/astro-mode.test.js
rename to packages/astro/test/astro-mode.test.ts
index 08e9a8055c72..ddefc1e58f5b 100644
--- a/packages/astro/test/astro-mode.test.js
+++ b/packages/astro/test/astro-mode.test.ts
@@ -2,13 +2,12 @@ import assert from 'node:assert/strict';
import { existsSync, promises as fs } from 'node:fs';
import { after, afterEach, 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('--mode', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
- let devDataStoreFile;
- let prodDataStoreFile;
+ let fixture: Fixture;
+ let devDataStoreFile: URL;
+ let prodDataStoreFile: URL;
async function deleteDataStoreFiles() {
await fs.unlink(devDataStoreFile).catch(() => {});
@@ -98,8 +97,7 @@ describe('--mode', () => {
});
describe('dev', () => {
- /** @type {import('./test-utils.js').DevServer} */
- let devServer;
+ let devServer: DevServer;
before(async () => {
await deleteDataStoreFiles();
devServer = await fixture.startDevServer();
@@ -126,8 +124,7 @@ describe('--mode', () => {
});
describe('dev --mode develop', () => {
- /** @type {import('./test-utils.js').DevServer} */
- let devServer;
+ let devServer: DevServer;
before(async () => {
await deleteDataStoreFiles();
devServer = await fixture.startDevServer({ mode: 'develop' });
diff --git a/packages/astro/test/astro-not-response.test.js b/packages/astro/test/astro-not-response.test.ts
similarity index 82%
rename from packages/astro/test/astro-not-response.test.js
rename to packages/astro/test/astro-not-response.test.ts
index 63bcef2368dd..1c868a8f387e 100644
--- a/packages/astro/test/astro-not-response.test.js
+++ b/packages/astro/test/astro-not-response.test.ts
@@ -1,12 +1,11 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
+import { type DevServer, type Fixture, loadFixture } from './test-utils.js';
// Asset bundling
describe('Not returning responses', () => {
- let fixture;
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({
@@ -29,7 +28,7 @@ describe('Not returning responses', () => {
true,
'Only instance of Response can be returned from an Astro file',
);
- return null;
+ return;
}
assert.fail('Should have thrown an error');
diff --git a/packages/astro/test/astro-pageDirectoryUrl.test.js b/packages/astro/test/astro-pageDirectoryUrl.test.ts
similarity index 85%
rename from packages/astro/test/astro-pageDirectoryUrl.test.js
rename to packages/astro/test/astro-pageDirectoryUrl.test.ts
index 76e224b07466..0dd45a4cbc90 100644
--- a/packages/astro/test/astro-pageDirectoryUrl.test.js
+++ b/packages/astro/test/astro-pageDirectoryUrl.test.ts
@@ -1,11 +1,10 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
+import { type Fixture, loadFixture } from './test-utils.js';
describe('build format', () => {
describe('build.format: file', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
@@ -25,8 +24,7 @@ describe('build format', () => {
});
describe('build.format: preserve', () => {
- /** @type {import('./test-utils.js').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-pages.test.js b/packages/astro/test/astro-pages.test.ts
similarity index 91%
rename from packages/astro/test/astro-pages.test.js
rename to packages/astro/test/astro-pages.test.ts
index f359e3e53457..9fd7770131fe 100644
--- a/packages/astro/test/astro-pages.test.js
+++ b/packages/astro/test/astro-pages.test.ts
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
-import { isWindows, loadFixture } from './test-utils.js';
+import { type DevServer, type Fixture, isWindows, loadFixture } from './test-utils.js';
describe('Pages', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro pages/' });
@@ -34,7 +34,7 @@ describe('Pages', () => {
if (isWindows) return;
describe('Development', () => {
- let devServer;
+ let devServer: DevServer;
before(async () => {
devServer = await fixture.startDevServer();
diff --git a/packages/astro/test/astro-partial-html.test.js b/packages/astro/test/astro-partial-html.test.ts
similarity index 91%
rename from packages/astro/test/astro-partial-html.test.js
rename to packages/astro/test/astro-partial-html.test.ts
index 9d04ea0ba257..1b56e0273409 100644
--- a/packages/astro/test/astro-partial-html.test.js
+++ b/packages/astro/test/astro-partial-html.test.ts
@@ -1,11 +1,11 @@
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('Partial HTML', async () => {
- let fixture;
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-preview-allowed-hosts.test.js b/packages/astro/test/astro-preview-allowed-hosts.test.ts
similarity index 89%
rename from packages/astro/test/astro-preview-allowed-hosts.test.js
rename to packages/astro/test/astro-preview-allowed-hosts.test.ts
index fc16e9cf2559..ab9f1db7ef08 100644
--- a/packages/astro/test/astro-preview-allowed-hosts.test.js
+++ b/packages/astro/test/astro-preview-allowed-hosts.test.ts
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import http from 'node:http';
import { after, before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
+import { type Fixture, loadFixture, type PreviewServer } from './test-utils.js';
/**
* Make a raw HTTP request with a custom Host header.
@@ -9,7 +9,7 @@ import { loadFixture } from './test-utils.js';
* We also use the actual bound port from previewServer.server.address() to avoid
* port mismatch if the configured port is already in use.
*/
-function fetchWithHost(port, hostHeader) {
+function fetchWithHost(port: number, hostHeader: string): Promise {
return new Promise((resolve, reject) => {
const req = http.request(
{
@@ -29,13 +29,13 @@ function fetchWithHost(port, hostHeader) {
});
}
-function getBoundPort(previewServer) {
+function getBoundPort(previewServer: PreviewServer): number {
return previewServer.server.address().port;
}
describe('astro preview - allowedHosts via vite config', () => {
- let fixture;
- let previewServer;
+ let fixture: Fixture;
+ let previewServer: PreviewServer;
before(async () => {
fixture = await loadFixture({
@@ -68,8 +68,8 @@ describe('astro preview - allowedHosts via vite config', () => {
});
describe('astro preview - allowedHosts true via vite config', () => {
- let fixture;
- let previewServer;
+ let fixture: Fixture;
+ let previewServer: PreviewServer;
before(async () => {
fixture = await loadFixture({
@@ -98,8 +98,8 @@ describe('astro preview - allowedHosts true via vite config', () => {
});
describe('astro preview - server.allowedHosts takes precedence over vite.preview.allowedHosts', () => {
- let fixture;
- let previewServer;
+ let fixture: Fixture;
+ let previewServer: PreviewServer;
before(async () => {
fixture = await loadFixture({
diff --git a/packages/astro/test/astro-preview-headers.test.js b/packages/astro/test/astro-preview-headers.test.ts
similarity index 88%
rename from packages/astro/test/astro-preview-headers.test.js
rename to packages/astro/test/astro-preview-headers.test.ts
index 93445b724ccc..4a8d33da43b5 100644
--- a/packages/astro/test/astro-preview-headers.test.js
+++ b/packages/astro/test/astro-preview-headers.test.ts
@@ -1,10 +1,10 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
-import { loadFixture } from './test-utils.js';
+import { type Fixture, loadFixture, type PreviewServer } from './test-utils.js';
describe('Astro preview headers', () => {
- let fixture;
- let previewServer;
+ let fixture: Fixture;
+ let previewServer: PreviewServer;
const headers = {
astro: 'test',
};
diff --git a/packages/astro/test/astro-public.test.js b/packages/astro/test/astro-public.test.ts
similarity index 89%
rename from packages/astro/test/astro-public.test.js
rename to packages/astro/test/astro-public.test.ts
index 8abc606af11c..968fbeef5569 100644
--- a/packages/astro/test/astro-public.test.js
+++ b/packages/astro/test/astro-public.test.ts
@@ -1,12 +1,13 @@
import assert from 'node:assert/strict';
import { Writable } from 'node:stream';
import { after, before, describe, it } from 'node:test';
+import type { AstroLogMessage } from '../dist/core/logger/core.js';
import { AstroLogger } from '../dist/core/logger/core.js';
-import { loadFixture } from './test-utils.js';
+import { type DevServer, type Fixture, loadFixture } from './test-utils.js';
describe('Public', () => {
- let fixture;
- let buildLogs = [];
+ let fixture: Fixture;
+ const buildLogs: AstroLogMessage[] = [];
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-public/' });
@@ -14,6 +15,7 @@ describe('Public', () => {
vite: {
logLevel: 'info',
},
+ // @ts-expect-error - logger is accepted by the fixture build wrapper
logger: new AstroLogger({
level: 'info',
destination: new Writable({
@@ -63,8 +65,8 @@ describe('Public', () => {
});
describe('Public (dev)', () => {
- let fixture;
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-public/' });
diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.test.ts
similarity index 88%
rename from packages/astro/test/astro-scripts.test.js
rename to packages/astro/test/astro-scripts.test.ts
index d059d1210ea3..0bc426002a12 100644
--- a/packages/astro/test/astro-scripts.test.js
+++ b/packages/astro/test/astro-scripts.test.ts
@@ -1,12 +1,11 @@
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('Scripts', () => {
describe('Build', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-scripts/',
@@ -42,7 +41,7 @@ describe('Scripts', () => {
assert.equal($('script').length, 1);
// test 2: inside assets
- let entryURL = $('script').attr('src');
+ let entryURL = $('script').attr('src')!;
assert.equal(entryURL.includes('_astro/'), true);
});
@@ -54,7 +53,7 @@ describe('Scripts', () => {
assert.equal($('script').length, 1);
// test 2: inside assets
- let entryURL = $('script').attr('src');
+ let entryURL = $('script').attr('src')!;
assert.equal(entryURL.includes('_astro/'), true);
});
@@ -81,9 +80,8 @@ describe('Scripts', () => {
});
describe('Inlining', () => {
- /** @type {import('./test-utils').Fixture} */
// eslint-disable-next-line @typescript-eslint/no-shadow
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-scripts/',
@@ -107,10 +105,8 @@ describe('Scripts', () => {
});
describe('Dev', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+ let fixture: Fixture;
+ let devServer: DevServer;
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-scripts/',
@@ -147,7 +143,7 @@ describe('Scripts', () => {
let moduleScripts = $('[type=module]');
moduleScripts.each((_i, el) => {
if (
- $(el).attr('src').includes('Glob/GlobComponent.astro?astro&type=script&index=0&lang.ts')
+ $(el).attr('src')!.includes('Glob/GlobComponent.astro?astro&type=script&index=0&lang.ts')
) {
found++;
}
@@ -162,7 +158,7 @@ describe('Scripts', () => {
let found = 0;
let moduleScripts = $('[type=module]');
moduleScripts.each((_i, el) => {
- if ($(el).attr('src').includes('?astro&type=script&index=0&lang.ts')) {
+ if ($(el).attr('src')!.includes('?astro&type=script&index=0&lang.ts')) {
found++;
}
});
@@ -176,7 +172,7 @@ describe('Scripts', () => {
let found = 0;
let moduleScripts = $('[type=module]');
moduleScripts.each((_i, el) => {
- if ($(el).attr('src').includes('@id/astro:scripts/page.js')) {
+ if ($(el).attr('src')!.includes('@id/astro:scripts/page.js')) {
found++;
}
});
diff --git a/packages/astro/test/astro-slots-nested.test.js b/packages/astro/test/astro-slots-nested.test.ts
similarity index 92%
rename from packages/astro/test/astro-slots-nested.test.js
rename to packages/astro/test/astro-slots-nested.test.ts
index 7ab56249c32e..811eaa60cc56 100644
--- a/packages/astro/test/astro-slots-nested.test.js
+++ b/packages/astro/test/astro-slots-nested.test.ts
@@ -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('Nested Slots', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-slots-nested/' });
@@ -27,8 +26,7 @@ describe('Nested Slots', () => {
});
describe('Client components nested inside server-only framework components', () => {
- /** @type {cheerio.CheerioAPI} */
- let $;
+ let $: cheerio.CheerioAPI;
before(async () => {
const html = await fixture.readFile('/server-component-nested/index.html');
$ = cheerio.load(html);
diff --git a/packages/astro/test/astro-slots.test.js b/packages/astro/test/astro-slots.test.ts
similarity index 89%
rename from packages/astro/test/astro-slots.test.js
rename to packages/astro/test/astro-slots.test.ts
index cb3bad2dbe65..df1db2933c5a 100644
--- a/packages/astro/test/astro-slots.test.js
+++ b/packages/astro/test/astro-slots.test.ts
@@ -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', () => {
- let fixture;
+ let fixture: Fixture;
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-slots/' });
@@ -163,23 +163,23 @@ describe('Slots', () => {
const elements = $('div');
assert.equal(elements.length, 10);
- const [first, second, third] = elements;
+ const first = elements.eq(0);
+ const second = elements.eq(1);
+ const third = elements.eq(2);
- assert.notEqual(first.children[0].data, second.children[0].data);
- assert.notEqual(second.children[0].data, third.children[0].data);
- assert.notEqual(third.children[0].data, first.children[0].data);
+ assert.notEqual(first.text(), second.text());
+ assert.notEqual(second.text(), third.text());
+ assert.notEqual(third.text(), first.text());
}
});
it('Arguments can be passed to named slots with Astro.slots.render()', async () => {
const html = await fixture.readFile('/slotted-named-functions/index.html');
const $ = cheerio.load(html);
- const beforeDiv = $('div#before');
- const [beforeChildren] = beforeDiv.children('div');
- assert.deepEqual(beforeChildren.firstChild.data, 'Test Content BEFORE');
- const afterDiv = $('div#after');
- const [afterChildren] = afterDiv.children('div');
- assert.deepEqual(afterChildren.firstChild.data, 'Test Content AFTER');
+ const beforeDiv = $('div#before > div');
+ assert.deepEqual(beforeDiv.text(), 'Test Content BEFORE');
+ const afterDiv = $('div#after > div');
+ assert.deepEqual(afterDiv.text(), 'Test Content AFTER');
});
it('Unused slot builds without error', async () => {
diff --git a/packages/astro/test/astro-sync.test.js b/packages/astro/test/astro-sync.test.ts
similarity index 82%
rename from packages/astro/test/astro-sync.test.js
rename to packages/astro/test/astro-sync.test.ts
index eaf1f75bbc46..cf42a7cffc0a 100644
--- a/packages/astro/test/astro-sync.test.js
+++ b/packages/astro/test/astro-sync.test.ts
@@ -1,28 +1,21 @@
-// @ts-check
import assert from 'node:assert/strict';
import * as fs from 'node:fs';
import { beforeEach, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
+import type { AstroLogMessage } from '../dist/core/logger/core.js';
import { AstroLogger } from '../dist/core/logger/core.js';
-import { loadFixture } from './test-utils.js';
+import { type Fixture, loadFixture } from './test-utils.js';
const createFixture = () => {
- /** @type {Awaited>} */
- let astroFixture;
- /** @type {Record} */
- const writtenFiles = {};
- /** @type {Array} */
- const warnLogs = [];
+ let astroFixture: Fixture;
+ const writtenFiles: Record = {};
+ const warnLogs: Array = [];
- /**
- * @param {string} path
- */
- const getExpectedPath = (path) => fileURLToPath(new URL(path, astroFixture.config.root));
+ const getExpectedPath = (path: string) => fileURLToPath(new URL(path, astroFixture.config.root));
return {
- /** @param {string} root */
- async load(root) {
+ async load(root: string) {
astroFixture = await loadFixture({ root });
return astroFixture.config;
},
@@ -32,21 +25,13 @@ const createFixture = () => {
async whenSyncing() {
const fsMock = {
...fs,
- /**
- * @param {fs.PathLike} path
- * @param {string} contents
- */
- writeFileSync(path, contents) {
+ writeFileSync(path: fs.PathLike, contents: string) {
writtenFiles[path.toString()] = contents;
return fs.writeFileSync(path, contents);
},
promises: {
...fs.promises,
- /**
- * @param {fs.PathLike} path
- * @param {string} contents
- */
- writeFile(path, contents) {
+ writeFile(path: fs.PathLike, contents: string) {
writtenFiles[path.toString()] = contents;
return fs.promises.writeFile(path, contents);
},
@@ -71,34 +56,28 @@ const createFixture = () => {
console.error = originalWarn;
}
},
- /** @param {string} path */
- thenFileShouldExist(path) {
+ thenFileShouldExist(path: string) {
assert.equal(
writtenFiles.hasOwnProperty(getExpectedPath(path)),
true,
`${path} does not exist`,
);
},
- /**
- * @param {string} path
- * @param {string} content
- * @param {string | undefined} error
- */
- thenFileContentShouldInclude(path, content, error = undefined) {
+ thenFileContentShouldInclude(
+ path: string,
+ content: string,
+ error: string | undefined = undefined,
+ ) {
assert.equal(writtenFiles[getExpectedPath(path)].includes(content), true, error);
},
- /**
- * @param {string} path
- * @param {string} content
- * @param {string | undefined} error
- */
- thenFileContentShouldNotInclude(path, content, error = undefined) {
+ thenFileContentShouldNotInclude(
+ path: string,
+ content: string,
+ error: string | undefined = undefined,
+ ) {
assert.equal(writtenFiles[getExpectedPath(path)].includes(content), false, error);
},
- /**
- * @param {string} path
- */
- thenFileShouldBeValidTypeScript(path) {
+ thenFileShouldBeValidTypeScript(path: string) {
try {
const content = writtenFiles[getExpectedPath(path)];
const result = ts.transpileModule(content, {
@@ -112,13 +91,10 @@ const createFixture = () => {
`${path} should be valid TypeScript. Output: ${result.outputText}`,
);
} catch (error) {
- assert.fail(`${path} is not valid TypeScript. Error: ${error.message}`);
+ assert.fail(`${path} is not valid TypeScript. Error: ${(error as Error).message}`);
}
},
- /**
- * @param {string} message
- */
- thenWarnLogsInclude(message) {
+ thenWarnLogsInclude(message: string) {
if (warnLogs.length === 0) {
assert.fail('No error log');
}
@@ -129,8 +105,7 @@ const createFixture = () => {
};
describe('astro sync', () => {
- /** @type {ReturnType} */
- let fixture;
+ let fixture: ReturnType;
beforeEach(async () => {
fixture = createFixture();
});
@@ -269,10 +244,7 @@ describe('astro sync', () => {
describe('No content config', () => {
it('Syncs silently without error when content config does not exist', async () => {
- /**
- * @type {import("../dist/core/logger/core.js").AstroLogMessage[]}
- */
- const logs = [];
+ const logs: AstroLogMessage[] = [];
const logger = new AstroLogger({
level: 'debug',
destination: {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e7deedf8b21b..0f97bd5bb8c9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -122,10 +122,10 @@ importers:
devDependencies:
'@codspeed/vitest-plugin':
specifier: 5.2.0
- version: 5.2.0(tinybench@2.9.0)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))(vitest@4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
+ version: 5.2.0(tinybench@2.9.0)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))(vitest@4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)))
vitest:
specifier: ^4.1.0
- version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
+ version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
benchmark/packages/adapter:
dependencies:
@@ -232,7 +232,7 @@ importers:
version: 18.3.1(react@18.3.1)
vitest:
specifier: ^4.1.0
- version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
+ version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
devDependencies:
'@types/react':
specifier: ^18.3.28
@@ -506,7 +506,7 @@ importers:
version: link:../../packages/astro
vitest:
specifier: ^4.1.0
- version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
+ version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
packages/astro:
dependencies:
@@ -697,6 +697,9 @@ importers:
'@types/js-yaml':
specifier: ^4.0.9
version: 4.0.9
+ '@types/parse-srcset':
+ specifier: ^1.0.0
+ version: 1.0.0
'@types/picomatch':
specifier: ^4.0.2
version: 4.0.2
@@ -762,7 +765,7 @@ importers:
version: 11.0.5
vitest:
specifier: ^4.1.0
- version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
+ version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
optionalDependencies:
sharp:
specifier: ^0.34.0
@@ -4245,7 +4248,7 @@ importers:
version: link:../../..
vitest:
specifier: ^4.1.0
- version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
+ version: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
packages/astro/test/fixtures/vue-component:
dependencies:
@@ -9968,6 +9971,9 @@ packages:
'@types/normalize-package-data@2.4.4':
resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==}
+ '@types/parse-srcset@1.0.0':
+ resolution: {integrity: sha512-5ehc1s3aIQJ05ZVAmYoqDUN8zvlrIZvRUfYP+2bhGNzrY5RQBeJS9JO9jpkVm/vSOW/MkRYLArS/fhXY5cgXPg==}
+
'@types/picomatch@4.0.2':
resolution: {integrity: sha512-qHHxQ+P9PysNEGbALT8f8YOSHW0KJu6l2xU8DYY0fu/EmGxXdVnuTLvFUvBgPJMSqXq29SYHveejeAha+4AYgA==}
@@ -15470,6 +15476,7 @@ packages:
'@vitest/ui': 4.1.0
happy-dom: '*'
jsdom: '*'
+ vite: ^6.0.0 || ^7.0.0 || ^8.0.0-0
peerDependenciesMeta:
'@edge-runtime/vm':
optional: true
@@ -16584,12 +16591,12 @@ snapshots:
transitivePeerDependencies:
- debug
- '@codspeed/vitest-plugin@5.2.0(tinybench@2.9.0)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))(vitest@4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))':
+ '@codspeed/vitest-plugin@5.2.0(tinybench@2.9.0)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))(vitest@4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)))':
dependencies:
'@codspeed/core': 5.2.0
tinybench: 2.9.0
vite: 7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
- vitest: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
+ vitest: 4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
transitivePeerDependencies:
- debug
@@ -18875,6 +18882,8 @@ snapshots:
'@types/normalize-package-data@2.4.4': {}
+ '@types/parse-srcset@1.0.0': {}
+
'@types/picomatch@4.0.2': {}
'@types/prismjs@1.26.6': {}
@@ -25326,7 +25335,7 @@ snapshots:
optionalDependencies:
vite: 7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)
- vitest@4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3):
+ vitest@4.1.0(@opentelemetry/api@1.9.0)(@types/node@25.2.3)(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3)):
dependencies:
'@vitest/expect': 4.1.0
'@vitest/mocker': 4.1.0(vite@7.3.1(@types/node@25.2.3)(jiti@2.6.1)(lightningcss@1.32.0)(sass@1.98.0)(tsx@4.21.0)(yaml@2.8.3))
@@ -25352,17 +25361,7 @@ snapshots:
'@opentelemetry/api': 1.9.0
'@types/node': 25.2.3
transitivePeerDependencies:
- - jiti
- - less
- - lightningcss
- msw
- - sass
- - sass-embedded
- - stylus
- - sugarss
- - terser
- - tsx
- - yaml
volar-service-css@0.0.70(@volar/language-service@2.4.28):
dependencies: