Skip to content

Commit

Permalink
Add TypeScript tests to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Jul 12, 2024
1 parent eb4f9dc commit 2e155d9
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 12 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
**/.venv/
**/__pycache__/
**/dist/
**/out/
**/node_modules/
*.vsix
*.pyc
/bundled/libs/
.vscode-test/
.vscode-test/
out/
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
**/.venv/
**/__pycache__/
**/dist/
**/out/
**/node_modules/
*.vsix
*.pyc
.mypy_cache/**
/bundled/libs/
.vscode-test/
out/
3 changes: 2 additions & 1 deletion .vscode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = defineConfig({
workspaceFolder: "./src/testFixture",
mocha: {
ui: "tdd",
timeout: 10000,
color: true,
timeout: 20000,
},
});
2 changes: 2 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ requirements.txt
scripts/
src/
tests/
out/
.vscode-test/
tsconfig.json
webpack.config.js
11 changes: 9 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 11 additions & 2 deletions src/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand All @@ -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) => {
Expand Down
6 changes: 5 additions & 1 deletion src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"target": "ES2020",
"lib": ["ES2020"],
"sourceMap": true,
"outDir": "out",
"rootDir": "src",
"strict": true,
"noImplicitReturns": true,
Expand Down

0 comments on commit 2e155d9

Please sign in to comment.