Registry /
testing / vscode-test-adapter-util
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TestAdapterRegistrar
✓ import { TestAdapterRegistrar } from 'vscode-test-adapter-util';
✗ const { TestAdapterRegistrar } = require('vscode-test-adapter-util');
Primarily designed for ESM usage within VS Code extensions. `TestAdapterRegistrar` is crucial for linking your custom TestAdapter to the Test Explorer.
Log
✓ import { Log } from 'vscode-test-adapter-util';
✗ const Log = require('vscode-test-adapter-util').Log;
Used for logging diagnostic information from your test adapter to the VS Code output channel. Useful for debugging and user feedback.
sendTestEvent
✓ import { sendTestEvent } from 'vscode-test-adapter-util';
✗ import sendTestEvent from 'vscode-test-adapter-util/dist/sendTestEvent';
A utility function to send `TestEvent` objects to the Test Explorer, indicating test progress and results. Avoid direct imports from internal paths like `dist`.
This quickstart demonstrates how to create a basic VS Code Test Adapter using `vscode-test-adapter-util`. It shows registering a custom `MyTestAdapter` with the Test Explorer using `TestAdapterRegistrar`, initializing a `Log` instance for output, and simulating test discovery and execution using `sendTestEvent` to update test states in the UI.
import * as vscode from 'vscode';
import { TestAdapter, TestLoadFinishedEvent, TestLoadStartedEvent, TestRunFinishedEvent, TestRunStartedEvent, TestSuiteEvent, TestEvent, TestController } from 'vscode-test-adapter-api';
import { TestAdapterRegistrar, Log, sendTestEvent } from 'vscode-test-adapter-util';
class MyTestAdapter implements TestAdapter {
private disposables: vscode.Disposable[] = [];
private readonly testsEmitter = new vscode.EventEmitter<TestLoadStartedEvent | TestLoadFinishedEvent>();
private readonly testStatesEmitter = new vscode.EventEmitter<TestRunStartedEvent | TestRunFinishedEvent | TestSuiteEvent | TestEvent>();
private readonly retireEmitter = new vscode.EventEmitter<void>();
get tests(): vscode.Event<TestLoadStartedEvent | TestLoadFinishedEvent> { return this.testsEmitter.event; }
get testStates(): vscode.Event<TestRunStartedEvent | TestRunFinishedEvent | TestSuiteEvent | TestEvent> { return this.testStatesEmitter.event; }
get retire(): vscode.Event<void> { return this.retireEmitter.event; }
constructor(public readonly workspaceFolder: vscode.WorkspaceFolder, private readonly log: Log) {
this.log.info('Initializing MyTestAdapter for workspace ' + workspaceFolder.name);
}
async load(): Promise<void> {
this.testsEmitter.fire({ type: 'started' });
this.log.debug('Starting test load...');
const suite = {
type: 'suite' as const,
id: 'root',
label: 'My Tests',
children: [
{ type: 'test' as const, id: 'test1', label: 'Example Test 1' },
{ type: 'test' as const, id: 'test2', label: 'Example Test 2' }
]
};
this.testsEmitter.fire({ type: 'finished', suite });
this.log.debug('Test load finished.');
}
async run(testIds: string[]): Promise<void> {
this.testStatesEmitter.fire({ type: 'started', tests: testIds });
this.log.info('Running tests: ' + JSON.stringify(testIds));
for (const id of testIds) {
sendTestEvent(this.testStatesEmitter, { type: 'test', test: id, state: 'running' });
await new Promise(resolve => setTimeout(resolve, Math.random() * 500 + 100)); // Simulate async work
const passed = Math.random() > 0.3;
sendTestEvent(this.testStatesEmitter, { type: 'test', test: id, state: passed ? 'passed' : 'failed', message: passed ? undefined : 'Simulated failure' });
this.log.debug(`Test ${id} ${passed ? 'passed' : 'failed'}`);
}
this.testStatesEmitter.fire({ type: 'finished' });
this.log.info('Test run finished.');
}
async debug(testIds: string[]): Promise<void> {
this.log.warn('Debug not yet implemented for MyTestAdapter. Running normally instead.');
return this.run(testIds);
}
cancel(): void {
this.log.info('Test run cancelled.');
}
dispose(): void {
this.cancel();
for (const disposable of this.disposables) {
disposable.dispose();
}
this.disposables = [];
}
}
export function activate(context: vscode.ExtensionContext) {
const log = new Log('myTestAdapter', context.outputChannel, 'MyTestAdapter Log');
context.subscriptions.push(log);
const testExplorerExtension = vscode.extensions.getExtension<TestController>('hbenl.vscode-test-explorer');
if (testExplorerExtension) {
log.info('Test Explorer extension found. Registering adapter.');
const testHub = testExplorerExtension.exports;
context.subscriptions.push(new TestAdapterRegistrar(
testHub,
workspaceFolder => new MyTestAdapter(workspaceFolder, log)
));
} else {
log.warn('Test Explorer extension not found. MyTestAdapter will not be registered.');
}
}
Errors
Common errors & fixes
Error: Cannot find module 'vscode-test-adapter-util'
The package is not correctly installed or linked in the extension's `node_modules`.
fixRun `npm install vscode-test-adapter-util` or `yarn add vscode-test-adapter-util` in your extension project. For a multi-root workspace, ensure it's installed in the correct workspace folder.
TypeError: Cannot read properties of undefined (reading 'exports') when getting Test Explorer extension
The `hbenl.vscode-test-explorer` extension is not installed or not activated in the VS Code instance running your extension, or its identifier is incorrect.
fixVerify that `hbenl.vscode-test-explorer` is installed and enabled in your VS Code environment. Double-check the extension ID string in `vscode.extensions.getExtension('hbenl.vscode-test-explorer')`. Handle the case where the extension might not be found gracefully. TypeScript error: Argument of type 'TestAdapterRegistrar' is not assignable to parameter of type 'Disposable'
Older versions of `TestAdapterRegistrar` might not correctly implement `vscode.Disposable` or there's a type mismatch in your `tsconfig.json` or `vscode` types.
fixEnsure `vscode-test-adapter-util` and `@types/vscode` are up-to-date. Ensure your `TestAdapterRegistrar` instance is properly initialized and its `dispose()` method is correctly defined and called during your extension's deactivation.
Audit
Dependencies
vscoderequiredPeer dependency as it's a VS Code extension utility. Specified in engines field.
vscode-test-adapter-apirequiredProvides the core interfaces (like TestAdapter, TestHub) that this utility library assists in implementing and interacting with.
vscode-test-exploreroptionalThe VS Code extension for which this utility provides helpers. Conceptual dependency as this library's primary purpose is to integrate with it.