Socket
Socket
Sign inDemoInstall

vscode-test

Package Overview
Dependencies
Maintainers
6
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vscode-test - npm Package Compare versions

Comparing version 1.4.1 to 1.5.0

.eslintrc.js

10

CHANGELOG.md
# Changelog
### 1.5.0 | 2021-01-25
- Fix download failing on windows with long file paths
- Make installation platform aware [#78](https://github.com/microsoft/vscode-test/issues/78)
- Download and unzip directly for faster setup
- Add download progress indicator
- Show signal that caused vscode to quit if no exit code is present [#64](https://github.com/microsoft/vscode-test/issues/64)
### 1.4.1 | 2020-10-27

@@ -129,2 +137,2 @@

- Support specifying testing locale. [#1](https://github.com/Microsoft/vscode-test/pull/1).
- Fix zip extraction failure where `.vscode-test/vscode-<VERSION>` dir doesn't exist on Linux. [#3](https://github.com/Microsoft/vscode-test/issues/3).
- Fix zip extraction failure where `.vscode-test/vscode-<VERSION>` dir doesn't exist on Linux. [#3](https://github.com/Microsoft/vscode-test/issues/3).

2

out/del.d.ts

@@ -1,1 +0,1 @@

export declare function rmdir(dir: string): Promise<{}>;
export declare function rmdir(dir: string): Promise<void>;
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
var rimraf = require("rimraf");
exports.rmdir = void 0;
const rimraf = require("rimraf");
// todo: rmdir supports a `recurse` option as of Node 12. Drop rimraf when 10 is EOL.
function rmdir(dir) {
return new Promise(function (c, e) {
rimraf(dir, function (err) {
return new Promise((c, e) => {
rimraf(dir, err => {
if (err) {

@@ -8,0 +14,0 @@ return e(err);

@@ -10,6 +10,6 @@ /**

* Download and unzip a copy of VS Code in `.vscode-test`. The paths are:
* - `.vscode-test/vscode-<VERSION>`. For example, `./vscode-test/vscode-1.32.0`
* - `.vscode-test/vscode-insiders`.
* - `.vscode-test/vscode-<PLATFORM>-<VERSION>`. For example, `./vscode-test/vscode-win32-1.32.0`
* - `.vscode-test/vscode-win32-insiders`.
*
* *If a local copy exists at `.vscode-test/vscode-<VERSION>`, skip download.*
* *If a local copy exists at `.vscode-test/vscode-<PLATFORM>-<VERSION>`, skip download.*
*

@@ -16,0 +16,0 @@ * @param version The version of VS Code to download such as `1.32.0`. You can also use

@@ -6,76 +6,27 @@ "use strict";

*--------------------------------------------------------------------------------------------*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadAndUnzipVSCode = void 0;
const fs = require("fs");
const path = require("path");
const cp = require("child_process");
const request = require("./request");
const del = require("./del");
const util_1 = require("./util");
const unzipper_1 = require("unzipper");
const stream_1 = require("stream");
const os_1 = require("os");
const util_2 = require("util");
const extensionRoot = process.cwd();
const vscodeTestDir = path.resolve(extensionRoot, '.vscode-test');
const vscodeStableReleasesAPI = `https://update.code.visualstudio.com/api/releases/stable`;
async function fetchLatestStableVersion() {
const versions = await request.getJSON(vscodeStableReleasesAPI);
if (!versions || !Array.isArray(versions) || !versions[0]) {
throw Error('Failed to get latest VS Code version');
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var https = require("https");
var fs = require("fs");
var path = require("path");
var cp = require("child_process");
var request = require("./request");
var del = require("./del");
var util_1 = require("./util");
var extensionRoot = process.cwd();
var vscodeTestDir = path.resolve(extensionRoot, '.vscode-test');
var vscodeStableReleasesAPI = "https://update.code.visualstudio.com/api/releases/stable";
function fetchLatestStableVersion() {
return __awaiter(this, void 0, void 0, function () {
var versions;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, request.getJSON(vscodeStableReleasesAPI)];
case 1:
versions = _a.sent();
if (!versions || !Array.isArray(versions) || !versions[0]) {
throw Error('Failed to get latest VS Code version');
}
return [2 /*return*/, versions[0]];
}
});
});
return versions[0];
}
function isValidVersion(version) {
return __awaiter(this, void 0, void 0, function () {
var validVersions;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, request.getJSON(vscodeStableReleasesAPI)];
case 1:
validVersions = _a.sent();
return [2 /*return*/, version === 'insiders' || validVersions.indexOf(version) !== -1];
}
});
});
async function isValidVersion(version) {
const validVersions = await request.getJSON(vscodeStableReleasesAPI);
return version === 'insiders' || validVersions.indexOf(version) !== -1;
}

@@ -89,73 +40,72 @@ /**

*/
function downloadVSCodeArchive(version, platform) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!fs.existsSync(vscodeTestDir)) {
fs.mkdirSync(vscodeTestDir);
}
return [2 /*return*/, new Promise(function (resolve, reject) {
var downloadUrl = util_1.getVSCodeDownloadUrl(version, platform);
console.log("Downloading VS Code " + version + " from " + downloadUrl);
var requestOptions = util_1.urlToOptions(downloadUrl);
https.get(requestOptions, function (res) {
if (res.statusCode !== 302) {
reject('Failed to get VS Code archive location');
}
var archiveUrl = res.headers.location;
if (!archiveUrl) {
reject('Failed to get VS Code archive location');
return;
}
var archiveRequestOptions = util_1.urlToOptions(archiveUrl);
if (archiveUrl.endsWith('.zip')) {
var archivePath_1 = path.resolve(vscodeTestDir, "vscode-" + version + ".zip");
var outStream_1 = fs.createWriteStream(archivePath_1);
outStream_1.on('close', function () {
resolve(archivePath_1);
});
https
.get(archiveRequestOptions, function (res) {
res.pipe(outStream_1);
})
.on('error', function (e) { return reject(e); });
}
else {
var zipPath_1 = path.resolve(vscodeTestDir, "vscode-" + version + ".tgz");
var outStream_2 = fs.createWriteStream(zipPath_1);
outStream_2.on('close', function () {
resolve(zipPath_1);
});
https
.get(archiveRequestOptions, function (res) {
res.pipe(outStream_2);
})
.on('error', function (e) { return reject(e); });
}
});
})];
});
async function downloadVSCodeArchive(version, platform) {
if (!fs.existsSync(vscodeTestDir)) {
fs.mkdirSync(vscodeTestDir);
}
const downloadUrl = util_1.getVSCodeDownloadUrl(version, platform);
const text = `Downloading VS Code ${version} from ${downloadUrl}`;
process.stdout.write(text);
const res = await request.getStream(downloadUrl);
if (res.statusCode !== 302) {
throw 'Failed to get VS Code archive location';
}
const archiveUrl = res.headers.location;
if (!archiveUrl) {
throw 'Failed to get VS Code archive location';
}
const download = await request.getStream(archiveUrl);
printProgress(text, download);
return { stream: download, format: archiveUrl.endsWith('.zip') ? 'zip' : 'tgz' };
}
function printProgress(baseText, res) {
const total = Number(res.headers['content-length']);
let received = 0;
let timeout;
const reset = '\x1b[G\x1b[0K';
res.on('data', chunk => {
if (!timeout) {
timeout = setTimeout(() => {
process.stdout.write(`${reset}${baseText}: ${received}/${total} (${(received / total * 100).toFixed()}%)`);
timeout = undefined;
}, 100);
}
received += chunk.length;
});
res.on('end', () => {
if (timeout) {
clearTimeout(timeout);
}
console.log(`${reset}${baseText}: complete`);
});
res.on('error', err => {
throw err;
});
}
/**
* Unzip a .zip or .tar.gz VS Code archive
* Unzip a .zip or .tar.gz VS Code archive stream.
*/
function unzipVSCode(vscodeArchivePath) {
// The 'vscode-1.32' out of '.../vscode-1.32.zip'
var dirName = path.parse(vscodeArchivePath).name;
var extractDir = path.resolve(vscodeTestDir, dirName);
var res;
if (vscodeArchivePath.endsWith('.zip')) {
if (process.platform === 'win32') {
res = cp.spawnSync('powershell.exe', [
'-NoProfile',
'-ExecutionPolicy',
'Bypass',
'-NonInteractive',
'-NoLogo',
'-Command',
"Microsoft.PowerShell.Archive\\Expand-Archive -Path \"" + vscodeArchivePath + "\" -DestinationPath \"" + extractDir + "\""
]);
async function unzipVSCode(extractDir, stream, format) {
if (format === 'zip') {
// note: this used to use Expand-Archive, but this caused a failure
// on longer file paths on windows. Instead use unzipper, which does
// not have this limitation.
//
// However it has problems that prevent it working on OSX:
// - https://github.com/ZJONSSON/node-unzipper/issues/216 (avoidable)
// - https://github.com/ZJONSSON/node-unzipper/issues/115 (not avoidable)
if (process.platform !== 'darwin') {
await new Promise((resolve, reject) => stream
.pipe(unzipper_1.Extract({ path: extractDir }))
.on('close', resolve)
.on('error', reject));
}
else {
res = cp.spawnSync('unzip', [vscodeArchivePath, '-d', "" + extractDir]);
const stagingFile = path.join(os_1.tmpdir(), `vscode-test-${Date.now()}.zip`);
try {
await util_2.promisify(stream_1.pipeline)(stream, fs.createWriteStream(stagingFile));
await spawnDecompressorChild('unzip', ['-q', stagingFile, '-d', extractDir]);
}
finally {
// fs.unlink(stagingFile, () => undefined);
}
}

@@ -168,14 +118,21 @@ }

}
res = cp.spawnSync('tar', ['-xzf', vscodeArchivePath, '-C', extractDir]);
await spawnDecompressorChild('tar', ['-xzf', '-', '-C', extractDir], stream);
}
if (res && !(res.status === 0 && res.signal === null)) {
throw Error("Failed to unzip downloaded vscode at " + vscodeArchivePath);
}
}
function spawnDecompressorChild(command, args, input) {
const child = cp.spawn(command, args, { stdio: 'pipe' });
input === null || input === void 0 ? void 0 : input.pipe(child.stdin);
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
return new Promise((resolve, reject) => {
child.on('error', reject);
child.on('exit', code => code === 0 ? resolve() : reject(new Error(`Failed to unzip archive, exited with ${code}`)));
});
}
/**
* Download and unzip a copy of VS Code in `.vscode-test`. The paths are:
* - `.vscode-test/vscode-<VERSION>`. For example, `./vscode-test/vscode-1.32.0`
* - `.vscode-test/vscode-insiders`.
* - `.vscode-test/vscode-<PLATFORM>-<VERSION>`. For example, `./vscode-test/vscode-win32-1.32.0`
* - `.vscode-test/vscode-win32-insiders`.
*
* *If a local copy exists at `.vscode-test/vscode-<VERSION>`, skip download.*
* *If a local copy exists at `.vscode-test/vscode-<PLATFORM>-<VERSION>`, skip download.*
*

@@ -189,84 +146,65 @@ * @param version The version of VS Code to download such as `1.32.0`. You can also use

*/
function downloadAndUnzipVSCode(version, platform) {
return __awaiter(this, void 0, void 0, function () {
var downloadedPath, _a, currentHash, currentDate, _b, latestHash, latestTimestamp, err_1, vscodeArchivePath, err_2;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!version) return [3 /*break*/, 5];
if (!(version === 'stable')) return [3 /*break*/, 2];
return [4 /*yield*/, fetchLatestStableVersion()];
case 1:
version = _c.sent();
return [3 /*break*/, 4];
case 2:
if (!!fs.existsSync(path.resolve(vscodeTestDir, "vscode-" + version))) return [3 /*break*/, 4];
return [4 /*yield*/, isValidVersion(version)];
case 3:
if (!(_c.sent())) {
throw Error("Invalid version " + version);
}
_c.label = 4;
case 4: return [3 /*break*/, 7];
case 5: return [4 /*yield*/, fetchLatestStableVersion()];
case 6:
version = _c.sent();
_c.label = 7;
case 7:
downloadedPath = path.resolve(vscodeTestDir, "vscode-" + version);
if (!fs.existsSync(downloadedPath)) return [3 /*break*/, 14];
if (!(version === 'insiders')) return [3 /*break*/, 13];
_a = util_1.insidersDownloadDirMetadata(downloadedPath), currentHash = _a.version, currentDate = _a.date;
return [4 /*yield*/, util_1.getLatestInsidersMetadata(util_1.systemDefaultPlatform)];
case 8:
_b = _c.sent(), latestHash = _b.version, latestTimestamp = _b.timestamp;
if (!(currentHash === latestHash)) return [3 /*break*/, 9];
console.log("Found .vscode-test/vscode-insiders matching latest Insiders release. Skipping download.");
return [2 /*return*/, Promise.resolve(util_1.insidersDownloadDirToExecutablePath(downloadedPath))];
case 9:
_c.trys.push([9, 11, , 12]);
console.log("Remove outdated Insiders at " + downloadedPath + " and re-downloading.");
console.log("Old: " + currentHash + " | " + currentDate);
console.log("New: " + latestHash + " | " + new Date(parseInt(latestTimestamp, 10)).toISOString());
return [4 /*yield*/, del.rmdir(downloadedPath)];
case 10:
_c.sent();
console.log("Removed " + downloadedPath);
return [3 /*break*/, 12];
case 11:
err_1 = _c.sent();
console.error(err_1);
throw Error("Failed to remove outdated Insiders at " + downloadedPath + ".");
case 12: return [3 /*break*/, 14];
case 13:
console.log("Found .vscode-test/vscode-" + version + ". Skipping download.");
return [2 /*return*/, Promise.resolve(util_1.downloadDirToExecutablePath(downloadedPath))];
case 14:
_c.trys.push([14, 16, , 17]);
return [4 /*yield*/, downloadVSCodeArchive(version, platform)];
case 15:
vscodeArchivePath = _c.sent();
if (fs.existsSync(vscodeArchivePath)) {
unzipVSCode(vscodeArchivePath);
console.log("Downloaded VS Code " + version + " into .vscode-test/vscode-" + version);
// Remove archive
fs.unlinkSync(vscodeArchivePath);
}
return [3 /*break*/, 17];
case 16:
err_2 = _c.sent();
console.error(err_2);
throw Error("Failed to download and unzip VS Code " + version);
case 17:
if (version === 'insiders') {
return [2 /*return*/, Promise.resolve(util_1.insidersDownloadDirToExecutablePath(path.resolve(vscodeTestDir, "vscode-" + version)))];
}
else {
return [2 /*return*/, util_1.downloadDirToExecutablePath(path.resolve(vscodeTestDir, "vscode-" + version))];
}
return [2 /*return*/];
async function downloadAndUnzipVSCode(version, platform = util_1.systemDefaultPlatform) {
if (version) {
if (version === 'stable') {
version = await fetchLatestStableVersion();
}
else {
/**
* Only validate version against server when no local download that matches version exists
*/
if (!fs.existsSync(path.resolve(vscodeTestDir, `vscode-${platform}-${version}`))) {
if (!(await isValidVersion(version))) {
throw Error(`Invalid version ${version}`);
}
}
});
});
}
}
else {
version = await fetchLatestStableVersion();
}
const downloadedPath = path.resolve(vscodeTestDir, `vscode-${platform}-${version}`);
if (fs.existsSync(downloadedPath)) {
if (version === 'insiders') {
const { version: currentHash, date: currentDate } = util_1.insidersDownloadDirMetadata(downloadedPath);
const { version: latestHash, timestamp: latestTimestamp } = await util_1.getLatestInsidersMetadata(util_1.systemDefaultPlatform);
if (currentHash === latestHash) {
console.log(`Found insiders matching latest Insiders release. Skipping download.`);
return Promise.resolve(util_1.insidersDownloadDirToExecutablePath(downloadedPath));
}
else {
try {
console.log(`Remove outdated Insiders at ${downloadedPath} and re-downloading.`);
console.log(`Old: ${currentHash} | ${currentDate}`);
console.log(`New: ${latestHash} | ${new Date(latestTimestamp).toISOString()}`);
await del.rmdir(downloadedPath);
console.log(`Removed ${downloadedPath}`);
}
catch (err) {
console.error(err);
throw Error(`Failed to remove outdated Insiders at ${downloadedPath}.`);
}
}
}
else {
console.log(`Found .vscode-test/vscode-${platform}-${version}. Skipping download.`);
return Promise.resolve(util_1.downloadDirToExecutablePath(downloadedPath));
}
}
try {
const { stream, format } = await downloadVSCodeArchive(version, platform);
await unzipVSCode(downloadedPath, stream, format);
console.log(`Downloaded VS Code ${version} into .vscode-test/vscode-${platform}-${version}`);
}
catch (err) {
console.error(err);
throw Error(`Failed to download and unzip VS Code ${version}`);
}
if (version === 'insiders') {
return Promise.resolve(util_1.insidersDownloadDirToExecutablePath(path.resolve(vscodeTestDir, `vscode-${platform}-${version}`)));
}
else {
return util_1.downloadDirToExecutablePath(path.resolve(vscodeTestDir, `vscode-${platform}-${version}`));
}
}
exports.downloadAndUnzipVSCode = downloadAndUnzipVSCode;

