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
70 changes: 70 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Run Tests

on:
pull_request:
branches: [main]
push:
branches: [main]

concurrency:
group: test-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
python-tests:
name: Python tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Install uv
uses: astral-sh/setup-uv@v9.0.0
with:
enable-cache: true
python-version: '3.13'

- name: Install extension's bundled Python dependencies
run: uv pip install --target bundled/libs -r pyproject.toml

- name: Install dev dependencies
run: uv sync

- name: Run Python tests
run: uv run pytest src/test/python_tests -v

extension-tests:
name: Extension (TypeScript) tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Install pnpm
uses: pnpm/action-setup@v6
with:
version: 10

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: '24'
cache: 'pnpm'

- name: Install JavaScript dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm run lint

- name: Check formatting
run: pnpm run format-check

- name: Compile extension
run: pnpm run compile

- name: Compile tests
run: pnpm run compile-tests

- name: Run extension tests
# @vscode/test-electron launches a real (headless) VS Code instance,
# which needs a virtual display on Linux runners.
run: xvfb-run -a pnpm test
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
### 🐛 Bug fixes

- Updated publisher name from `<david-yz-liu>` to `david-yz-liu`
- Fixed `substitute_attr` in the bundled language server not restoring the original value when the wrapped code raised an exception

### 🔧 Internal changes

- Removed unused `nox` dependency
- Improved test infrastructure: fixed and expanded Python tests, added Typescript extension tests (using Mocha + `@vscode/test-electron`), and added GitHub Actions workflow to run tests
- Removed unused glob pattern `'build/**/*.yml'` from `package.json` `format-check` command
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ If you want to avoid this during testing, and you do not need breakpoints, launc

### Running tests

To run the Python tests, run `uv run pytest src/test/python_tests`.
To run the Python (language server) tests, run `uv run pytest src/test/python_tests`.

To run the extension's TypeScript tests, run `pnpm test`. This compiles the extension and its
tests, downloads a copy of VS Code (cached under `.vscode-test/` after the first run), installs
the `ms-python.python` extension dependency into that test profile, and runs the suite in a real
(headless-capable) Extension Development Host. On Linux, this requires a display server, e.g. run
it as `xvfb-run -a pnpm test`.

Both test suites also run automatically in CI on every pull request and push to `main`; see
`.github/workflows/test.yml`.

## Linting

Expand Down
6 changes: 4 additions & 2 deletions bundled/tool/lsp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def substitute_attr(obj: Any, attribute: str, new_value: Any):
"""Manage object attributes context when using runpy.run_module()."""
old_value = getattr(obj, attribute)
setattr(obj, attribute, new_value)
yield
setattr(obj, attribute, old_value)
try:
yield
finally:
setattr(obj, attribute, old_value)


@contextlib.contextmanager
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "pnpm run compile-tests && pnpm run compile && pnpm run lint",
"lint": "eslint src",
"format-check": "prettier --check 'src/**/*.ts' 'build/**/*.yml' '.github/**/*.yml'",
"format-check": "prettier --check src/**/*.ts .github/**/*.yml",
"format": "prettier --write src/**/*.ts .github/**/*.yml",
"test": "node ./out/test/runTest.js",
"vsce-package": "vsce package -o python-ta.vsix"
},
Expand Down Expand Up @@ -157,6 +158,7 @@
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/glob": "^9.0.0",
"@types/mocha": "^10.0.10",
"@types/node": "20.x",
"@types/vscode": "1.78.0",
"@typescript-eslint/eslint-plugin": "^8.62.1",
Expand All @@ -165,6 +167,7 @@
"@vscode/vsce": "^3.7.1",
"eslint": "^10.3.0",
"glob": "^13.0.6",
"mocha": "^11.8.0",
"prettier": "^3.8.3",
"ts-loader": "^9.6.2",
"typescript": "^6.0.3",
Expand Down
Loading