158 lines
5.4 KiB
JavaScript
Executable File
158 lines
5.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
var remote = require('gulp-remote-src-vscode');
|
|
var vzip = require('gulp-vinyl-zip');
|
|
var symdest = require('gulp-symdest');
|
|
var untar = require('gulp-untar');
|
|
var gunzip = require('gulp-gunzip');
|
|
var chmod = require('gulp-chmod');
|
|
var filter = require('gulp-filter');
|
|
var path = require('path');
|
|
var cp = require('child_process');
|
|
var fs = require('fs');
|
|
var shared = require('../lib/shared');
|
|
var request = require('request');
|
|
var source = require('vinyl-source-stream');
|
|
|
|
var version = process.env.CODE_VERSION || '*';
|
|
var isInsiders = version === 'insiders';
|
|
|
|
var testRunFolder = path.join('.vscode-test', isInsiders ? 'insiders' : 'stable');
|
|
var testRunFolderAbsolute = path.join(process.cwd(), testRunFolder);
|
|
|
|
var downloadPlatform = (process.platform === 'darwin') ? 'darwin' : process.platform === 'win32' ? 'win32-archive' : 'linux-x64';
|
|
|
|
var windowsExecutable;
|
|
var darwinExecutable;
|
|
var linuxExecutable;
|
|
|
|
if (isInsiders) {
|
|
windowsExecutable = path.join(testRunFolderAbsolute, 'Code - Insiders.exe');
|
|
darwinExecutable = path.join(testRunFolderAbsolute, 'Visual Studio Code - Insiders.app', 'Contents', 'MacOS', 'Electron');
|
|
linuxExecutable = path.join(testRunFolderAbsolute, 'VSCode-linux-x64', 'code-insiders');
|
|
} else {
|
|
windowsExecutable = path.join(testRunFolderAbsolute, 'Code.exe');
|
|
darwinExecutable = path.join(testRunFolderAbsolute, 'Visual Studio Code.app', 'Contents', 'MacOS', 'Electron');
|
|
linuxExecutable = path.join(testRunFolderAbsolute, 'VSCode-linux-x64', 'code');
|
|
if (['0.10.1', '0.10.2', '0.10.3', '0.10.4', '0.10.5', '0.10.6', '0.10.7', '0.10.8', '0.10.9'].indexOf(version) >= 0) {
|
|
linuxExecutable = path.join(testRunFolderAbsolute, 'VSCode-linux-x64', 'Code');
|
|
}
|
|
}
|
|
|
|
var testsFolder;
|
|
if (process.env.CODE_TESTS_PATH) {
|
|
testsFolder = process.env.CODE_TESTS_PATH;
|
|
} else if (fs.existsSync(path.join(process.cwd(), 'out', 'test'))) {
|
|
testsFolder = path.join(process.cwd(), 'out', 'test'); // TS extension
|
|
} else {
|
|
testsFolder = path.join(process.cwd(), 'test'); // JS extension
|
|
}
|
|
|
|
var testsWorkspace = process.env.CODE_TESTS_WORKSPACE || testsFolder;
|
|
var extensionsFolder = process.env.CODE_EXTENSIONS_PATH || process.cwd();
|
|
var executable = (process.platform === 'darwin') ? darwinExecutable : process.platform === 'win32' ? windowsExecutable : linuxExecutable;
|
|
|
|
console.log('### VS Code Extension Test Run ###');
|
|
console.log('Current working directory: ' + process.cwd());
|
|
|
|
function runTests() {
|
|
var args = [
|
|
testsWorkspace,
|
|
'--extensionDevelopmentPath=' + extensionsFolder,
|
|
'--extensionTestsPath=' + testsFolder
|
|
];
|
|
|
|
console.log('Running extension tests: ' + [executable, args.join(' ')].join(' '));
|
|
|
|
var cmd = cp.spawn(executable, args);
|
|
|
|
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('Failed to execute tests: ' + data.toString());
|
|
});
|
|
|
|
cmd.on('close', function (code) {
|
|
console.log('Tests exited with code: ' + code);
|
|
|
|
if (code !== 0) {
|
|
process.exit(code); // propagate exit code to outer runner
|
|
}
|
|
});
|
|
}
|
|
|
|
function downloadExecutableAndRunTests() {
|
|
getDownloadUrl(function (downloadUrl) {
|
|
console.log('Downloading VS Code into "' + testRunFolderAbsolute + '" from: ' + downloadUrl);
|
|
|
|
var version = downloadUrl.match(/\d+\.\d+\.\d+/)[0].split('\.');
|
|
var isTarGz = downloadUrl.match(/linux/) && version[0] >= 1 && version[1] >= 5;
|
|
|
|
var stream;
|
|
if (isTarGz) {
|
|
var gulpFilter = filter(['VSCode-linux-x64/code', 'VSCode-linux-x64/code-insiders', 'VSCode-linux-x64/resources/app/node_modules*/vscode-ripgrep/**/rg'], { restore: true });
|
|
stream = request(downloadUrl)
|
|
.pipe(source(path.basename(downloadUrl)))
|
|
.pipe(gunzip())
|
|
.pipe(untar())
|
|
.pipe(gulpFilter)
|
|
.pipe(chmod(493)) // 0o755
|
|
.pipe(gulpFilter.restore)
|
|
.pipe(symdest(testRunFolder));
|
|
} else {
|
|
stream = remote('', { base: downloadUrl })
|
|
.pipe(vzip.src())
|
|
.pipe(symdest(testRunFolder));
|
|
}
|
|
|
|
stream.on('end', runTests);
|
|
});
|
|
}
|
|
|
|
function getDownloadUrl(clb) {
|
|
if (process.env.CODE_DOWNLOAD_URL) {
|
|
return clb(process.env.CODE_DOWNLOAD_URL);
|
|
}
|
|
|
|
getTag(function (tag) {
|
|
return clb(['https://vscode-update.azurewebsites.net', tag, downloadPlatform, (isInsiders ? 'insider' : 'stable')].join('/'));
|
|
});
|
|
}
|
|
|
|
function getTag(clb) {
|
|
if (version !== '*' && version !== 'insiders') {
|
|
return clb(version);
|
|
}
|
|
|
|
shared.getContents('https://vscode-update.azurewebsites.net/api/releases/' + (isInsiders ? 'insider/' : 'stable/') + downloadPlatform, null, null, function (error, tagsRaw) {
|
|
if (error) {
|
|
exitWithError(error);
|
|
}
|
|
|
|
try {
|
|
clb(JSON.parse(tagsRaw)[0]); // first one is latest
|
|
} catch (error) {
|
|
exitWithError(error);
|
|
}
|
|
});
|
|
}
|
|
|
|
fs.exists(executable, function (exists) {
|
|
if (exists) {
|
|
runTests();
|
|
} else {
|
|
downloadExecutableAndRunTests();
|
|
}
|
|
});
|
|
|
|
function exitWithError(error) {
|
|
console.error('Error running tests: ' + error.toString());
|
|
process.exit(1);
|
|
}
|