@@ -7,7 +7,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveCliPathFromVSCodeExecutablePath = exports.runTests = exports.downloadAndUnzipVSCode = void 0;
var download_1 = require("./download");
exports.downloadAndUnzipVSCode = download_1.downloadAndUnzipVSCode;
Object.defineProperty(exports, "downloadAndUnzipVSCode", { enumerable: true, get: function () { return download_1.downloadAndUnzipVSCode; } });
var runTest_1 = require("./runTest");
exports.runTests = runTest_1.runTests;
Object.defineProperty(exports, "runTests", { enumerable: true, get: function () { return runTest_1.runTests; } });
var util_1 = require("./util");
exports.resolveCliPathFromVSCodeExecutablePath = util_1.resolveCliPathFromVSCodeExecutablePath;
Object.defineProperty(exports, "resolveCliPathFromVSCodeExecutablePath", { enumerable: true, get: function () { return util_1.resolveCliPathFromVSCodeExecutablePath; } });

@@ -1,1 +0,4 @@

export declare function getJSON(api: string): Promise<any>;
/// <reference types="node" />
import { IncomingMessage } from 'http';
export declare function getStream(api: string): Promise<IncomingMessage>;
export declare function getJSON<T>(api: string): Promise<T>;

@@ -6,67 +6,35 @@ "use strict";

