diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 632c12e85ba8..bc1d16065495 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -251,9 +251,13 @@ jobs: pnpm run test:language-tools:no-vs cd packages/language-tools/vscode xvfb-run -a pnpm test - # TODO: Figure out why the vscode tests are fine, but the ts-plugin ones are super flaky - # cd ../ts-plugin - # xvfb-run -a pnpm test + + - name: Test ts-plugin (Linux, flaky) + if: runner.os == 'Linux' + timeout-minutes: 10 + working-directory: packages/language-tools/ts-plugin + # TODO: Figure out why the vscode tests are fine, but the ts-plugin ones are super flaky + run: xvfb-run -a pnpm test || echo "::warning title=ts-plugin tests failed::Known flaky; not failing CI." - name: Test if: runner.os != 'Linux' diff --git a/packages/language-tools/ts-plugin/.vscode-test.js b/packages/language-tools/ts-plugin/.vscode-test.mjs similarity index 52% rename from packages/language-tools/ts-plugin/.vscode-test.js rename to packages/language-tools/ts-plugin/.vscode-test.mjs index de1ce81d4b3a..f91e86fbfa36 100644 --- a/packages/language-tools/ts-plugin/.vscode-test.js +++ b/packages/language-tools/ts-plugin/.vscode-test.mjs @@ -1,14 +1,15 @@ -const { defineConfig } = require('@vscode/test-cli'); +import { defineConfig } from '@vscode/test-cli'; -module.exports = defineConfig([ +export default defineConfig([ { label: 'unitTests', - files: 'test/**/*.test.js', + files: 'test/**/*.test.mts', extensionDevelopmentPath: '../vscode', version: 'stable', mocha: { ui: 'tdd', timeout: 20000, + require: ['tsx'], }, }, ]); diff --git a/packages/language-tools/ts-plugin/package.json b/packages/language-tools/ts-plugin/package.json index 0d63cc569265..2890edccff5d 100644 --- a/packages/language-tools/ts-plugin/package.json +++ b/packages/language-tools/ts-plugin/package.json @@ -22,7 +22,8 @@ "scripts": { "build": "tsc", "dev": "tsc --watch", - "test": "vscode-test" + "test": "vscode-test", + "typecheck:tests": "tsc --build tsconfig.test.json" }, "author": "withastro", "license": "MIT", @@ -39,9 +40,11 @@ "@types/mocha": "^10.0.10", "@types/node": "^20.9.0", "@types/semver": "^7.7.1", + "@types/vscode": "^1.92.0", "@vscode/test-cli": "^0.0.12", "@vscode/test-electron": "^2.5.2", "mocha": "^11.7.5", + "tsx": "^4.21.0", "typescript": "^5.9.3", "vscode-uri": "^3.1.0" } diff --git a/packages/language-tools/ts-plugin/test/suite/extension.test.js b/packages/language-tools/ts-plugin/test/suite/extension.test.mts similarity index 80% rename from packages/language-tools/ts-plugin/test/suite/extension.test.js rename to packages/language-tools/ts-plugin/test/suite/extension.test.mts index 08f4ed144ebc..a63b27ff7d99 100644 --- a/packages/language-tools/ts-plugin/test/suite/extension.test.js +++ b/packages/language-tools/ts-plugin/test/suite/extension.test.mts @@ -1,14 +1,19 @@ -const assert = require('node:assert'); -const path = require('node:path'); -const vscode = require('vscode'); +import 'mocha'; +import assert from 'node:assert'; +import path from 'node:path'; +import * as vscode from 'vscode'; suite('Extension Test Suite', () => { vscode.window.showInformationMessage('Start all tests.'); // TypeScript takes a while to wake up and there's unfortunately no good way to wait for it - async function waitForTS(command, commandArgs, condition) { + async function waitForTS( + command: string, + commandArgs: unknown[], + condition: (result: T) => boolean, + ): Promise { for (let i = 0; i < 2000; i++) { - const commandResult = await vscode.commands.executeCommand(command, ...commandArgs); + const commandResult = await vscode.commands.executeCommand(command, ...commandArgs); if (condition(commandResult)) { return commandResult; } @@ -24,7 +29,7 @@ suite('Extension Test Suite', () => { vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts')), ); - const references = await waitForTS( + const references = await waitForTS( 'vscode.executeReferenceProvider', [doc.uri, new vscode.Position(0, 18)], (result) => result.length > 1, @@ -39,7 +44,7 @@ suite('Extension Test Suite', () => { vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts')), ); - const completions = await waitForTS( + const completions = await waitForTS( 'vscode.executeCompletionItemProvider', [doc.uri, new vscode.Position(4, 12)], (result) => result.items.length > 0, @@ -56,7 +61,7 @@ suite('Extension Test Suite', () => { vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts')), ); - const implementations = await waitForTS( + const implementations = await waitForTS( 'vscode.executeImplementationProvider', [doc.uri, new vscode.Position(6, 15)], (result) => result.length > 1, diff --git a/packages/language-tools/ts-plugin/tsconfig.test.json b/packages/language-tools/ts-plugin/tsconfig.test.json new file mode 100644 index 000000000000..3ad1bbfc413f --- /dev/null +++ b/packages/language-tools/ts-plugin/tsconfig.test.json @@ -0,0 +1,13 @@ +{ + "extends": "../../../tsconfig.base.json", + "include": ["test/**/*.mts", "test/**/*.ts", ".vscode-test.*"], + "exclude": ["test/fixtures/**"], + "compilerOptions": { + "types": ["node"], + "allowJs": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "rewriteRelativeImportExtensions": true + }, + "references": [{ "path": "../../astro/tsconfig.test.json" }] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79f4ab078724..9d30ea87eb30 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6690,6 +6690,9 @@ importers: '@types/semver': specifier: ^7.7.1 version: 7.7.1 + '@types/vscode': + specifier: ^1.92.0 + version: 1.109.0 '@vscode/test-cli': specifier: ^0.0.12 version: 0.0.12 @@ -6699,6 +6702,9 @@ importers: mocha: specifier: ^11.7.5 version: 11.7.5 + tsx: + specifier: ^4.21.0 + version: 4.21.0 typescript: specifier: ^5.9.3 version: 5.9.3