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
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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'],
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.

We use @vscode/test-cli to run the test, which is based on mocha. I need require: ['tsx'] in order to run typescript test files in mocha.

},
},
]);
5 changes: 4 additions & 1 deletion packages/language-tools/ts-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>(
command: string,
commandArgs: unknown[],
condition: (result: T) => boolean,
): Promise<T> {
for (let i = 0; i < 2000; i++) {
const commandResult = await vscode.commands.executeCommand(command, ...commandArgs);
const commandResult = await vscode.commands.executeCommand<T>(command, ...commandArgs);
if (condition(commandResult)) {
return commandResult;
}
Expand All @@ -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.Location[]>(
'vscode.executeReferenceProvider',
[doc.uri, new vscode.Position(0, 18)],
(result) => result.length > 1,
Expand All @@ -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.CompletionList>(
'vscode.executeCompletionItemProvider',
[doc.uri, new vscode.Position(4, 12)],
(result) => result.items.length > 0,
Expand All @@ -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.Location[]>(
'vscode.executeImplementationProvider',
[doc.uri, new vscode.Position(6, 15)],
(result) => result.length > 1,
Expand Down
13 changes: 13 additions & 0 deletions packages/language-tools/ts-plugin/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -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" }]
}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading