@vscode/test-web 0.0.40 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/index.js CHANGED
@@ -35,20 +35,14 @@ async function runTests(options) {
35
35
  const server = await (0, main_1.runServer)(host, port, config);
36
36
  return new Promise(async (s, e) => {
37
37
  const endpoint = `http://${host}:${port}`;
38
- const configContext = async (context) => {
39
- context.once('close', () => server.close());
38
+ const configPage = async (page, browser) => {
40
39
  const unreportedOutput = [];
41
- await context.exposeFunction('codeAutomationLog', (type, args) => {
42
- try {
43
- console[type](...args);
44
- }
45
- catch (_e) {
46
- unreportedOutput.push({ type, args });
47
- }
40
+ await page.exposeFunction('codeAutomationLog', (type, args) => {
41
+ console[type](...args);
48
42
  });
49
- await context.exposeFunction('codeAutomationExit', async (code) => {
43
+ await page.exposeFunction('codeAutomationExit', async (code) => {
50
44
  try {
51
- await context.browser()?.close();
45
+ await browser.close();
52
46
  }
53
47
  catch (error) {
54
48
  console.error(`Error when closing browser: ${error}`);
@@ -67,8 +61,11 @@ async function runTests(options) {
67
61
  });
68
62
  };
69
63
  console.log(`Opening browser on ${endpoint}...`);
70
- const context = await openBrowser(endpoint, options, configContext);
71
- if (!context) {
64
+ const context = await openBrowser(endpoint, options, configPage);
65
+ if (context) {
66
+ context.once('close', () => server.close());
67
+ }
68
+ else {
72
69
  server.close();
73
70
  e(new Error('Can not run test as opening of browser failed.'));
74
71
  }
@@ -103,10 +100,8 @@ async function open(options) {
103
100
  const port = options.port ?? 3000;
104
101
  const server = await (0, main_1.runServer)(host, port, config);
105
102
  const endpoint = `http://${host}:${port}`;
106
- const configContext = async (context) => {
107
- context.once('close', () => server.close());
108
- };
109
- const context = await openBrowser(endpoint, options, configContext);
103
+ const context = await openBrowser(endpoint, options);
104
+ context?.once('close', () => server.close());
110
105
  return {
111
106
  dispose: () => {
112
107
  server.close();
@@ -115,7 +110,7 @@ async function open(options) {
115
110
  };
116
111
  }
117
112
  exports.open = open;
118
- async function openBrowser(endpoint, options, configureContext) {
113
+ async function openBrowser(endpoint, options, configPage) {
119
114
  if (options.browserType === 'none') {
120
115
  return undefined;
121
116
  }
@@ -137,7 +132,6 @@ async function openBrowser(endpoint, options, configureContext) {
137
132
  if (options.permissions) {
138
133
  context.grantPermissions(options.permissions);
139
134
  }
140
- await configureContext(context);
141
135
  // forcefully close browser if last page is closed. workaround for https://github.com/microsoft/playwright/issues/2946
142
136
  let openPages = 0;
143
137
  context.on('page', page => {
@@ -150,6 +144,9 @@ async function openBrowser(endpoint, options, configureContext) {
150
144
  });
151
145
  });
152
146
  const page = context.pages()[0] ?? await context.newPage();
147
+ if (configPage) {
148
+ await configPage(page, browser);
149
+ }
153
150
  if (options.waitForDebugger) {
154
151
  await page.waitForFunction(() => '__jsDebugIsReady' in globalThis);
155
152
  }
@@ -12,24 +12,24 @@ const http = require("http");
12
12
  const createHttpsProxyAgent = require("https-proxy-agent");
13
13
  const createHttpProxyAgent = require("http-proxy-agent");
14
14
  const url_1 = require("url");
15
- const decompress = require("decompress");
16
- const decompressTargz = require("decompress-targz");
17
15
  async function getLatestVersion(quality) {
18
16
  const update = await fetchJSON(`https://update.code.visualstudio.com/api/update/web-standalone/${quality}/latest`);
19
17
  return update;
20
18
  }
21
19
  const reset = '\x1b[G\x1b[0K';
22
- async function download(downloadUrl, destination, message) {
20
+ async function downloadAndUntar(downloadUrl, destination, message) {
23
21
  process.stdout.write(message);
22
+ if (!(0, fs_1.existsSync)(destination)) {
23
+ await fs_1.promises.mkdir(destination, { recursive: true });
24
+ }
25
+ const tar = await Promise.resolve().then(() => require('tar-fs'));
26
+ const gunzip = await Promise.resolve().then(() => require('gunzip-maybe'));
24
27
  return new Promise((resolve, reject) => {
25
28
  const httpLibrary = downloadUrl.startsWith('https') ? https : http;
26
29
  httpLibrary.get(downloadUrl, getAgent(downloadUrl), res => {
27
30
  const total = Number(res.headers['content-length']);
28
31
  let received = 0;
29
32
  let timeout;
30
- const outStream = (0, fs_1.createWriteStream)(destination);
31
- outStream.on('close', () => resolve(destination));
32
- outStream.on('error', reject);
33
33
  res.on('data', chunk => {
34
34
  if (!timeout) {
35
35
  timeout = setTimeout(() => {
@@ -45,26 +45,20 @@ async function download(downloadUrl, destination, message) {
45
45
  }
46
46
  process.stdout.write(`${reset}${message}: complete\n`);
47
47
  });
48
- res.on('error', reject);
49
- res.pipe(outStream);
48
+ const extract = res.pipe(gunzip()).pipe(tar.extract(destination, { strip: 1 }));
49
+ extract.on('finish', () => {
50
+ process.stdout.write(`Extracted to ${destination}\n`);
51
+ resolve();
52
+ });
53
+ extract.on('error', reject);
50
54
  });
51
55
  });
52
56
  }
53
- async function unzip(source, destination, message) {
54
- process.stdout.write(message);
55
- if (!(0, fs_1.existsSync)(destination)) {
56
- await fs_1.promises.mkdir(destination, { recursive: true });
57
- }
58
- await decompress(source, destination, {
59
- plugins: [
60
- decompressTargz()
61
- ],
62
- strip: 1
63
- });
64
- process.stdout.write(`${reset}${message}: complete\n`);
65
- }
66
57
  async function downloadAndUnzipVSCode(quality, vscodeTestDir) {
67
58
  const info = await getLatestVersion(quality);
59
+ if (!info.url.endsWith('.tar.gz')) {
60
+ throw new Error(`Unexpected download URL: ${info.url}. Should end with .tar.gz`);
61
+ }
68
62
  const folderName = `vscode-web-${quality}-${info.version}`;
69
63
  const downloadedPath = path.resolve(vscodeTestDir, folderName);
70
64
  if ((0, fs_1.existsSync)(downloadedPath) && (0, fs_1.existsSync)(path.join(downloadedPath, 'version'))) {
@@ -75,24 +69,14 @@ async function downloadAndUnzipVSCode(quality, vscodeTestDir) {
75
69
  }
76
70
  await fs_1.promises.mkdir(vscodeTestDir, { recursive: true });
77
71
  const productName = `VS Code ${quality === 'stable' ? 'Stable' : 'Insiders'}`;
78
- const tmpArchiveName = path.join(vscodeTestDir, `vscode-web-${quality}-${info.version}-tmp`);
79
72
  try {
80
- await download(info.url, tmpArchiveName, `Downloading ${productName}`);
81
- await unzip(tmpArchiveName, downloadedPath, `Unpacking ${productName}`);
73
+ await downloadAndUntar(info.url, downloadedPath, `Downloading ${productName}`);
82
74
  await fs_1.promises.writeFile(path.join(downloadedPath, 'version'), folderName);
83
75
  }
84
76
  catch (err) {
85
77
  console.error(err);
86
78
  throw Error(`Failed to download and unpack ${productName}`);
87
79
  }
88
- finally {
89
- try {
90
- fs_1.promises.unlink(tmpArchiveName);
91
- }
92
- catch (e) {
93
- // ignore
94
- }
95
- }
96
80
  return { type: 'static', location: downloadedPath, quality, version: info.version };
97
81
  }
98
82
  exports.downloadAndUnzipVSCode = downloadAndUnzipVSCode;
@@ -23,12 +23,14 @@ class Workbench {
23
23
  this.productOverrides = productOverrides;
24
24
  }
25
25
  async render(workbenchWebConfiguration) {
26
+ if (this.productOverrides) {
27
+ workbenchWebConfiguration.productConfiguration = { ...workbenchWebConfiguration.productConfiguration, ...this.productOverrides };
28
+ }
26
29
  const values = {
27
30
  WORKBENCH_WEB_CONFIGURATION: asJSON(workbenchWebConfiguration),
28
31
  WORKBENCH_AUTH_SESSION: '',
29
32
  WORKBENCH_WEB_BASE_URL: this.baseUrl,
30
33
  WORKBENCH_BUILTIN_EXTENSIONS: asJSON(this.builtInExtensions),
31
- WORKBENCH_PRODUCT_OVERRIDES: this.productOverrides ? asJSON(this.productOverrides) : '',
32
34
  WORKBENCH_MAIN: this.getMain()
33
35
  };
34
36
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vscode/test-web",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
4
4
  "scripts": {
5
5
  "install-extensions": "yarn --cwd=fs-provider && yarn --cwd=sample",
6
6
  "compile": "tsc -p ./ && yarn compile-fs-provider",
@@ -25,18 +25,18 @@
25
25
  "dependencies": {
26
26
  "@koa/router": "^12.0.0",
27
27
  "@koa/cors": "^4.0.0",
28
- "koa": "^2.14.1",
28
+ "koa": "^2.14.2",
29
29
  "koa-morgan": "^1.0.1",
30
30
  "koa-mount": "^4.0.0",
31
31
  "koa-static": "^5.0.0",
32
32
  "minimist": "^1.2.8",
33
- "playwright": "^1.32.2",
33
+ "playwright": "^1.32.3",
34
34
  "vscode-uri": "^3.0.7",
35
35
  "http-proxy-agent": "^5.0.0",
36
36
  "https-proxy-agent": "^5.0.1",
37
- "decompress": "^4.2.1",
38
- "decompress-targz": "^4.1.1",
39
- "get-stream": "6.0.1"
37
+ "get-stream": "6.0.1",
38
+ "tar-fs": "^2.1.1",
39
+ "gunzip-maybe": "^1.4.2"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/koa": "^2.13.6",
@@ -46,12 +46,13 @@
46
46
  "@types/koa__router": "^12.0.0",
47
47
  "@types/minimist": "^1.2.2",
48
48
  "@types/node": "16.x",
49
- "@typescript-eslint/eslint-plugin": "^5.57.0",
50
- "@typescript-eslint/parser": "^5.57.0",
51
- "@types/decompress": "^4.2.4",
52
- "eslint": "^8.37.0",
49
+ "@types/gunzip-maybe": "^1.4.0",
50
+ "@types/tar-fs": "^2.0.1",
51
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
52
+ "@typescript-eslint/parser": "^5.58.0",
53
+ "eslint": "^8.38.0",
53
54
  "eslint-plugin-header": "^3.1.1",
54
- "typescript": "^5.0.3"
55
+ "typescript": "^5.0.4"
55
56
  },
56
57
  "license": "MIT",
57
58
  "author": "Visual Studio Code Team",
@@ -25,9 +25,6 @@
25
25
  <!-- Builtin Extensions (running out of sources) -->
26
26
  <meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">
27
27
 
28
- <!-- Product Overrides (running out of sources) -->
29
- <meta id="vscode-workbench-product-overrides" data-settings="{{WORKBENCH_PRODUCT_OVERRIDES}}">
30
-
31
28
  <!-- Workbench Icon/Manifest/CSS -->
32
29
  <link rel="icon" href="{{WORKBENCH_WEB_BASE_URL}}/favicon.ico" type="image/x-icon" />
33
30
  <link rel="manifest" href="{{WORKBENCH_WEB_BASE_URL}}/manifest.json">
@@ -25,9 +25,6 @@
25
25
  <!-- Builtin Extensions (running out of sources) -->
26
26
  <meta id="vscode-workbench-builtin-extensions" data-settings="{{WORKBENCH_BUILTIN_EXTENSIONS}}">
27
27
 
28
- <!-- Product Overrides (running out of sources) -->
29
- <meta id="vscode-workbench-product-overrides" data-settings="{{WORKBENCH_PRODUCT_OVERRIDES}}">
30
-
31
28
  <!-- Workbench Icon/Manifest/CSS -->
32
29
  <link rel="icon" href="{{WORKBENCH_WEB_BASE_URL}}/favicon.ico" type="image/x-icon" />
33
30
  <link rel="manifest" href="{{WORKBENCH_WEB_BASE_URL}}/manifest.json">