Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing

Test Suites

All tests live under src/test/suite/ and use Mocha in TDD mode (suite / test).

FileKindWhat it covers
type-analyzer.test.tsUnitMonomorphic/polymorphic detection, edge cases
code-generator.test.tsUnitWrapper generation, port annotations, DiffClock handling
manifest-frequency.test.tsUnitWhich clock domain sets the P&R target frequency
diagram-tabs.test.tsUnitDiagrams reuse one preview tab; pinned ones are kept
gitignore.test.tsUnitWhen the .clash/ gitignore offer is made and what it writes
run-history.test.tsUnitReading past runs off disk; which directories count as history
contributions.test.tsUnitpackage.json contributions match what the extension registers
synthesis-features.test.tsUnitCommands, configuration, synthesis types
synthesis-targets.test.tsUnitTarget registry, default/resolved scripts, script diffing, and that the installed Yosys supports every offered target
parallelism.test.tsUnitJob-count resolution shared by the cabal/GHC/Yosys/nextpnr *Jobs settings
settings-panel.test.tsUnitThe settings panel’s embedded webview script parses and its custom-script keys resolve
code-actions.test.tsUnitCode action provider for Haskell functions
platform-tools.test.tsUnitYosys/nextpnr tool detection
tool-provider.test.tsUnitManaged toolchain resolution and install paths
toolchain.test.tsUnitFull toolchain availability
clash-compiler.test.tsUnitClash compiler invocation helpers
nextpnr-runner.test.tsUnitnextpnr child-process lifecycle
results-tree.test.tsUnitResults tree construction
clash-tree.test.tsUnitSidebar sections and routing to their providers
functions-tree.test.tsUnitThe Functions section’s empty states: HLS missing, working, or done
internal-components.test.tsUnitInternal component expansion
netlist-renderer.test.tsUnitnetlistsvg-based diagram rendering
packaging.test.tsUnitWhat vsce would package: deny list, required files
spawn-options.test.tsUnitEvery external-tool spawn passes windowsHide, so no console window flashes on Windows
pnr-targets.test.tsIntegrationEnd-to-end synthesis + place & route per target
ooc-blackbox.test.tsIntegrationOut-of-context scripts stub sub-components as black boxes; a real Yosys run proves they survive
hls-client.test.tsIntegrationHLS communication
function-detector.test.tsIntegrationFunction detection from real Haskell files via HLS
integration.test.tsIntegrationPer-module synthesis, target frequency, end-to-end flows

Running Tests

From the terminal

npm test

This compiles first (via pretest) and then launches a headless VS Code instance against test-project/.

runTest.ts handles the two environment problems that used to make this fail:

  • NixOS / headless hosts. Set VSCODE_EXECUTABLE_PATH to a nix-wrapped Electron binary (e.g. from vscode-fhs) if the downloaded VS Code build cannot find its system libraries. Leave it unset to let @vscode/test-electron download a matching build. It must be a real Electron binary, not the code CLI wrapper — the wrapper backgrounds the app and exits 0, so the test host never runs.
  • Running from VS Code’s integrated terminal. The parent editor leaks ELECTRON_RUN_AS_NODE=1 and a set of VSCODE_* variables that would make the test host run as plain Node or attach to the running instance. runTest.ts strips them, so the integrated terminal works the same as an external one.

From VS Code

  1. Ctrl+Shift+D → select Extension Tests
  2. Press F5

A second VS Code window opens with the test-project workspace, runs all suites, and reports results in the Debug Console. Use this when you want breakpoints.

Writing a New Test

import * as assert from 'assert';

suite('My Feature', () => {
    test('does the right thing', () => {
        assert.strictEqual(1 + 1, 2);
    });

    test('async operation', async function () {
        this.timeout(10_000);
        const result = await someAsyncCall();
        assert.ok(result);
    });
});

Place the file in src/test/suite/ with a .test.ts suffix — the test runner picks it up automatically via the glob in index.ts.

Debugging a Test

Set breakpoints in your .test.ts file, then launch Extension Tests with F5. Execution pauses at breakpoints; use the Debug panel to inspect state.