diff --git a/README.md b/README.md index 05b8740..563a5d9 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,20 @@ vscode-test-web --browserType=chromium --extensionDevelopmentPath=$extensionLoca Open VS Code in the Browser on a folder with test data from the local disk: -``` +```sh vscode-test-web --browserType=chromium --extensionDevelopmentPath=$extensionLocation $testDataLocation ``` VS Code for the Web will open on a virtual workspace (scheme `vscode-test-web`), backed by a file system provider that gets the file/folder data from the local disk. Changes to the file system are kept in memory and are not written back to disk. +Open VS Code in the Browser with external network access: + +```sh +vscode-test-web --browserType=chromium --browserOption=--disable-web-security extensionDevelopmentPath=$extensionLocation +``` + +This allows the extension being tested to make network requests to external hosts. + Via API: ```ts @@ -68,6 +76,7 @@ CLI options: |Option|Argument Description| |-----|-----| | --browser | The browser to launch: `chromium` (default), `firefox`, `webkit` or `none`. | +| --browserOption | Command line argument to use when launching the browser instance. Argument can be provided multiple times. | | --extensionDevelopmentPath | A path pointing to an extension under development to include. | | --extensionTestsPath | A path to a test module to run. | | --quality | `insiders` (default), or `stable`. Ignored when sourcesPath is provided. | diff --git a/package.json b/package.json index 1c3b963..53e3427 100644 --- a/package.json +++ b/package.json @@ -63,4 +63,4 @@ "bugs": { "url": "https://github.com/microsoft/vscode-test-web/issues" } -} +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 231193f..c7deb96 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,11 @@ export interface Options { */ browserType: BrowserType; + /** + * Browser command line options. + */ + browserOptions?: string[]; + /** * Absolute path to folder that contains one or more extensions (in subfolders). * Extension folders include a `package.json` extension manifest. @@ -271,6 +276,11 @@ async function openBrowser(endpoint: string, options: Options, configPage?: (pag } const args: string[] = []; + + if (options.browserOptions) { + args.push(...options.browserOptions); + } + if (process.platform === 'linux' && options.browserType === 'chromium') { args.push('--no-sandbox'); } @@ -385,7 +395,26 @@ function validatePermissions(permissions: unknown): string[] | undefined { return permissions; } - console.log(`Invalid permission`); + console.log(`Invalid permission: ${permissions}`); + showHelp(); + process.exit(-1); +} + +function validateBrowserOptions(browserOptions: unknown): string[] | undefined { + if (browserOptions === undefined) { + return undefined; + } + function isValidOption(p: unknown): p is string { + return typeof p === 'string'; + } + if (isValidOption(browserOptions)) { + return [browserOptions]; + } + if (Array.isArray(browserOptions) && browserOptions.every(isValidOption)) { + return browserOptions; + } + + console.log(`Invalid browser option: ${browserOptions}`); showHelp(); process.exit(-1); } @@ -497,6 +526,7 @@ function validatePortNumber(port: unknown): number | undefined { interface CommandLineOptions { browser?: string; + browserOptions?: string; browserType?: string; extensionDevelopmentPath?: string; extensionTestsPath?: string; @@ -521,7 +551,8 @@ interface CommandLineOptions { function showHelp() { console.log('Usage:'); - console.log(` --browser 'chromium' | 'firefox' | 'webkit' | 'none': The browser to launch. [Optional, defaults to 'chromium']`) + console.log(` --browser 'chromium' | 'firefox' | 'webkit' | 'none': The browser to launch. [Optional, defaults to 'chromium']`); + console.log(` --browserOption option: Command line argument to use when launching the browser instance. [Optional, Multiple]`) console.log(` --extensionDevelopmentPath path: A path pointing to an extension under development to include. [Optional]`); console.log(` --extensionTestsPath path: A path to a test module to run. [Optional]`); console.log(` --quality 'insiders' | 'stable' [Optional, default 'insiders', ignored when running from sources]`); @@ -556,7 +587,7 @@ async function cliMain(): Promise { console.log(`${manifest.name}: ${manifest.version}`); const options: minimist.Opts = { - string: ['extensionDevelopmentPath', 'extensionTestsPath', 'browser', 'browserType', 'quality', 'version', 'waitForDebugger', 'folder-uri', 'permission', 'extensionPath', 'extensionId', 'sourcesPath', 'host', 'port', 'testRunnerDataDir'], + string: ['extensionDevelopmentPath', 'extensionTestsPath', 'browser', 'browserOption', 'browserType', 'quality', 'version', 'waitForDebugger', 'folder-uri', 'permission', 'extensionPath', 'extensionId', 'sourcesPath', 'host', 'port', 'testRunnerDataDir'], boolean: ['open-devtools', 'headless', 'hideServerLog', 'printServerLog', 'help', 'verbose', 'coi', 'esm'], unknown: arg => { if (arg.startsWith('-')) { @@ -573,6 +604,7 @@ async function cliMain(): Promise { process.exit(); } + const browserOptions = validateBrowserOptions(args.browserOption); const browserType = validateBrowserType(args); const extensionTestsPath = await validatePathOrUndefined(args, 'extensionTestsPath', true); const extensionDevelopmentPath = await validatePathOrUndefined(args, 'extensionDevelopmentPath'); @@ -612,6 +644,7 @@ async function cliMain(): Promise { runTests({ extensionTestsPath, extensionDevelopmentPath, + browserOptions, browserType, quality, devTools, @@ -637,6 +670,7 @@ async function cliMain(): Promise { } else { open({ extensionDevelopmentPath, + browserOptions, browserType, quality, devTools,