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
7 changes: 7 additions & 0 deletions .github/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"allowJs": true
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
run: pnpm run publint

- name: Type-check test files
run: pnpm -C packages/astro run typecheck:tests
run: pnpm run typecheck:tests

test:
name: 'Test (${{ matrix.TEST_SUITE.name }}): ${{ matrix.os }} (node@${{ matrix.NODE_VERSION }})'
Expand Down
2 changes: 1 addition & 1 deletion knip.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-check
const testEntry = 'test/**/*.test.js';
const testEntry = 'test/**/*.test.{js,ts}';

/** @type {import('knip').KnipConfig} */
export default {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"test:e2e": "cd packages/astro && pnpm playwright install firefox && pnpm run test:e2e",
"test:e2e:match": "cd packages/astro && pnpm playwright install firefox && pnpm run test:e2e:match",
"test:e2e:hosts": "turbo run test:hosted",
"typecheck:tests": "pnpm -r typecheck:tests",
"benchmark": "astro-benchmark",
"lint": "biome lint && knip && eslint . --report-unused-disable-directives-severity=warn --concurrency=auto",
"lint:ci": "knip && pnpm run eslint:ci",
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
"test:e2e:match": "playwright test -g",
"test:e2e:chrome": "playwright test",
"test:e2e:firefox": "playwright test --config playwright.firefox.config.js",
"test:types": "tsc --project test/types/tsconfig.json",
"typecheck:tests": "tsc --project tsconfig.test.json",
"test:types": "tsc --build test/types/tsconfig.json",
"typecheck:tests": "tsc --build tsconfig.test.json",
"test:unit": "astro-scripts test \"test/units/**/*.test.ts\" --strip-types --teardown ./test/units/teardown.ts",
"test:integration": "pnpm run test:integration:js && pnpm run test:integration:ts",
"test:integration:js": "astro-scripts test \"test/*.test.js\"",
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/types/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, it } from 'node:test';
import { expectTypeOf } from 'expect-type';
import type * as z from 'zod/v4';
import { type FontProviderSchema, FontFamilySchema } from '../../src/assets/fonts/config.js';
import type { FontProvider, FontFamily } from '../../src/assets/fonts/types.js';
import type { CacheSchema, RouteRulesSchema } from '../../src/core/cache/config.js';
import { type FontProviderSchema, FontFamilySchema } from '../../dist/assets/fonts/config.js';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, we were using src because zod could cause some issues. If that's not the case anymore, I'm glad!

