@vscode/test-web
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -49,4 +49,11 @@ #!/usr/bin/env node | ||
/** | ||
* The folder URI to open VSCode on | ||
* A local path to open VSCode on. VS Code for the browser will open an a virtual | ||
* file system ('vscode-test-web://mount') where the files of the local folder will served. | ||
* The file system is read/write, but modifications are stored in memory and not written back to disk. | ||
*/ | ||
folderPath?: string; | ||
/** | ||
* The folder URI to open VSCode on. If 'folderPath' is set this will be ignored and 'vscode-test-web://mount' | ||
* is used as folder URI instead. | ||
*/ | ||
folderUri?: string; | ||
@@ -53,0 +60,0 @@ } |
133
out/index.js
@@ -26,3 +26,4 @@ #!/usr/bin/env node | ||
build: await getBuild(options.version), | ||
folderUri: options.folderUri | ||
folderUri: options.folderUri, | ||
folderMountPath: options.folderPath | ||
}; | ||
@@ -57,3 +58,4 @@ const port = 3000; | ||
build: await getBuild(options.version), | ||
folderUri: options.folderUri | ||
folderUri: options.folderUri, | ||
folderMountPath: options.folderPath | ||
}; | ||
@@ -105,15 +107,60 @@ const port = 3000; | ||
} | ||
function isStringOrUndefined(value) { | ||
return value === undefined || (typeof value === 'string'); | ||
function validateStringOrUndefined(options, name) { | ||
const value = options[name]; | ||
if (value === undefined || (typeof value === 'string')) { | ||
return value; | ||
} | ||
console.log(`'${name}' needs to be a string value.`); | ||
showHelp(); | ||
process.exit(-1); | ||
} | ||
function isBooleanOrUndefined(value) { | ||
return value === undefined || (typeof value === 'boolean'); | ||
async function validatePathOrUndefined(options, name, isFile) { | ||
const loc = validateStringOrUndefined(options, name); | ||
return loc && validatePath(loc, isFile); | ||
} | ||
function isBrowserType(browserType) { | ||
return (typeof browserType === 'string') && ['chromium', 'firefox', 'webkit'].includes(browserType); | ||
function validateBooleanOrUndefined(options, name) { | ||
const value = options[name]; | ||
if (value === undefined || (typeof value === 'boolean')) { | ||
return value; | ||
} | ||
console.log(`'${name}' needs to be a boolean value.`); | ||
showHelp(); | ||
process.exit(-1); | ||
} | ||
function isValidVersion(version) { | ||
return version === undefined || ((typeof version === 'string') && ['insiders', 'stable', 'sources'].includes(version)); | ||
function valdiateBrowserType(browserType) { | ||
if (browserType === 'undefined') { | ||
return 'chromium'; | ||
} | ||
if ((typeof browserType === 'string') && ['chromium', 'firefox', 'webkit'].includes(browserType)) { | ||
return browserType; | ||
} | ||
console.log(`Invalid browser type.`); | ||
showHelp(); | ||
process.exit(-1); | ||
} | ||
function getPortNumber(port) { | ||
async function validatePath(loc, isFile) { | ||
loc = path.resolve(loc); | ||
if (isFile) { | ||
if (!await download_1.fileExists(loc)) { | ||
console.log(`'${loc}' must be an existing file.`); | ||
process.exit(-1); | ||
} | ||
} | ||
else { | ||
if (!await download_1.directoryExists(loc)) { | ||
console.log(`'${loc}' must be an existing folder.`); | ||
process.exit(-1); | ||
} | ||
} | ||
return loc; | ||
} | ||
function validateVersion(version) { | ||
if (version === undefined || ((typeof version === 'string') && ['insiders', 'stable', 'sources'].includes(version))) { | ||
return version; | ||
} | ||
console.log(`Invalid version.`); | ||
showHelp(); | ||
process.exit(-1); | ||
} | ||
function validatePortNumber(port) { | ||
if (typeof port === 'string') { | ||
@@ -127,27 +174,45 @@ const number = Number.parseInt(port); | ||
} | ||
if (require.main === module) { | ||
const options = { string: ['extensionDevelopmentPath', 'extensionTestsPath', 'browserType', 'version', 'waitForDebugger', 'folder-uri'], boolean: ['open-devtools', 'headless'] }; | ||
function showHelp() { | ||
console.log('Usage:'); | ||
console.log(` --browserType 'chromium' | 'firefox' | 'webkit': The browser to launch`); | ||
console.log(` --extensionDevelopmentPath path. [Optional]: A path pointing to a extension to include.`); | ||
console.log(` --extensionTestsPath path. [Optional]: A path to a test module to run`); | ||
console.log(` --version. 'insiders' (Default) | 'stable' | 'sources' [Optional]`); | ||
console.log(` --open-devtools. Opens the dev tools [Optional]`); | ||
console.log(` --headless. Whether to show the browser. Defaults to true when an extensionTestsPath is provided, otherwise false. [Optional]`); | ||
console.log(` folderPath. A local folder to open VS Code on. The folder content will be available as a virtual file system`); | ||
} | ||
async function cliMain() { | ||
const options = { string: ['extensionDevelopmentPath', 'extensionTestsPath', 'browserType', 'version', 'waitForDebugger', 'folder-uri', 'mount'], boolean: ['open-devtools', 'headless'] }; | ||
const args = minimist(process.argv.slice(2), options); | ||
const { browserType, extensionDevelopmentPath, extensionTestsPath, version, waitForDebugger, headless } = args; | ||
const port = getPortNumber(waitForDebugger); | ||
if (!isBrowserType(browserType) || !isStringOrUndefined(extensionDevelopmentPath) || !isStringOrUndefined(extensionTestsPath) || !isValidVersion(version) || !isStringOrUndefined(args['folder-uri']) || !isBooleanOrUndefined(args['open-devtools']) || !isBooleanOrUndefined(headless)) { | ||
console.log('Usage:'); | ||
console.log(` --browserType 'chromium' | 'firefox' | 'webkit': The browser to launch`); | ||
console.log(` --extensionDevelopmentPath path. [Optional]: A path pointing to a extension to include.`); | ||
console.log(` --extensionTestsPath path. [Optional]: A path to a test module to run`); | ||
console.log(` --folder-uri. [Optional]: The folder to open VS Code on`); | ||
console.log(` --version. 'insiders' (Default) | 'stable' | 'sources' [Optional]`); | ||
console.log(` --open-devtools. Opens the dev tools [Optional]`); | ||
console.log(` --headless. Whether to show the browser. Defaults to true when an extensionTestsPath is provided, otherwise false. [Optional]`); | ||
process.exit(-1); | ||
const browserType = valdiateBrowserType(args.browserType); | ||
const version = validateVersion(args.version); | ||
const extensionTestsPath = await validatePathOrUndefined(args, 'extensionTestsPath', true); | ||
const extensionDevelopmentPath = await validatePathOrUndefined(args, 'extensionDevelopmentPath'); | ||
const headless = validateBooleanOrUndefined(args, 'headless'); | ||
const devTools = validateBooleanOrUndefined(args, 'open-devtools'); | ||
const port = validatePortNumber(args.waitForDebugger); | ||
let folderUri = validateStringOrUndefined(args, 'folder-uri'); | ||
let folderPath; | ||
const inputs = args._; | ||
if (inputs.length) { | ||
const input = await validatePath(inputs[0]); | ||
if (input) { | ||
folderPath = input; | ||
if (folderUri) { | ||
console.log(`Local folder provided as input, ignoring 'folder-uri'`); | ||
} | ||
folderUri = `vscode-test-web://mount/`; | ||
} | ||
} | ||
if (extensionTestsPath) { | ||
runTests({ | ||
extensionTestsPath: extensionTestsPath && path.resolve(extensionTestsPath), | ||
extensionDevelopmentPath: extensionDevelopmentPath && path.resolve(extensionDevelopmentPath), | ||
extensionTestsPath, | ||
extensionDevelopmentPath, | ||
browserType, | ||
version, | ||
devTools: args['open-devtools'], | ||
devTools, | ||
waitForDebugger: port, | ||
folderUri: args['folder-uri'], | ||
folderUri, | ||
folderPath, | ||
headless | ||
@@ -158,8 +223,9 @@ }); | ||
open({ | ||
extensionDevelopmentPath: extensionDevelopmentPath && path.resolve(extensionDevelopmentPath), | ||
extensionDevelopmentPath, | ||
browserType, | ||
version, | ||
devTools: args['open-devtools'], | ||
devTools, | ||
waitForDebugger: port, | ||
folderUri: args['folder-uri'], | ||
folderUri, | ||
folderPath, | ||
headless | ||
@@ -169,1 +235,4 @@ }); | ||
} | ||
if (require.main === module) { | ||
cliMain(); | ||
} |
@@ -13,2 +13,3 @@ "use strict"; | ||
const path = require("path"); | ||
const mounts_1 = require("./mounts"); | ||
async function createApp(config) { | ||
@@ -34,2 +35,3 @@ const app = new Koa(); | ||
} | ||
mounts_1.configureMounts(config, app); | ||
app.use(workbench_1.default(config)); | ||
@@ -36,0 +38,0 @@ return app; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchJSON = exports.fetch = exports.downloadAndUnzipVSCode = void 0; | ||
exports.fileExists = exports.directoryExists = exports.fetchJSON = exports.fetch = exports.downloadAndUnzipVSCode = void 0; | ||
const fs_1 = require("fs"); | ||
@@ -153,1 +153,21 @@ const path = require("path"); | ||
} | ||
async function directoryExists(path) { | ||
try { | ||
const stats = await fs_1.promises.stat(path); | ||
return stats.isDirectory(); | ||
} | ||
catch { | ||
return false; | ||
} | ||
} | ||
exports.directoryExists = directoryExists; | ||
async function fileExists(path) { | ||
try { | ||
const stats = await fs_1.promises.stat(path); | ||
return stats.isFile(); | ||
} | ||
catch { | ||
return false; | ||
} | ||
} | ||
exports.fileExists = fileExists; |
@@ -13,2 +13,3 @@ "use strict"; | ||
const download_1 = require("./download"); | ||
const mounts_1 = require("./mounts"); | ||
function asJSON(value) { | ||
@@ -36,3 +37,3 @@ return JSON.stringify(value).replace(/"/g, '"'); | ||
catch (e) { | ||
return e; | ||
return String(e); | ||
} | ||
@@ -81,2 +82,8 @@ } | ||
} | ||
if (config.folderMountPath) { | ||
if (!options.additionalBuiltinExtensions) { | ||
options.additionalBuiltinExtensions = []; | ||
} | ||
options.additionalBuiltinExtensions.push({ scheme: ctx.protocol, authority: ctx.host, path: mounts_1.fsProviderExtensionPrefix }); | ||
} | ||
return options; | ||
@@ -139,4 +146,5 @@ } | ||
}); | ||
//mountAPI(config, router); | ||
return router.routes(); | ||
} | ||
exports.default = default_1; |
{ | ||
"name": "@vscode/test-web", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"scripts": { | ||
"compile": "tsc -p ./", | ||
"postinstall": "yarn --cwd=fs-provider && yarn --cwd=sample", | ||
"compile": "tsc -p ./ && yarn compile-fs-provider", | ||
"watch": "tsc -w -p ./", | ||
"prepublishOnly": "tsc -p ./", | ||
"prepublishOnly": "yarn compile", | ||
"test": "eslint src --ext ts && tsc --noEmit", | ||
"preversion": "npm test", | ||
"postversion": "git push && git push --tags", | ||
"compile-fs-provider": "yarn --cwd=fs-provider compile-web", | ||
"compile-sample": "yarn --cwd=sample compile-web", | ||
"sample": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --browserType=chromium", | ||
"sample-tests": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --extensionTestsPath=sample/dist/web/test/suite/index.js --browserType=chromium" | ||
"sample": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --browserType=chromium sample/test-workspace", | ||
"sample-tests": "npm run compile && npm run compile-sample && node . --extensionDevelopmentPath=sample --extensionTestsPath=sample/dist/web/test/suite/index.js --browserType=chromium --headless=false sample/test-workspace" | ||
}, | ||
@@ -15,0 +17,0 @@ "main": "./out/index.js", |
@@ -5,6 +5,7 @@ # @vscode/test-web | ||
This module helps testing VS Code web extensions locally. | ||
This module helps testing [VS Code web extensions](https://code.visualstudio.com/api/extension-guides/web-extensions) locally. | ||
The node module runs a local web server that serves VS Code Browser including the extensions located at the given local path. Additionally the extension tests are automatically run. | ||
The node module runs a local web server that serves VS Code for the browser including the extensions located at the given local path. Additionally the extension tests are automatically run. | ||
The node module providers a command line as well as an API. | ||
@@ -15,6 +16,6 @@ ## Usage | ||
Test web extension in browser: | ||
Test a web extension in a browser: | ||
```sh | ||
vscode-test-web --browserType=webkit --extensionDevelopmentPath=$extensionLocation | ||
vscode-test-web --browserType=chromium --extensionDevelopmentPath=$extensionLocation | ||
``` | ||
@@ -25,6 +26,13 @@ | ||
```sh | ||
vscode-test-web --browserType=webkit --extensionDevelopmentPath=$extensionLocation --extensionTestsPath=$extensionLocation/dist/web/test/suite/index.js | ||
vscode-test-web --browserType=chromium --extensionDevelopmentPath=$extensionLocation --extensionTestsPath=$extensionLocation/dist/web/test/suite/index.js | ||
``` | ||
Open VS Code in the Browser on a folder with test data from the local disk: | ||
``` | ||
vscode-test-web --browserType=chromium --extensionDevelopmentPath=$extensionLocation $testDataLocation | ||
``` | ||
VS Code Browser 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. | ||
Via API: | ||
@@ -57,11 +65,11 @@ | ||
--extensionTestsPath path. [Optional]: A path to a test module to run | ||
--folder-uri. [Optional]: The folder to open VS Code on | ||
--version. 'insiders' (Default) | 'stable' | 'sources' [Optional] | ||
--open-devtools. Opens the dev tools [Optional] | ||
--headless. Whether to show the browser. Defaults to true when an extensionTestsPath is provided, otherwise false. [Optional] | ||
folderPath. A local folder to open VS Code on. The folder content will be available as a virtual file system` | ||
``` | ||
Corrsponding options are available in the API. | ||
Corresponding options are available in the API. | ||
## Development | ||
@@ -68,0 +76,0 @@ |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
74488
15
1373
99
1
10
7