Test Setup - redhat-developer/vscode-extension-tester GitHub Wiki
The ExTester offers both CLI and API to perform all the setup actions. That way you can simply integrate it into your npm scripts, or just call it from your code if that is more preferable.
-
CODE_VERSION- can be used to set version of VS Code you want to run with the appropriate ChromeDriver versionexport CODE_VERSION="1.84.2"
-
TEST_RESOURCES- can be used to set folder used for all test resources, by default$TMPDIR/test-resources(value of$TMPDIRdiffers based on operating system)export TEST_RESOURCES="./test-folder"
-
HTTP_PROXY- can be used to route http request over a prox for downloading VSCode and Chromium driver. -
EXTENSIONS_FOLDER- configuring the extension path where extensions are installed/loaded. -
EXTENSION_DEV_PATH- The developer extension that is loaded under development. -
HTTPS_TLS_REJECT_UNAUTHORIZED- Disable TLS check when downloading VSCode and Chromium driver. '0' is disabled and '1' is enabled, this setting aligns withNODE_TLS_REJECT_UNAUTHORIZED.export HTTPS_TLS_REJECT_UNAUTHORIZED="0"
All the CLI actions are available with the command extest which is available to your npm scripts once the package is installed. The default storage folder for all test resources is a $TMPDIR/test-resources.
If you wish to manually download VS Code of a given version
Usage: extest get-vscode [options]
Download VS Code for testing
Options:
-s, --storage <storage> # Use this folder for all test resources
-c, --code_version <version> # Version of VS Code to download
-t, --type <type> # Type of VS Code release (stable/insider)
-n, --no_cache # Disable caching of VS Code download (default: false)
--config <path> # Path to extester.config.json configuration file
-h, --help # output usage informationDownload chrome driver for a given version of VS Code
Usage: extest get-chromedriver [options]
Download ChromeDriver binary
Options:
-s, --storage <storage> # Use this folder for all test resources
-c, --code_version <version> # Version of VS Code you want to run with the ChromeDriver
-t, --type <type> # Type of VS Code release (stable/insider)
-n, --no_cache # Disable caching of ChromeDriver download (default: false)
--config <path> # Path to extester.config.json configuration file
-h, --help # display help for commandTo manually build and install your extension. This step is not necessary to run the tests, since the framework will run the extension directly from source.
Usage: extest install-vsix [options]
Install extension from vsix file into test instance of VS Code
Options:
-s, --storage <storage> # Use this folder for all test resources
-e, --extensions_dir <extensions_directory> # VS Code will use this directory for managing extensions
-f, --vsix_file <file> # path/URL to vsix file containing the extension
--package_options <json> # JSON string of vsce IPackageOptions (e.g. '{"useYarn":true,"followSymlinks":true}')
-t, --type <type> # Type of VS Code release (stable/insider)
--config <path> # Path to extester.config.json configuration file
-h, --help # display help for command
To also install arbitrary extensions by ID into your test instance.
Usage: extest install-from-marketplace [options] <id> [ids...]
Install extension from marketplace with given <id> into test instance of VS Code
Options:
-s, --storage <storage> # Use this folder for all test resources
-e, --extensions_dir <extensions_directory> # VS Code will use this directory for managing extensions
-t, --type <type> # Type of VS Code release (stable/insider)
-p, --pre_release # Installs the pre-release version of the extension
--config <path> # Path to extester.config.json configuration file
-h, --help # display help for commandTo perform all test setup steps in one command
Usage: extest setup-tests [options]
Set up all necessary requirements for tests to run
Options:
-s, --storage <storage> # Use this folder for all test resources
-e, --extensions_dir <extensions_directory> # VS Code will use this directory for managing extensions
-c, --code_version <version> # Version of VS Code to download
-t, --type <type> # Type of VS Code release (stable/insider)
--package_options <json> # JSON string of vsce IPackageOptions (e.g. '{"useYarn":true,"followSymlinks":true}')
-i, --install_dependencies # Automatically install extensions your extension depends on (default: false)
-n, --no_cache # Disable caching of VS Code and ChromeDriver downloads (default: false)
--config <path> # Path to extester.config.json configuration file
-h, --help # display help for commandTo run test files
Usage: extest run-tests [options] [testFiles...]
Run the test files specified by glob pattern(s)
Options:
-s, --storage <storage> # Use this folder for all test resources
-e, --extensions_dir <extensions_directory> # VS Code will use this directory for managing extensions
-c, --code_version <version> # Version of VS Code to be used
-t, --type <type> # Type of VS Code release (stable/insider)
-o, --code_settings <settings.json> # Path to custom settings for VS Code json file
-u, --uninstall_extension # Uninstall the extension after the test run (default: false)
-m, --mocha_config <mocharc.js> # Path to Mocha configuration file
-l, --log_level <level> # Log messages from webdriver with a given level (default: "Info")
-f, --offline # Attempt to run without internet connection, make sure to have all requirements downloaded (default: false)
-C, --coverage # Enable code coverage using c8
-L, --locale <locale> # Launch VS Code with the given display language (e.g. ru, zh-cn). Requires the language pack to be installed via -i. See [[Locale-Testing]]
-p, --custom_page_objects <path> # Path to a compiled JS locator contribution file for custom page objects
--config <path> # Path to extester.config.json configuration file
-h, --help # display help for commandPerform all test setup and run tests in a single command
Usage: extest setup-and-run [options] [testFiles...]
Perform all setup and run tests specified by glob pattern(s)
Options:
-s, --storage <storage> # Use this folder for all test resources
-e, --extensions_dir <extensions_directory> # VS Code will use this directory for managing extensions
-c, --code_version <version> # Version of VS Code to download
-t, --type <type> # Type of VS Code release (stable/insider)
-o, --code_settings <settings.json> # Path to custom settings for VS Code json file
--package_options <json> # JSON string of vsce IPackageOptions (e.g. '{"useYarn":true,"followSymlinks":true}')
-u, --uninstall_extension # Uninstall the extension after the test run (default: false)
-m, --mocha_config <mocharc.js> # Path to Mocha configuration file
-i, --install_dependencies # Automatically install extensions your extension depends on (default: false)
-l, --log_level <level> # Log messages from webdriver with a given level (default: "Info")
-f, --offline # Attempt to run without internet connection, make sure to have all requirements downloaded (default: false)
-C, --coverage # Enable code coverage using c8
-n, --no_cache # Disable caching of VS Code and ChromeDriver downloads (default: false)
-L, --locale <locale> # Launch VS Code with the given display language (e.g. ru, zh-cn). Requires the language pack to be installed via -i. See [[Locale-Testing]]
-p, --custom_page_objects <path> # Path to a compiled JS locator contribution file for custom page objects
--config <path> # Path to extester.config.json configuration file
-h, --help # display help for commandInstead of repeating long CLI flag sequences, you can define all options in an extester.config.json file at the root of your project. ExTester automatically discovers it by walking up from the current working directory.
Create extester.config.json next to your package.json:
{
"setup": {
"vscodeVersion": "latest",
"installDependencies": true
},
"run": {
"testFiles": ["./out/test/**/*.test.js"],
"resources": ["."],
"extensionsDir": "./test-extensions"
}
}Then replace your npm script:
ExTester searches for extester.config.json by walking up the directory tree from cwd (the same strategy used by .mocharc.json and similar tools). The first file found is used.
To point to a specific file instead:
extest setup-and-run --config ./config/extester.config.jsonSettings are resolved in this order — later sources override earlier ones:
built-in defaults ← extester.config.json ← CLI flags
Environment variables (CODE_VERSION, TEST_RESOURCES, etc.) continue to apply at their existing layer inside ExTester and are not affected by the config file.
All fields are optional. Paths are resolved relative to the config file's location.
Controls VS Code + ChromeDriver download and extension installation. Used by get-vscode, get-chromedriver, install-vsix, setup-tests, and setup-and-run.
| Field | Type | Default | CLI equivalent | Description |
|---|---|---|---|---|
vscodeVersion |
string | "latest" |
-c / --code_version
|
VS Code version: latest, min, max, or 1.X.Y
|
type |
"stable" |
"insider" |
"stable" |
-t / --type
|
storage |
string |
$TEST_RESOURCES or $TMPDIR/test-resources
|
-s / --storage
|
Folder for all downloaded test resources |
extensionsDir |
string | — |
-e / --extensions_dir
|
VS Code extensions directory override |
packageOptions |
object | — | --package_options |
vsce IPackageOptions forwarded to vsce.createVSIX()
|
installDependencies |
boolean | false |
-i / --install_dependencies
|
Install marketplace dependencies automatically |
noCache |
boolean | false |
-n / --no_cache
|
Skip cached downloads |
Controls test execution inside VS Code. Used by run-tests and setup-and-run.
| Field | Type | Default | CLI equivalent | Description |
|---|---|---|---|---|
testFiles |
string[] | — | positional [testFiles...]
|
Glob pattern(s) for test files. Used when no CLI positional args are provided. |
vscodeVersion |
string | "latest" |
-c / --code_version
|
VS Code version: latest, min, max, or 1.X.Y
|
type |
"stable" |
"insider" |
"stable" |
-t / --type
|
storage |
string |
$TEST_RESOURCES or $TMPDIR/test-resources
|
-s / --storage
|
Folder for all downloaded test resources |
extensionsDir |
string | — |
-e / --extensions_dir
|
VS Code extensions directory override |
settings |
string | — |
-o / --code_settings
|
Path to a custom VS Code settings.json
|
cleanup |
boolean | false |
-u / --uninstall_extension
|
Uninstall the extension after the test run |
mochaConfig |
string | — |
-m / --mocha_config
|
Path to a Mocha configuration file |
logLevel |
string | "Info" |
-l / --log_level
|
Webdriver log level: Debug, Info, Warning, Severe, OFF, ALL
|
offline |
boolean | false |
-f / --offline
|
Run without internet access |
coverage |
boolean | false |
-C / --coverage
|
Enable c8 code coverage |
resources |
string[] | [] |
-r / --open_resource
|
Files or folders to open in VS Code at startup |
customPageObjects |
string | — |
-p / --custom_page_objects
|
Path to a compiled JS locator contribution file |
locale |
string | — |
-L / --locale
|
Display language locale (e.g. ru, zh-cn). Requires the language pack extension to be installed. See Locale-Testing
|
Add a $schema field to get inline validation and autocomplete in VS Code and other JSON-aware editors:
{
"$schema": "./node_modules/vscode-extension-tester/resources/extester.schema.json",
"setup": { ... },
"run": { ... }
}The ExTester implements a caching mechanism for both VS Code and ChromeDriver downloads to improve performance and reduce bandwidth usage. Here's how it works:
-
Resource Caching:
- When downloading, archives are saved with version-specific names (e.g.,
1.84.2-stable.zipfor VS Code,114.0.5735.90-chromedriver_win32.zipfor ChromeDriver) - Before downloading, the system checks if a matching version exists in the cache
- If found in cache, the download is skipped and the cached archive is unpacked
- The archive is preserved for future use
- When downloading, archives are saved with version-specific names (e.g.,
When the --no_cache option is enabled:
-
Resource Behavior:
- Always downloads a fresh copy of the archive
- Saves it with a generic filename (e.g.,
stable.zipfor VS Code,chromedriver_win32.zipfor ChromeDriver) - After unpacking, the downloaded archive is removed
- Note: If a version is already unpacked, it will be reused even with --no_cache to avoid unnecessary unpacking
NOTE:
Unpackedrefers to the extracted VS Code and ChromeDriver executables that are ready to run, stored separately from their downloaded archives. This is a critical distinction to understand when working with ExTester's caching system.
The same actions are available in the ExTester class as API:
The packageOptions field (and its CLI counterpart --package_options <json>) accepts any option
from the IPackageOptions interface of @vscode/vsce.
The object is forwarded directly to vsce.createVSIX(), so every packaging option vsce supports
is available without ExTester needing to enumerate them individually.
Common examples:
// Use yarn instead of npm
{ useYarn: true }
// Recurse into symlinked directories (fixes missing-symlink issues)
{ followSymlinks: true }
// Combine options freely
{ useYarn: true, followSymlinks: true, preRelease: true }CLI equivalent:
extest setup-and-run 'out/**/*.test.js' --package_options '{"useYarn":true,"followSymlinks":true}'export interface SetupOptions {
/** version of VS Code to test against, defaults to latest */
vscodeVersion?: string;
/** vsce packaging options passed directly to vsce.createVSIX() */
packageOptions?: IPackageOptions;
/** install the extension's dependencies from the marketplace. Defaults to `false`. */
installDependencies?: boolean;
/** disable caching of VS Code and ChromeDriver downloads */
noCache?: boolean;
}
export declare const DEFAULT_SETUP_OPTIONS: {
vscodeVersion: string;
installDependencies: boolean;
};
export interface RunOptions {
/** version of VS Code to test against, defaults to latest */
vscodeVersion?: string;
/** path to custom settings json file */
settings?: string;
/** remove the extension's directory as well (if present) */
cleanup?: boolean;
/** path to a custom mocha configuration file */
config?: string;
/** logging level of the webdriver */
logLevel?: VSBrowserLogLevel;
/** try to perform all setup without internet connection, needs all requirements pre-downloaded manually */
offline?: boolean;
/** display language locale for VS Code (e.g. 'ru', 'zh-cn'). Requires the matching language pack extension to be installed. See [[Locale-Testing]] */
locale?: string;
/** custom page objects locator contribution to load at startup */
customPageObjects?: CustomPageObjectsOptions;
}
export interface CustomPageObjectsOptions {
/** path to a compiled JS module exporting a `locators` object in LocatorDiff shape */
locatorsPath: string;
}
/** defaults for the [[RunOptions]] */
export declare const DEFAULT_RUN_OPTIONS: {
vscodeVersion: "latest";
settings: "";
logLevel: logging.Level.INFO;
offline: false;
};
/**
* ExTester
*/
export declare class ExTester {
private code;
private chrome;
constructor(storageFolder?: string, releaseType?: ReleaseQuality, extensionsDir?: string);
/**
* Download VS Code of given version and release quality stream
* @param version version to download, default latest
*/
downloadCode(version?: string): Promise<void>;
/**
* Install the extension into the test instance of VS Code
* @param vsixFile path to extension .vsix file. If not set, default vsce path will be used
* @param useYarn when true run `vsce package` with the `--yarn` flag
*/
installVsix({ vsixFile, useYarn }?: { vsixFile?: string; useYarn?: boolean }): Promise<void>;
/**
* Install an extension from VS Code marketplace into the test instance
* @param id id of the extension to install
*/
installFromMarketplace(id: string): Promise<void>;
/**
* Download the matching chromedriver for a given VS Code version
* @param vscodeVersion selected versio nof VS Code, default latest
*/
downloadChromeDriver(vscodeVersion?: string): Promise<void>;
/**
* Performs all necessary setup: getting VS Code + ChromeDriver
* and packaging/installing extension into the test instance
*
* @param options Additional options for setting up the tests
*/
setupRequirements(options?: SetupOptions): Promise<void>;
/**
* Performs requirements setup and runs extension tests
*
* @param testFilesPattern glob pattern for test files to run
* @param vscodeVersion version of VS Code to test against, defaults to latest
* @param setupOptions Additional options for setting up the tests
* @param runOptions Additional options for running the tests
*
* @returns Promise resolving to the mocha process exit code - 0 for no failures, 1 otherwise
*/
setupAndRunTests(
testFilesPattern: string,
vscodeVersion?: string,
setupOptions?: Omit<SetupOptions, "vscodeVersion">,
runOptions?: Omit<RunOptions, "vscodeVersion">,
): Promise<number>;
/**
* Runs the selected test files in VS Code using mocha and webdriver
* @param testFilesPattern glob pattern for selected test files
* @param runOptions Additional options for running the tests
*
* @returns Promise resolving to the mocha process exit code - 0 for no failures, 1 otherwise
*/
runTests(testFilesPattern: string, runOptions?: RunOptions): Promise<number>;
}