*--------------------------------------------------------------------------------------------*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
Object.defineProperty(exports, "__esModule", { value: true });
exports.getJSON = exports.getStream = void 0;
const https = require("https");
const util_1 = require("./util");
async function getStream(api) {
return new Promise((resolve, reject) => {
https.get(api, util_1.urlToOptions(api), res => resolve(res)).on('error', reject);
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
exports.getStream = getStream;
async function getJSON(api) {
return new Promise((resolve, reject) => {
https.get(api, util_1.urlToOptions(api), res => {
if (res.statusCode !== 200) {
reject('Failed to get JSON');
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var https = require("https");
var util_1 = require("./util");
function getJSON(api) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
https.get(util_1.urlToOptions(api), function (res) {
if (res.statusCode !== 200) {
reject('Failed to get JSON');
}
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
try {
var jsonData = JSON.parse(data);
resolve(jsonData);
}
catch (err) {
console.error("Failed to parse response from " + api + " as JSON");
reject(err);
}
});
res.on('error', function (err) {
reject(err);
});
});
})];
let data = '';
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
try {
const jsonData = JSON.parse(data);
resolve(jsonData);
}
catch (err) {
console.error(`Failed to parse response from ${api} as JSON`);
reject(err);
}
});
res.on('error', err => {
reject(err);
});
});

