Skip to content

Add first set of extension tests - #503

Merged
thomasp85 merged 19 commits into
mainfrom
feat/add-extension-tests
Aug 3, 2026
Merged

Add first set of extension tests#503
thomasp85 merged 19 commits into
mainfrom
feat/add-extension-tests

Conversation

@juliasilge

Copy link
Copy Markdown
Member

This PR adds the first automated test suite for the extension ggsql-vscode, plus a GitHub Actions workflow to run it. It has 20 tests across four files, 27 TextMate scope assertions, and a Testing section in ggsql-vscode/CLAUDE.md.

The tests depend on one of the fixes from #502 FYI.

The extension as stock VS Code sees it:

Area Tests
Activation, language resolution, command gating 4
parseCells cell splitting 7
.sql attachment gating (isGgsqlDocument) 5
CodeLens placement 4
TextMate scopes 27 assertions

This does not include anything that needs a Positron host (the language runtime manager, the Connections pane drivers, and cell execution. Also sqlAssociation.ts, manager.ts and connections.ts). I'll add that in a second step after our next release, when we'll have Linux builds for test runners.

I checked every test by breaking the code it covers and confirming it goes red, not just by watching the suite go green. A whole-suite scrutiny pass then re-ran independent mutations across all 20. IMO that kind of thing is worth doing, especially with AI-generated code and tests, which can be really low value sometimes.

Findings about the extension itself

Two things surfaced that are not test problems:

  • The comment in cellParser.ts claimed a marker-free document is treated as one cell. It is not; parseCells returns no cells at all, and the whole-document fallback lives in extension.ts. Comment corrected in its own commit.
  • sqlFilesEnabled()'s true fallback argument is unreachable. package.json already declares a default for ggsql.enableSqlFiles, and VS Code resolves .get() against the registered schema default first. Documented in place for now, no behaviour change.

Test infrastructure

Two runners behind npm test:

  • @vscode/test-cli drives a real VS Code instance for anything needing the vscode API. CI wraps it in xvfb-run.
  • vscode-tmgrammar-test checks TextMate scopes in plain Node, so npm run test:grammar is a roughly one second loop with no Electron.

Tests compile to out-test/ via a dedicated tsconfig.test.json, deliberately not to out/, which esbuild.js owns. Emitting both to out/ would have meant the test build overwriting the extension bundle.

The Mocha timeout is set to 5s, matching what I have found works well for the Quarto extension's suite.

npm run lint, npm run check-types and npm test are clean, with 20 passing plus the grammar fixture. A clean rm -rf node_modules && npm ci && npm test also passes, which is the closest local approximation of the CI run.

@juliasilge
juliasilge requested a review from thomasp85 August 3, 2026 14:40

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THANKS!

@thomasp85
thomasp85 merged commit 9fe6721 into main Aug 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants