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
44 changes: 44 additions & 0 deletions .github/workflows/test-extension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test Extension

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

jobs:
# Runs the suite against stock VS Code. A sibling job will run the same
# extension against Positron, which covers the language runtime, connection
# drivers and cell execution that stock VS Code cannot reach.
test-extension:
runs-on: ubuntu-latest
name: Test (VS Code)
defaults:
run:
working-directory: ggsql-vscode

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: ggsql-vscode/package-lock.json

- name: Install XVFB
# The extension tests drive a real VS Code instance, which needs a
# display. The grammar tests do not, but run under the same command.
run: sudo apt-get -y update && sudo apt-get -y install xvfb

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Run tests
run: xvfb-run -a npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ ggsql.Rcheck/
*.dmg
*.AppImage
.cargo-packager/

# Superpowers SDD scratch (ledger, briefs, review packages)
.superpowers/
2 changes: 2 additions & 0 deletions ggsql-vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
out
out-test
.vscode-test/
6 changes: 6 additions & 0 deletions ggsql-vscode/.vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out-test/test/**/*.test.js',
mocha: { timeout: 5000 },
});
3 changes: 3 additions & 0 deletions ggsql-vscode/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.yarnrc
vsc-extension-quickstart.md
**/tsconfig.json
tsconfig.test.json
**/.eslintrc.json
**/*.map
**/*.ts
Expand All @@ -15,3 +16,5 @@ esbuild.js
out/**/*.map
package-lock.json
*.vsix
out-test/**
.vscode-test.mjs
31 changes: 30 additions & 1 deletion ggsql-vscode/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ ggsql-vscode/
│ ├── codelens.ts "▶ Run cell" lens above each cell
│ ├── decorations.ts Cell separator decorations
│ ├── context.ts Sets editor context keys (e.g. ggsql.hasCodeCells)
│ └── types.ts Shared interfaces
│ ├── sqlAssociation.ts One-time notice pointing at files.associations for .sql highlighting
│ ├── types.ts Shared interfaces
│ └── test/ Mocha suites (unit + activation) and the grammar fixture
├── syntaxes/
│ └── ggsql.tmLanguage.json TextMate grammar (used for tokenization in VS Code)
├── examples/ Sample .ggsql files
Expand Down Expand Up @@ -119,6 +121,33 @@ code --install-extension ggsql-<version>.vsix

Watch mode for development: `npm run watch` (runs esbuild + tsc in parallel).

## Testing

```sh
cd ggsql-vscode
npm test # grammar scopes, then the VS Code suites
npm run test:grammar # TextMate scopes only; no Electron, fast
npm run test:extension
```

Tests live in `src/test/` and compile to `out-test/` via `tsconfig.test.json`, deliberately not to `out/`, which `esbuild.js` owns. The whole of `src/` compiles there, not just `src/test/`, because the unit tests import the extension's own modules. `@vscode/test-cli` launches a real VS Code instance, so a window appears while the suites run; CI wraps the same command in `xvfb-run`.

Note that `tsc` does not prune output for deleted sources: if you delete or rename a test, remove its `.js` and `.js.map` from `out-test/test/` or the runner keeps executing the stale copy. `npm run test:extension` on its own does not recompile, so run `npm test` (or `npm run compile-tests` first) after editing any `.ts`.

The suites cover the extension as stock VS Code sees it: activation, language resolution, cell parsing, `.sql` gating, CodeLens placement and TextMate scopes. The Positron surface (runtime manager, connection drivers, cell execution) is not covered, since it needs a Positron host. `sqlAssociation.ts`, `manager.ts` and `connections.ts` are also untested.

Add new tests as `src/test/<name>.test.ts`; no config change is needed.

### Editing the grammar fixture

`src/test/grammar/highlight.gsql` uses `vscode-tmgrammar-test`'s annotation format, which has three rules worth knowing before you touch it:

- The header must be exactly `-- SYNTAX TEST "source.ggsql"`. A trailing `>>`, which some examples show, makes the tool reject the file with a parse error rather than an assertion failure.
- A `^` caret's column is the comment token length plus its index in the assertion line, matched against the source line's 0-based columns. Carets therefore cannot target source columns 0 and 1, which is why the `<---` form exists for line-initial tokens.
- For `<---`, the dash count sets the assertion's right edge from column 0. It must be at least 1 and no more than the target token's length, so it is not cosmetic.

Assertion lines are stripped before tokenization, so they never tokenize as ggsql comments.

## See also

- [`/CLAUDE.md`](../CLAUDE.md) — workspace overview.
Expand Down
Loading
Loading