diff --git a/packages/astro/test/fixtures/astro-typescript/.gitignore b/packages/astro/test/fixtures/astro-typescript/.gitignore new file mode 100644 index 0000000000..bfe3b8d326 --- /dev/null +++ b/packages/astro/test/fixtures/astro-typescript/.gitignore @@ -0,0 +1 @@ +tsconfig.json \ No newline at end of file diff --git a/packages/astro/test/fixtures/astro-typescript/astro.config.mjs b/packages/astro/test/fixtures/astro-typescript/astro.config.mjs new file mode 100644 index 0000000000..882e6515a6 --- /dev/null +++ b/packages/astro/test/fixtures/astro-typescript/astro.config.mjs @@ -0,0 +1,4 @@ +import { defineConfig } from 'astro/config'; + +// https://astro.build/config +export default defineConfig({}); diff --git a/packages/astro/test/fixtures/astro-typescript/package.json b/packages/astro/test/fixtures/astro-typescript/package.json new file mode 100644 index 0000000000..65199bbe88 --- /dev/null +++ b/packages/astro/test/fixtures/astro-typescript/package.json @@ -0,0 +1,8 @@ +{ + "name": "@test/astro-typescript", + "version": "0.0.0", + "private": true, + "dependencies": { + "astro": "workspace:*" + } +} diff --git a/packages/astro/test/fixtures/astro-typescript/src/.gitkeep b/packages/astro/test/fixtures/astro-typescript/src/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/astro/test/typescript.test.js b/packages/astro/test/typescript.test.js new file mode 100644 index 0000000000..ee1d9006ea --- /dev/null +++ b/packages/astro/test/typescript.test.js @@ -0,0 +1,63 @@ +// @ts-check +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; +import { loadFixture } from './test-utils.js'; +import { fileURLToPath } from 'node:url'; +import { existsSync, rmSync } from 'node:fs'; + +/** + * + * @param {Omit} config + * @returns + */ +const createFixture = async (config = {}) => { + /** @type {Awaited>} */ + const astroFixture = await loadFixture({ root: './fixtures/astro-typescript/', ...config }); + const { root } = astroFixture.config; + const stringRoot = fileURLToPath(root); + rmSync(new URL('./tsconfig.json', root), { force: true }); + rmSync(new URL('./src/env.d.ts', root), { force: true }); + rmSync(new URL('./.astro', root), { force: true, recursive: true }); + + return { + sync: () => astroFixture.sync({ root: stringRoot }), + /** @param {string} path */ + fileExists: (path) => { + return existsSync(new URL(path, root)); + }, + }; +}; + +describe('experimental.typescript', () => { + it('should create .astro/tsconfig.json if experimental.typescript is enabled', async () => { + const fixture = await createFixture({ experimental: { typescript: {} } }); + await fixture.sync(); + assert.equal(fixture.fileExists('./.astro/tsconfig.json'), true); + }); + + it('should not create src/env.d.ts if experimental.typescript is enabled', async () => {}); + + it('should not create .astro/tsconfig.json if experimental.typescript is disabled', async () => {}); + + it('should create src/env.d.ts if experimental.typescript is disabled', async () => {}); + + it('should throw if tsconfig.json has invalid extends', async () => {}); + + it('should throw if tsconfig.json has invalid include', async () => {}); + + it('should throw if tsconfig.json has invalid exclude', async () => {}); + + it('should add outDir to .astro/tsconfig.json', async () => {}); + + it('should handle include/exclude relative paths', async () => {}); + + it('should work with astro check', async () => {}); + + it('should work in dev', async () => {}); + + it('should work in build', async () => {}); + + it('should work in sync', async () => {}); + + it('should create a tsconfig.json if it does not exist yet', async () => {}); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4563fdae50..e37cdd8ade 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2457,6 +2457,12 @@ importers: specifier: ^3.4.38 version: 3.4.38(typescript@5.5.4) + packages/astro/test/fixtures/astro-typescript: + dependencies: + astro: + specifier: workspace:* + version: link:../../.. + packages/astro/test/fixtures/before-hydration: dependencies: '@astrojs/preact':