Skip to content

Commit

Permalink
Re-enable extension_development_path option and add coverage support
Browse files Browse the repository at this point in the history
  • Loading branch information
TamiTakamiya committed Apr 2, 2024
1 parent a2daf71 commit 4949cc2
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out/
node_modules/
.npmrc
.npmrc
tests/test-project/coverage/
178 changes: 173 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "npx lerna run build",
"build:changed": "npx lerna run build --since main",
"test": "npm run ui-test --workspace=extester-test",
"coverage": "npm run ui-coverage --workspace=extester-test",
"test:build": "npm run build && npm install --workspace=extester-test && npm test"
},
"workspaces": [
Expand Down
1 change: 1 addition & 0 deletions packages/extester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@vscode/vsce": "^2.24.0",
"@vscode-extension-tester/locators": "^1.0.0",
"@vscode-extension-tester/page-objects": "^1.0.0",
"c8": "^9.1.0",
"commander": "^12.0.0",
"compare-versions": "^6.1.0",
"fs-extra": "^11.2.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/extester/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class VSBrowser {
static readonly browserName = 'vscode';
private storagePath: string;
private extensionsFolder: string | undefined;
private extensionDevelopmentPath: string | undefined;
private customSettings: Object;
private _driver!: WebDriver;
private codeVersion: string;
Expand All @@ -25,6 +26,7 @@ export class VSBrowser {
constructor(codeVersion: string, releaseType: ReleaseQuality, customSettings: Object = {}, logLevel: logging.Level = logging.Level.INFO) {
this.storagePath = process.env.TEST_RESOURCES ? process.env.TEST_RESOURCES : path.resolve(DEFAULT_STORAGE_FOLDER);
this.extensionsFolder = process.env.EXTENSIONS_FOLDER ? process.env.EXTENSIONS_FOLDER : undefined;
this.extensionDevelopmentPath = process.env.EXTENSION_DEV_PATH ? process.env.EXTENSION_DEV_PATH : undefined;
this.customSettings = customSettings;
this.codeVersion = codeVersion;
this.releaseType = releaseType;
Expand Down Expand Up @@ -76,6 +78,8 @@ export class VSBrowser {
fs.copyFileSync(path.resolve(__dirname, '..', '..', 'resources', 'state.vscdb'), path.join(userSettings, 'globalStorage', 'state.vscdb'));
}
args.push(`--extensionDevelopmentPath=${process.cwd()}`);
} else if(this.extensionDevelopmentPath) {
args.push(`--extensionDevelopmentPath=${this.extensionDevelopmentPath}`);
}

let options = new Options().setChromeBinaryPath(codePath).addArguments(...args) as any;
Expand Down Expand Up @@ -187,7 +191,7 @@ export class VSBrowser {
return;
}

const code = new CodeUtil(this.storagePath, this.releaseType, this.extensionsFolder);
const code = new CodeUtil(this.storagePath, this.releaseType, this.extensionsFolder, this.extensionDevelopmentPath);
code.open(...paths);
await new Promise(res => setTimeout(res, 3000));
await this.waitForWorkbench();
Expand Down
11 changes: 8 additions & 3 deletions packages/extester/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ program.command('setup-tests')
.option('-t, --type <type>', 'Type of VS Code release (stable/insider)')
.option('-y, --yarn', 'Use yarn to build the extension via vsce instead of npm', false)
.option('-i, --install_dependencies', 'Automatically install extensions your extension depends on', false)
.option('-d, --extension_development_path <extension development directory>', 'VSCode will use the unpackaged extension source from this directory')
.action(withErrors(async (cmd) => {
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir);
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir, cmd.extension_development_path);
await extest.setupRequirements({vscodeVersion: cmd.code_version, useYarn: cmd.yarn, installDependencies: cmd.install_dependencies});
}));

Expand All @@ -80,9 +81,11 @@ program.command('run-tests <testFiles...>')
.option('-m, --mocha_config <mocharc.js>', 'Path to Mocha configuration file')
.option('-l, --log_level <level>', 'Log messages from webdriver with a given level', 'Info')
.option('-f, --offline', 'Attempt to run without internet connection, make sure to have all requirements downloaded', false)
.option('-d, --extension_development_path <extension development directory>', 'VSCode will use the unpackaged extension source from this directory')
.option('-C, --coverage', 'Enable code coverage using c8')
.option('-r, --open_resource <resources...>', 'Open resources in VS Code. Multiple files and folders can be specified.')
.action(withErrors(async (testFiles, cmd) => {
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir);
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir, cmd.extension_development_path, cmd.coverage);
await extest.runTests(testFiles, {vscodeVersion: cmd.code_version, settings: cmd.code_settings, cleanup: cmd.uninstall_extension, config: cmd.mocha_config, logLevel: cmd.log_level, offline: cmd.offline, resources: cmd.open_resource ?? []});
}));

Expand All @@ -99,9 +102,11 @@ program.command('setup-and-run <testFiles...>')
.option('-i, --install_dependencies', 'Automatically install extensions your extension depends on', false)
.option('-l, --log_level <level>', 'Log messages from webdriver with a given level', 'Info')
.option('-f, --offline', 'Attempt to run without internet connection, make sure to have all requirements downloaded', false)
.option('-d, --extension_development_path <extension development directory>', 'VSCode will use the unpackaged extension source from this directory')
.option('-C, --coverage', 'Enable code coverage using c8')
.option('-r, --open_resource <resources...>', 'Open resources in VS Code. Multiple files and folders can be specified.')
.action(withErrors(async (testFiles, cmd) => {
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir);
const extest = new ExTester(cmd.storage, codeStream(cmd.type), cmd.extensions_dir, cmd.extension_development_path, cmd.coverage);
await extest.setupAndRunTests(testFiles, cmd.code_version, {useYarn: cmd.yarn, installDependencies: cmd.install_dependencies}, {settings: cmd.code_settings, cleanup: cmd.uninstall_extension, config: cmd.mocha_config, logLevel: cmd.log_level, resources: cmd.open_resource ?? []});
}));

Expand Down
Loading

0 comments on commit 4949cc2

Please sign in to comment.