@@ -73,0 +41,0 @@ });

@@ -6,40 +6,6 @@ "use strict";

*--------------------------------------------------------------------------------------------*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var cp = require("child_process");
var download_1 = require("./download");
exports.runTests = void 0;
const cp = require("child_process");
const download_1 = require("./download");
/**

@@ -50,66 +16,50 @@ * Run VS Code extension test

*/
function runTests(options) {
return __awaiter(this, void 0, void 0, function () {
var _a, args;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (!!options.vscodeExecutablePath) return [3 /*break*/, 2];
_a = options;
return [4 /*yield*/, download_1.downloadAndUnzipVSCode(options.version, options.platform)];
case 1:
_a.vscodeExecutablePath = _b.sent();
_b.label = 2;
case 2:
args = [
// https://github.com/microsoft/vscode/issues/84238
'--no-sandbox',
'--extensionDevelopmentPath=' + options.extensionDevelopmentPath,
'--extensionTestsPath=' + options.extensionTestsPath
];
if (options.launchArgs) {
args = options.launchArgs.concat(args);
}
return [2 /*return*/, innerRunTests(options.vscodeExecutablePath, args, options.extensionTestsEnv)];
}
});
});
async function runTests(options) {
if (!options.vscodeExecutablePath) {
options.vscodeExecutablePath = await download_1.downloadAndUnzipVSCode(options.version, options.platform);
}
let args = [
// https://github.com/microsoft/vscode/issues/84238
'--no-sandbox',
'--extensionDevelopmentPath=' + options.extensionDevelopmentPath,
'--extensionTestsPath=' + options.extensionTestsPath
];
if (options.launchArgs) {
args = options.launchArgs.concat(args);
}
return innerRunTests(options.vscodeExecutablePath, args, options.extensionTestsEnv);
}
exports.runTests = runTests;
function innerRunTests(executable, args, testRunnerEnv) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve, reject) {
var fullEnv = Object.assign({}, process.env, testRunnerEnv);
var cmd = cp.spawn(executable, args, { env: fullEnv });
cmd.stdout.on('data', function (data) {
console.log(data.toString());
});
cmd.stderr.on('data', function (data) {
console.error(data.toString());
});
cmd.on('error', function (data) {
console.log('Test error: ' + data.toString());
});
var finished = false;
function onProcessClosed(code, signal) {
if (finished) {
return;
}
finished = true;
console.log("Exit code: " + code);
if (code === null) {
reject(signal);
}
else if (code !== 0) {
reject('Failed');
}
console.log('Done\n');
resolve(code);
}
cmd.on('close', onProcessClosed);
cmd.on('exit', onProcessClosed);
})];
async function innerRunTests(executable, args, testRunnerEnv) {
return new Promise((resolve, reject) => {
const fullEnv = Object.assign({}, process.env, testRunnerEnv);
const cmd = cp.spawn(executable, args, { env: fullEnv });
cmd.stdout.on('data', function (data) {
console.log(data.toString());
});
cmd.stderr.on('data', function (data) {
console.error(data.toString());
});
cmd.on('error', function (data) {
console.log('Test error: ' + data.toString());
});
let finished = false;
function onProcessClosed(code, signal) {
if (finished) {
return;
}
finished = true;
console.log(`Exit code: ${code !== null && code !== void 0 ? code : signal}`);
if (code === null) {
reject(signal);
}
else if (code !== 0) {
reject('Failed');
}
console.log('Done\n');
resolve(code !== null && code !== void 0 ? code : -1);
}
cmd.on('close', onProcessClosed);
cmd.on('exit', onProcessClosed);
});
}
/// <reference types="node" />
import * as https from 'https';
import { DownloadPlatform } from './download';
export declare let systemDefaultPlatform: any;
export declare let systemDefaultPlatform: string;
export declare function getVSCodeDownloadUrl(version: string, platform?: DownloadPlatform): string;

