Files
vscode/.github/instructions/writing-tests.instructions.md
T
a3d955d72a sessions: move providers to contrib/providers with ESLint layer rules and docs (#316227)
- Move copilotChatSessions, remoteAgentHost, and agentHost providers from
  contrib/ into a new contrib/providers/ subfolder for clearer separation
- Add ESLint layer rule 'contrib/providers/*/~' (before 'contrib/*/~') so
  sibling contrib folders cannot import directly from providers
- Update all entry points (sessions.common.main.ts, sessions.desktop.main.ts,
  sessions.web.main.ts) to reference new provider paths
- Port all upstream changes from origin/main to the new provider locations
- Add contrib/providers entry to build/lib/i18n.resources.json
- Rewrite docs: README.md, LAYOUT.md, LAYERS.md, SESSIONS.md, SKILL.md,
  sessions.instructions.md; add source-code-organization, coding-guidelines,
  and writing-tests instruction files; remove stale SESSIONS_PROVIDER.md and
  AGENTS_CHAT_WIDGET.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-13 12:14:40 +00:00

2.2 KiB

description, applyTo
description applyTo
VS Code test writing guidelines — unit tests, integration tests, snapshot tests, and clean teardown patterns. Reference when writing or updating tests. {src/vs/**/test/**,src/vs/**/*.test.ts,src/vs/**/*.integrationTest.ts}

Writing Tests

Canonical reference: https://github.com/microsoft/vscode/wiki/Writing-Tests

Test Types

Type File suffix Location Runs in
Unit tests .test.ts src/vs/**/test/ Browser, Electron, or Node.js (depends on layer)
Integration tests .integrationTest.ts src/vs/**/test/ Real external APIs
Extension tests Standard extension test system extensions/*/ Extension host

Running Tests

  • Unit tests: scripts/test.sh (macOS/Linux) or scripts/test.bat (Windows)
    • Filter: --grep <pattern>
    • Glob: --runGlob **/myFile.test.js
  • Integration tests: scripts/test-integration.sh or scripts/test-integration.bat
  • VS Code UI: Use the Selfhost Test Provider

Writing Unit Tests

Tests use Mocha's BDD interface (suite/test) with the assert module and sinon for mocks.

Clean Teardown

Always use ensureNoDisposablesAreLeakedInTestSuite() to catch disposal leaks:

suite('myTests', () => {
  const store = ensureNoDisposablesAreLeakedInTestSuite();

  test('example', () => {
    const disposable = store.add(new MyDisposable());
    // ...
  });
});

Always call sinon.restore() in teardown to avoid leaking mocks.

Best Practices

  • Minimize assertions per test — prefer one assert.deepStrictEqual snapshot over many fine-grained assertions
  • Don't add tests to the wrong suite — find the relevant suite block
  • Follow existing patterns (describe/test or suite/test) consistently within a file
  • Don't stub globals (e.g., (mainWindow as any).X = ...) — make dependencies injectable instead

Snapshot Testing

Use assertSnapshot for Jest-like snapshot tests. Snapshots are written to a __snapshots__ directory beside the test file on first run — verify the output is correct, then subsequent runs compare against it.