import type { FontProvider, FontFamily } from '../../dist/assets/fonts/types.js';
import type { CacheSchema, RouteRulesSchema } from '../../dist/core/cache/config.js';
import type { CacheProviderConfig, RouteRules } from '../../dist/core/cache/types.js';
import type { SessionDriverConfigSchema } from '../../dist/core/session/config.js';
import type { SessionDriverConfig } from '../../dist/core/session/types.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"allowJs": true,
"emitDeclarationOnly": false,
"noEmit": true
"emitDeclarationOnly": false
}
}
2 changes: 2 additions & 0 deletions packages/astro/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"include": ["src", "dev-only.d.ts"],
"exclude": ["dist"],
"compilerOptions": {
"composite": true,
"rootDir": "./src",
"allowJs": true,
"declarationDir": "./dist",
"outDir": "./dist",
"jsx": "preserve",
"tsBuildInfoFile": "${configDir}/dist/._cache/tsconfig/tsbuildinfo.json",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that ._cache won't be published to NPM.

https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files

I put the tsbuildinfo.json under dist/ so that developers can more easily remove the dist/ to clean both the built .d.ts files and the cached index file tsbuildinfo.json.

"erasableSyntaxOnly": true
}
}
24 changes: 21 additions & 3 deletions packages/astro/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
{
"extends": "../../tsconfig.base.json",
"include": ["test/units/**/*.ts"],
"include": [
"test/units/**/*.ts",
"test/test-adapter.js",
"test/test-image-service.js",
"test/test-plugins.js",
"test/test-prerenderer.js",
"test/test-remote-image-service.js",
"test/test-utils.js",
"package.json"
],
"exclude": ["test/units/_temp-fixtures/**", "test/fixtures/**"],
"compilerOptions": {
"noEmit": true,
"types": ["vite/client", "node"],
"composite": true,
"allowJs": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"rewriteRelativeImportExtensions": true
}
},
"references": [
{
"path": "./tsconfig.json"
},
{
"path": "../../scripts/tsconfig.json"
}
]
}
3 changes: 2 additions & 1 deletion packages/integrations/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"",
"test": "astro-scripts test \"test/**/*.test.js\""
"test": "astro-scripts test \"test/**/*.test.ts\"",
"typecheck:tests": "tsc --build tsconfig.test.json"
},
"dependencies": {
"@astrojs/internal-helpers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test.describe('React 19 SSR integration', () => {
const fixture = await loadFixture({
root: new URL('./fixtures/react-19-preloads/', import.meta.url),
});
await fixture.build();
await fixture.build({});

const html = await fixture.readFile('/index.html');
const islandPattern = /<astro-island[^>]*>([\s\S]*?)<\/astro-island>/;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import { isWindows, loadFixture } from '../../../astro/test/test-utils.js';
import {
isWindows,
loadFixture,
type Fixture,
type DevServer,
} from '../../../astro/test/test-utils.js';

let fixture;
let fixture: Fixture;

describe('React Components', () => {
before(async () => {
Expand All @@ -14,7 +19,7 @@ describe('React Components', () => {

describe('build', () => {
before(async () => {
await fixture.build();
await fixture.build({});
});

it('Can load React', async () => {
Expand Down Expand Up @@ -144,8 +149,7 @@ describe('React Components', () => {
if (isWindows) return;

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

before(async () => {
devServer = await fixture.startDevServer();
Expand All @@ -156,7 +160,8 @@ describe('React Components', () => {
});

it('scripts proxy correctly', async () => {
const html = await fixture.fetch('/').then((res) => res.text());
const response = await fixture.fetch('/');
const html: string = await response.text();
const $ = cheerioLoad(html);

for (const script of $('script').toArray()) {
Expand All @@ -168,9 +173,10 @@ describe('React Components', () => {

// TODO: move this to separate dev test?
it.skip('Throws helpful error message on window SSR', async () => {
const html = await fixture.fetch('/window/index.html');
const response = await fixture.fetch('/window/index.html');
const html: string = await response.text();
assert.ok(
(await html.text()).includes(
html.includes(
`[/window]
The window object is not available during server-side rendering (SSR).
Try using \`import.meta.env.SSR\` to write SSR-friendly code.
Expand All @@ -181,19 +187,26 @@ describe('React Components', () => {

// In moving over to Vite, the jsx-runtime import is now obscured. TODO: update the method of finding this.
it.skip('uses the new JSX transform', async () => {
const html = await fixture.fetch('/index.html');
const response = await fixture.fetch('/index.html');
const html: string = await response.text();

// Grab the imports
const exp = /import\("(.+?)"\)/g;
let match, componentUrl;
let match, componentUrl: string | undefined;
while ((match = exp.exec(html))) {
if (match[1].includes('Research.js')) {
componentUrl = match[1];
break;
}
}
if (!componentUrl) {
throw new Error('Could not find component URL in HTML');
}

const component = await fixture.readFile(componentUrl);
const jsxRuntime = component.imports.filter((i) => i.specifier.includes('jsx-runtime'));
// @ts-expect-error: error TS2339: Property 'imports' does not exist on type 'string'.
const imports = component.imports;
const jsxRuntime = imports.filter((i: any) => i.specifier.includes('jsx-runtime'));
Comment thread
ematipico marked this conversation as resolved.

// test 1: react/jsx-runtime is used for the component
assert.ok(jsxRuntime);
Expand Down
17 changes: 17 additions & 0 deletions packages/integrations/react/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../../tsconfig.base.json",
"include": ["test/**/*.ts"],
"exclude": ["test/fixtures/**"],
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"rewriteRelativeImportExtensions": true
},
"references": [
{
"path": "../../astro/tsconfig.test.json"
}
]
}
12 changes: 0 additions & 12 deletions scripts/jsconfig.json

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/testing/github-test-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default new Transform({
file: event.data.file,
line: event.data.line,
column: event.data.column,
isSuite: event.data.details.type !== 'test',
isSuite: event.data.details.type === 'suite',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited this line because somehow astro is still using @types/node v18, which doesn't contain 'test' for this field.

cat node_modules/@types/node/package.json | jq '.version'
"18.19.130"

We should update @types/node, but that's out of the scope of this PR.

});
break;
}
Expand Down
12 changes: 12 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"allowJs": true
},
"references": [
{
"path": "../.github/scripts/tsconfig.json"
}
]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"outDir": "${configDir}/node_modules/.cache/tsconfig/out",
"types": ["node"]
}
}
Loading