@@ -13,3 +13,13 @@ export declare function urlToOptions(url: string): https.RequestOptions;

};
export declare function getLatestInsidersMetadata(platform: string): Promise<any>;
export interface IUpdateMetadata {
url: string;
name: string;
version: string;
productVersion: string;
hash: string;
timestamp: number;
sha256hash: string;
supportsFastUpdate: boolean;
}
export declare function getLatestInsidersMetadata(platform: string): Promise<IUpdateMetadata>;
/**

@@ -16,0 +26,0 @@ * Resolve the VS Code cli path from executable path returned from `downloadAndUnzipVSCode`.

@@ -6,41 +6,10 @@ "use strict";

*--------------------------------------------------------------------------------------------*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var path = require("path");
var url_1 = require("url");
var request = require("./request");
exports.resolveCliPathFromVSCodeExecutablePath = exports.getLatestInsidersMetadata = exports.insidersDownloadDirMetadata = exports.insidersDownloadDirToExecutablePath = exports.downloadDirToExecutablePath = exports.urlToOptions = exports.getVSCodeDownloadUrl = exports.systemDefaultPlatform = void 0;
const path = require("path");
const url_1 = require("url");
const request = require("./request");
const createHttpProxyAgent = require("https-proxy-agent");
const createHttpsProxyAgent = require("http-proxy-agent");
const fs_1 = require("fs");
switch (process.platform) {

@@ -57,26 +26,25 @@ case 'darwin':

function getVSCodeDownloadUrl(version, platform) {
var downloadPlatform = platform || exports.systemDefaultPlatform;
const downloadPlatform = platform || exports.systemDefaultPlatform;
if (version === 'insiders') {
return "https://update.code.visualstudio.com/latest/" + downloadPlatform + "/insider";
return `https://update.code.visualstudio.com/latest/${downloadPlatform}/insider`;
}
return "https://update.code.visualstudio.com/" + version + "/" + downloadPlatform + "/stable";
return `https://update.code.visualstudio.com/${version}/${downloadPlatform}/stable`;
}
exports.getVSCodeDownloadUrl = getVSCodeDownloadUrl;
var HttpsProxyAgent = require('https-proxy-agent');
var HttpProxyAgent = require('http-proxy-agent');
var PROXY_AGENT = undefined;
var HTTPS_PROXY_AGENT = undefined;
let PROXY_AGENT = undefined;
let HTTPS_PROXY_AGENT = undefined;
if (process.env.npm_config_proxy) {
PROXY_AGENT = new HttpProxyAgent(process.env.npm_config_proxy);
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_proxy);
PROXY_AGENT = createHttpProxyAgent(process.env.npm_config_proxy);
HTTPS_PROXY_AGENT = createHttpsProxyAgent(process.env.npm_config_proxy);
}
if (process.env.npm_config_https_proxy) {
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_https_proxy);
HTTPS_PROXY_AGENT = createHttpsProxyAgent(process.env.npm_config_https_proxy);
}
function urlToOptions(url) {
var options = url_1.parse(url);
if (PROXY_AGENT && options.protocol.startsWith('http:')) {
const parsed = new url_1.URL(url);
const options = {};
if (PROXY_AGENT && parsed.protocol.startsWith('http:')) {
options.agent = PROXY_AGENT;
}
if (HTTPS_PROXY_AGENT && options.protocol.startsWith('https:')) {
if (HTTPS_PROXY_AGENT && parsed.protocol.startsWith('https:')) {
options.agent = HTTPS_PROXY_AGENT;

@@ -112,3 +80,3 @@ }

function insidersDownloadDirMetadata(dir) {
var productJsonPath;
let productJsonPath;
if (process.platform === 'win32') {

@@ -123,3 +91,3 @@ productJsonPath = path.resolve(dir, 'resources/app/product.json');

}
var productJson = require(productJsonPath);
const productJson = JSON.parse(fs_1.readFileSync(productJsonPath, 'utf-8'));
return {

@@ -131,14 +99,5 @@ version: productJson.commit,

exports.insidersDownloadDirMetadata = insidersDownloadDirMetadata;
function getLatestInsidersMetadata(platform) {
return __awaiter(this, void 0, void 0, function () {
var remoteUrl;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
remoteUrl = "https://update.code.visualstudio.com/api/update/" + platform + "/insider/latest";
return [4 /*yield*/, request.getJSON(remoteUrl)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
async function getLatestInsidersMetadata(platform) {
const remoteUrl = `https://update.code.visualstudio.com/api/update/${platform}/insider/latest`;
return await request.getJSON(remoteUrl);
}

