@vscode/test-web
Advanced tools
Comparing version 0.0.57 to 0.0.58
# Changelog | ||
## 0.0.58 | ||
* new option `--commit` to specify the build of VS Code to use. By default the latest build is used. | ||
## 0.0.37 | ||
* new option `--testRunnerDataDir` to set the temporary folder for storing the VS Code builds used for running the tests | ||
## 0.0.28 | ||
@@ -7,0 +9,0 @@ * new option `--coi` to enable cross origin isolation. |
@@ -939,10 +939,9 @@ { | ||
"node_modules/micromatch": { | ||
"version": "4.0.4", | ||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", | ||
"integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", | ||
"version": "4.0.8", | ||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", | ||
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", | ||
"dev": true, | ||
"license": "MIT", | ||
"dependencies": { | ||
"braces": "^3.0.1", | ||
"picomatch": "^2.2.3" | ||
"braces": "^3.0.3", | ||
"picomatch": "^2.3.1" | ||
}, | ||
@@ -1084,7 +1083,6 @@ "engines": { | ||
"node_modules/picomatch": { | ||
"version": "2.3.0", | ||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.0.tgz", | ||
"integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==", | ||
"version": "2.3.1", | ||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", | ||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", | ||
"dev": true, | ||
"license": "MIT", | ||
"engines": { | ||
@@ -1091,0 +1089,0 @@ "node": ">=8.6" |
@@ -20,3 +20,4 @@ { | ||
"enabledApiProposals": [ | ||
"fileSearchProvider" | ||
"fileSearchProvider", | ||
"textSearchProvider" | ||
], | ||
@@ -23,0 +24,0 @@ "contributes": { |
@@ -7,2 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDownloadURL = getDownloadURL; | ||
exports.downloadAndUnzipVSCode = downloadAndUnzipVSCode; | ||
@@ -13,2 +14,3 @@ exports.fetch = fetch; | ||
exports.fileExists = fileExists; | ||
exports.readFileInRepo = readFileInRepo; | ||
const fs_1 = require("fs"); | ||
@@ -21,6 +23,20 @@ const path = require("path"); | ||
const url_1 = require("url"); | ||
async function getLatestVersion(quality) { | ||
const update = await fetchJSON(`https://update.code.visualstudio.com/api/update/web-standalone/${quality}/latest`); | ||
return update; | ||
async function getLatestBuild(quality) { | ||
return await fetchJSON(`https://update.code.visualstudio.com/api/update/web-standalone/${quality}/latest`); | ||
} | ||
async function getDownloadURL(quality, commit) { | ||
return new Promise((resolve, reject) => { | ||
const url = `https://update.code.visualstudio.com/commit:${commit}/web-standalone/${quality}`; | ||
const httpLibrary = url.startsWith('https') ? https : http; | ||
httpLibrary.get(url, { method: 'HEAD', ...getAgent(url) }, res => { | ||
console.log(res.statusCode, res.headers.location); | ||
if ((res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) && res.headers.location) { | ||
resolve(res.headers.location); | ||
} | ||
else { | ||
resolve(undefined); | ||
} | ||
}); | ||
}); | ||
} | ||
const reset = '\x1b[G\x1b[0K'; | ||
@@ -64,11 +80,22 @@ async function downloadAndUntar(downloadUrl, destination, message) { | ||
} | ||
async function downloadAndUnzipVSCode(quality, vscodeTestDir) { | ||
const info = await getLatestVersion(quality); | ||
const folderName = `vscode-web-${quality}-${info.version}`; | ||
async function downloadAndUnzipVSCode(vscodeTestDir, quality, commit) { | ||
let downloadURL; | ||
if (!commit) { | ||
const info = await getLatestBuild(quality); | ||
commit = info.version; | ||
downloadURL = info.url; | ||
} | ||
const folderName = `vscode-web-${quality}-${commit}`; | ||
const downloadedPath = path.resolve(vscodeTestDir, folderName); | ||
if ((0, fs_1.existsSync)(downloadedPath) && (0, fs_1.existsSync)(path.join(downloadedPath, 'version'))) { | ||
return { type: 'static', location: downloadedPath, quality, version: info.version }; | ||
return { type: 'static', location: downloadedPath, quality, version: commit }; | ||
} | ||
if (!downloadURL) { | ||
downloadURL = await getDownloadURL(quality, commit); | ||
if (!downloadURL) { | ||
throw Error(`Failed to find a download for ${quality} and ${commit}`); | ||
} | ||
} | ||
if ((0, fs_1.existsSync)(vscodeTestDir)) { | ||
await fs_1.promises.rmdir(vscodeTestDir, { recursive: true, maxRetries: 5 }); | ||
await fs_1.promises.rm(vscodeTestDir, { recursive: true, maxRetries: 5 }); | ||
} | ||
@@ -78,3 +105,3 @@ await fs_1.promises.mkdir(vscodeTestDir, { recursive: true }); | ||
try { | ||
await downloadAndUntar(info.url, downloadedPath, `Downloading ${productName}`); | ||
await downloadAndUntar(downloadURL, downloadedPath, `Downloading ${productName}`); | ||
await fs_1.promises.writeFile(path.join(downloadedPath, 'version'), folderName); | ||
@@ -84,5 +111,5 @@ } | ||
console.error(err); | ||
throw Error(`Failed to download and unpack ${productName}`); | ||
throw Error(`Failed to download and unpack ${productName}.${commit ? ' Did you specify a valid commit?' : ''}`); | ||
} | ||
return { type: 'static', location: downloadedPath, quality, version: info.version }; | ||
return { type: 'static', location: downloadedPath, quality, version: commit }; | ||
} | ||
@@ -156,1 +183,4 @@ async function fetch(api) { | ||
} | ||
async function readFileInRepo(pathInRepo) { | ||
return (await fs_1.promises.readFile(path.resolve(__dirname, '../..', pathInRepo))).toString(); | ||
} |
@@ -13,4 +13,4 @@ "use strict"; | ||
const extensions_1 = require("./extensions"); | ||
const mounts_1 = require("./mounts"); | ||
const download_1 = require("./download"); | ||
const mounts_1 = require("./mounts"); | ||
function asJSON(value) { | ||
@@ -20,2 +20,8 @@ return JSON.stringify(value).replace(/"/g, '"'); | ||
class Workbench { | ||
baseUrl; | ||
dev; | ||
esm; | ||
devCSSModules; | ||
builtInExtensions; | ||
productOverrides; | ||
constructor(baseUrl, dev, esm, devCSSModules, builtInExtensions = [], productOverrides) { | ||
@@ -35,10 +41,8 @@ this.baseUrl = baseUrl; | ||
WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration), | ||
WORKBENCH_AUTH_SESSION: '', | ||
WORKBENCH_WEB_BASE_URL: this.baseUrl, | ||
WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions), | ||
WORKBENCH_MAIN: this.getMain(), | ||
WORKBENCH_DEV_CSS_MODULES: JSON.stringify(this.devCSSModules) | ||
WORKBENCH_MAIN: await this.getMain() | ||
}; | ||
try { | ||
const workbenchTemplate = (await fs_1.promises.readFile(path.resolve(__dirname, `../../views/workbench${this.esm ? '-esm' : ''}.html`))).toString(); | ||
const workbenchTemplate = await (0, download_1.readFileInRepo)(`views/workbench${this.esm ? '-esm' : ''}.html`); | ||
return workbenchTemplate.replace(/\{\{([^}]+)\}\}/g, (_, key) => values[key] ?? 'undefined'); | ||
@@ -50,16 +54,35 @@ } | ||
} | ||
getMain() { | ||
async getMain() { | ||
const lines = []; | ||
if (this.esm) { | ||
return `<script type="module" src="${this.baseUrl}/out/vs/code/browser/workbench/workbench.js"></script>`; | ||
let workbenchMain = await (0, download_1.readFileInRepo)(`out/browser/esm/main.js`); | ||
if (this.dev) { | ||
lines.push("<script>", `globalThis._VSCODE_CSS_MODULES = ${JSON.stringify(this.devCSSModules)};`, "</script>", "<script>", "const sheet = document.getElementById('vscode-css-modules').sheet;", "globalThis._VSCODE_CSS_LOAD = function (url) { sheet.insertRule(`@import url(${url});`); };", "", "const importMap = { imports: {} };", "for (const cssModule of globalThis._VSCODE_CSS_MODULES) {", " const cssUrl = new URL(cssModule, globalThis._VSCODE_FILE_ROOT).href;", " const jsSrc = `globalThis._VSCODE_CSS_LOAD('${cssUrl}');\\n`;", " const blob = new Blob([jsSrc], { type: 'application/javascript' });", " importMap.imports[cssUrl] = URL.createObjectURL(blob);", "}", "const importMapElement = document.createElement('script');", "importMapElement.type = 'importmap';", "importMapElement.setAttribute('nonce', '1nline-m4p');", "importMapElement.textContent = JSON.stringify(importMap, undefined, 2);", "document.head.appendChild(importMapElement);", "</script>"); | ||
workbenchMain = workbenchMain.replace('./workbench.api', `${this.baseUrl}/out/vs/workbench/workbench.web.main.js`); | ||
lines.push(`<script type="module">${workbenchMain}</script>`); | ||
} | ||
else { | ||
workbenchMain = workbenchMain.replace('./workbench.api', `${this.baseUrl}/out/vs/workbench/workbench.web.main.internal.js`); | ||
lines.push(`<script src="${this.baseUrl}/out/nls.messages.js"></script>`); | ||
lines.push(`<script type="module">${workbenchMain}</script>`); | ||
} | ||
return lines.join('\n'); | ||
} | ||
if (this.dev) { | ||
return `<script> require(['vs/code/browser/workbench/workbench'], function() {}); </script>`; | ||
else { | ||
let workbenchMain = await (0, download_1.readFileInRepo)(`out/browser/amd/main.js`); // defines a AMD module `vscode-web-browser-main` | ||
workbenchMain = workbenchMain.replace('./workbench.api', `vs/workbench/workbench.web.main`); | ||
workbenchMain = workbenchMain + '\nrequire(["vscode-web-browser-main"], function() { });'; | ||
if (this.dev) { | ||
} | ||
else { | ||
lines.push(`<script src="${this.baseUrl}/out/nls.messages.js"></script>`); | ||
lines.push(`<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.nls.js"></script>`); | ||
lines.push(`<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.js"></script>`); | ||
} | ||
lines.push(`<script>${workbenchMain}</script>`); | ||
} | ||
return `<script src="${this.baseUrl}/out/nls.messages.js"></script>` | ||
+ `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.nls.js"></script>` | ||
+ `<script src="${this.baseUrl}/out/vs/workbench/workbench.web.main.js"></script>` | ||
+ `<script src="${this.baseUrl}/out/vs/code/browser/workbench/workbench.js"></script>`; | ||
return lines.join('\n'); | ||
} | ||
async renderCallback() { | ||
return await (0, download_1.fetch)(`${this.baseUrl}/out/vs/code/browser/workbench/callback.html`); | ||
return await (0, download_1.readFileInRepo)(`views/callback.html`); | ||
} | ||
@@ -122,4 +145,6 @@ } | ||
const productOverrides = await getProductOverrides(config.build.location); | ||
const devCSSModules = config.esm ? await getDevCssModules(config.build.location) : []; | ||
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, config.esm, devCSSModules, builtInExtensions, { | ||
const esm = config.esm || await isESM(config.build.location); | ||
console.log('Using ESM loader:', esm); | ||
const devCSSModules = esm ? await getDevCssModules(config.build.location) : []; | ||
ctx.state.workbench = new Workbench(`${ctx.protocol}://${ctx.host}/static/sources`, true, esm, devCSSModules, builtInExtensions, { | ||
...productOverrides, | ||
@@ -167,1 +192,10 @@ webEndpointUrlTemplate: `${ctx.protocol}://{{uuid}}.${ctx.host}/static/sources`, | ||
} | ||
async function isESM(vsCodeDevLocation) { | ||
try { | ||
const packageJSON = await fs_1.promises.readFile(path.join(vsCodeDevLocation, 'out', 'package.json')); | ||
return JSON.parse(packageJSON.toString()).type === 'module'; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "@vscode/test-web", | ||
"version": "0.0.57", | ||
"version": "0.0.58", | ||
"scripts": { | ||
"install-extensions": "npm i --prefix=fs-provider && npm i --prefix=sample", | ||
"compile": "tsc -p ./ && npm run compile-fs-provider", | ||
"watch": "tsc -w -p ./", | ||
"compile": "tsc -b ./ && npm run compile-fs-provider", | ||
"watch": "tsc -b -w ./", | ||
"prepack": "npm run compile", | ||
@@ -18,5 +18,5 @@ "test": "eslint src && tsc --noEmit", | ||
}, | ||
"main": "./out/index.js", | ||
"main": "./out/server/index.js", | ||
"bin": { | ||
"vscode-test-web": "./out/index.js" | ||
"vscode-test-web": "./out/server/index.js" | ||
}, | ||
@@ -55,4 +55,4 @@ "engines": { | ||
"@types/tar-fs": "^2.0.4", | ||
"@typescript-eslint/eslint-plugin": "^8.3.0", | ||
"@typescript-eslint/parser": "^8.3.0", | ||
"@typescript-eslint/eslint-plugin": "^8.4.0", | ||
"@typescript-eslint/parser": "^8.4.0", | ||
"eslint": "^9.9.1", | ||
@@ -59,0 +59,0 @@ "@tony.ganchev/eslint-plugin-header": "^3.1.2", |
@@ -83,2 +83,3 @@ # @vscode/test-web | ||
| --quality | `insiders` (default), or `stable`. Ignored when sourcesPath is provided. | | ||
| --commit | commitHash The servion of the server to use. Defaults to latest build version of the given quality. Ignored when sourcesPath is provided. | | ||
| --sourcesPath | If set, runs the server from VS Code sources located at the given path. Make sure the sources and extensions are compiled (`yarn compile` and `yarn compile-web`). | | ||
@@ -85,0 +86,0 @@ | --headless | If set, hides the browser. Defaults to true when an extensionTestsPath is provided, otherwise false. | |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
412525
23
5974
129