From 2e155d910926f4daa2169ff0fd5646214c690680 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 12 Jul 2024 12:19:46 +0530 Subject: [PATCH] Add TypeScript tests to CI --- .github/workflows/ci.yaml | 23 +++++++++++++++++++++++ .gitignore | 4 ++-- .prettierignore | 2 +- .vscode-test.js | 3 ++- .vscodeignore | 2 ++ justfile | 11 +++++++++-- package.json | 6 ++++-- src/test/e2e.test.ts | 13 +++++++++++-- src/test/helper.ts | 6 +++++- tsconfig.json | 1 - 10 files changed, 59 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 82b2c4d..e292571 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,3 +30,26 @@ jobs: run: just check - name: Run tests run: just test + + ts-tests: + name: TypeScript Tests + runs-on: ubuntu-latest + env: + UV_SYSTEM_PYTHON: 1 + steps: + - uses: extractions/setup-just@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/setup-python@v5 + with: + python-version: "3.7" + - uses: hynek/setup-cached-uv@v1 + - uses: actions/checkout@v4 + - name: Install bundled dependencies + run: just setup + - name: Install Node dependencies + run: npm ci + - name: Compile tests + run: npm run pretest + - name: Run tests + run: xvfb-run npm run tests diff --git a/.gitignore b/.gitignore index 2759032..c3cdeb6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,9 @@ **/.venv/ **/__pycache__/ **/dist/ -**/out/ **/node_modules/ *.vsix *.pyc /bundled/libs/ -.vscode-test/ \ No newline at end of file +.vscode-test/ +out/ \ No newline at end of file diff --git a/.prettierignore b/.prettierignore index b64d023..2eb0c21 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,10 +4,10 @@ **/.venv/ **/__pycache__/ **/dist/ -**/out/ **/node_modules/ *.vsix *.pyc .mypy_cache/** /bundled/libs/ .vscode-test/ +out/ diff --git a/.vscode-test.js b/.vscode-test.js index 0a94563..8d66ddd 100644 --- a/.vscode-test.js +++ b/.vscode-test.js @@ -5,6 +5,7 @@ module.exports = defineConfig({ workspaceFolder: "./src/testFixture", mocha: { ui: "tdd", - timeout: 10000, + color: true, + timeout: 20000, }, }); diff --git a/.vscodeignore b/.vscodeignore index f59cf1e..f759af6 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -23,5 +23,7 @@ requirements.txt scripts/ src/ tests/ +out/ +.vscode-test/ tsconfig.json webpack.config.js diff --git a/justfile b/justfile index 3b518fd..1646ab1 100755 --- a/justfile +++ b/justfile @@ -15,8 +15,9 @@ install: test: setup python -m unittest -e2e-test: install - npm run test +e2e-tests: setup + npm run pretest + npm run tests check: ruff check ./bundled/tool ./build ./tests @@ -34,3 +35,9 @@ fmt: build-package: setup npm ci npm run vsce-package + +clean: + rm -rf out + rm -rf node_modules + rm -rf .vscode-test + rm -rf bundled/libs diff --git a/package.json b/package.json index 93f412b..db5a92a 100644 --- a/package.json +++ b/package.json @@ -63,13 +63,15 @@ "fmt": "prettier -w .", "fmt-check": "prettier --check .", "lint": "eslint src --ext ts", - "compile": "tsc", + "compile": "webpack", + "compile-tests": "tsc -p . --outDir out", "tsc": "tsc --noEmit", "package": "webpack --mode production --devtool source-map --config ./webpack.config.js", "watch": "webpack --watch", "vsce-package": "vsce package -o ruff.vsix", "vscode:prepublish": "npm run package", - "test": "npm run compile && vscode-test" + "pretest": "npm run compile-tests && npm run compile", + "tests": "vscode-test" }, "contributes": { "configuration": { diff --git a/src/test/e2e.test.ts b/src/test/e2e.test.ts index d0b15ed..924e928 100644 --- a/src/test/e2e.test.ts +++ b/src/test/e2e.test.ts @@ -3,6 +3,8 @@ import * as assert from "assert"; import { getDocumentUri, activateExtension, sleep } from "./helper"; suite("E2E tests", () => { + const TIMEOUT = 5000; + teardown(async () => { await vscode.commands.executeCommand("workbench.action.closeAllEditors"); }); @@ -14,16 +16,23 @@ suite("E2E tests", () => { const document = await vscode.workspace.openTextDocument(documentUri); await vscode.window.showTextDocument(document); + const editor = vscode.window.activeTextEditor; + assert.ok(editor, "No active text editor"); + assert.ok( + editor.document.uri.fsPath.endsWith("diagnostics.py"), + "Active text editor is not diagnostics.py", + ); + let actualDiagnostics = vscode.languages.getDiagnostics(documentUri); if (actualDiagnostics.length === 0) { // Wait for diagnostics to be computed - let timeout = 1000; + let timeout = TIMEOUT; while (actualDiagnostics.length === 0 && timeout > 0) { await sleep(100); actualDiagnostics = vscode.languages.getDiagnostics(documentUri); timeout -= 100; } - assert.ok(actualDiagnostics.length > 0, "No diagnostics provided in 1 second"); + assert.ok(actualDiagnostics.length > 0, `No diagnostics provided in ${TIMEOUT}ms`); } actualDiagnostics = actualDiagnostics.sort((a, b) => { diff --git a/src/test/helper.ts b/src/test/helper.ts index 0d5a07e..94526c7 100644 --- a/src/test/helper.ts +++ b/src/test/helper.ts @@ -8,7 +8,11 @@ export async function activateExtension() { if (extension === undefined) { throw new Error(`Extension ${EXTENSION_ID} not found`); } - await extension.activate(); + try { + await extension.activate(); + } catch (e) { + console.error(`Failed to activate the extension: ${e}`); + } } export async function sleep(ms: number) { diff --git a/tsconfig.json b/tsconfig.json index 9340bb0..2d6a0d2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,6 @@ "target": "ES2020", "lib": ["ES2020"], "sourceMap": true, - "outDir": "out", "rootDir": "src", "strict": true, "noImplicitReturns": true,