@@ -145,0 +104,0 @@ exports.getLatestInsidersMetadata = getLatestInsidersMetadata;

{
"name": "vscode-test",
"version": "1.4.1",
"version": "1.5.0",
"scripts": {
"compile": "tsc -p ./",
"watch": "tsc -w -p ./",
"prepublish": "tsc -p ./"
"prepublish": "tsc -p ./",
"test": "eslint lib --ext ts && tsc --noEmit"
},

@@ -14,10 +15,16 @@ "main": "./out/index.js",

"dependencies": {
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.4",
"rimraf": "^2.6.3"
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "^5.0.0",
"rimraf": "^3.0.2",
"unzipper": "^0.10.11"
},
"devDependencies": {
"@types/node": "8",
"@types/rimraf": "^2.0.2",
"typescript": "^3.4.3"
"@types/node": "^12",
"@types/rimraf": "^3.0.0",
"@types/unzipper": "^0.10.3",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"eslint": "^7.17.0",
"eslint-plugin-header": "^3.1.0",
"typescript": "^4.1.3"
},

@@ -33,2 +40,2 @@ "license": "MIT",

}
}
}

@@ -1,13 +0,4 @@

<p>
<h1 align="center">vscode-test</h1>
</p>
# vscode-test
<p align="center">
<a href="https://dev.azure.com/vscode/vscode-test/_build?definitionId=15">
<img src="https://img.shields.io/azure-devops/build/vscode/350ef5c4-15fc-411a-9a5e-0622da4da69c/15.svg?label=Azure%20DevOps&logo=Azure%20Devops&style=flat-square">
</a>
<a href="https://travis-ci.org/microsoft/vscode-test">
<img src="https://img.shields.io/travis/microsoft/vscode-test.svg?label=Travis&logo=Travis&style=flat-square">
</a>
</p>
![Test Status Badge](https://github.com/microsoft/vscode-test/workflows/Tests/badge.svg)

@@ -18,3 +9,3 @@ This module helps you test VS Code extensions.

- Node >= 8.x
- Node >= 12.x
- Windows >= Windows Server 2012+ / Win10+ (anything with Powershell >= 5.0)

@@ -21,0 +12,0 @@ - macOS

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc