提交 91ab8307 编写于 作者: M Michel Kaporin

Refactored main.js to TS

上级 915a0056
......@@ -23,6 +23,5 @@ step "Build minified & upload source maps" \
step "Run smoke test" \
pushd test/smoke
npm install
npm run compile
node src/main.js --latest "$AGENT_BUILDDIRECTORY/VSCode-darwin/Visual Studio Code - Insiders.app/Contents/MacOS/Electron"
npm test -- --latest "$AGENT_BUILDDIRECTORY/VSCode-darwin/Visual Studio Code - Insiders.app/Contents/MacOS/Electron"
popd
\ No newline at end of file
......@@ -35,8 +35,7 @@ function configureEnvironment {
function runTest {
pushd test/smoke
npm install
npm run compile
sudo -u testuser -H xvfb-run -a -s "-screen 0 1024x768x8" node src/main.js --latest "$AGENT_BUILDDIRECTORY/VSCode-linux-ia32/code-insiders"
sudo -u testuser -H xvfb-run -a -s "-screen 0 1024x768x8" npm test -- --latest "$AGENT_BUILDDIRECTORY/VSCode-linux-ia32/code-insiders"
popd
}
......
Param(
[string]$arch,
[string]$mixinPassword,
[string]$vsoPAT
[string]$arch,
[string]$mixinPassword,
[string]$vsoPAT
)
. .\scripts\env.ps1
......@@ -9,38 +9,38 @@ Param(
# Create a _netrc file to download distro dependencies
# In order to get _netrc to work, we need a HOME variable setup
$env:HOME=$env:USERPROFILE
$env:HOME = $env:USERPROFILE
"machine monacotools.visualstudio.com password ${vsoPAT}" | Out-File "$env:USERPROFILE\_netrc" -Encoding ASCII
# Set the right architecture
$env:npm_config_arch="$arch"
$env:npm_config_arch = "$arch"
step "Install dependencies" {
exec { & npm install }
exec { & npm install }
}
$env:VSCODE_MIXIN_PASSWORD = $mixinPassword
step "Mix in repository from vscode-distro" {
exec { & npm run gulp -- mixin }
exec { & npm run gulp -- mixin }
}
step "Get Electron" {
exec { & npm run gulp -- "electron-$global:arch" }
exec { & npm run gulp -- "electron-$global:arch" }
}
step "Install distro dependencies" {
exec { & node build\tfs\common\installDistro.js }
exec { & node build\tfs\common\installDistro.js }
}
step "Build minified" {
exec { & npm run gulp -- --max_old_space_size=4096 "vscode-win32-$global:arch-min" }
exec { & npm run gulp -- --max_old_space_size=4096 "vscode-win32-$global:arch-min" }
}
step "Run smoke test" {
exec { & Push-Location test\smoke }
exec { & npm install; npm run compile }
exec { & node src/main.js --latest "$env:AGENT_BUILDDIRECTORY\VSCode-win32-$global:arch\Code - Insiders.exe" }
exec { & Pop-Location }
exec { & npm install }
exec { & npm test -- --latest "$env:AGENT_BUILDDIRECTORY\VSCode-win32-$global:arch\Code - Insiders.exe" }
exec { & Pop-Location }
}
done
\ No newline at end of file
......@@ -5,7 +5,7 @@
"scripts": {
"compile": "tsc",
"pretest": "tsc",
"test": "node src/main.js"
"test": "node out/main.js"
},
"devDependencies": {
"@types/mocha": "^2.2.41",
......@@ -23,4 +23,4 @@
"strip-json-comments": "^2.0.1",
"htmlparser2": "^3.9.2"
}
}
}
\ No newline at end of file
......@@ -3,17 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var fs = require('fs');
var https = require('https');
var program = require('commander');
var git = require('simple-git')();
var child_process = require('child_process');
var path = require('path');
var tempFolder = 'test_data';
var testRepoUrl = 'https://github.com/Microsoft/vscode-smoketest-express';
var testRepoLocalDir = path.join(process.cwd(), `${tempFolder}/vscode-smoketest-express`);
var keybindingsUrl = 'https://raw.githubusercontent.com/Microsoft/vscode-docs/master/scripts/keybindings';
const fs = require('fs');
const https = require('https');
const program = require('commander');
const git = require('simple-git')();
const child_process = require('child_process');
const path = require('path');
const tempFolder = 'test_data';
const testRepoUrl = 'https://github.com/Microsoft/vscode-smoketest-express';
const testRepoLocalDir = path.join(process.cwd(), `${tempFolder}/vscode-smoketest-express`);
const keybindingsUrl = 'https://raw.githubusercontent.com/Microsoft/vscode-docs/master/scripts/keybindings';
program
.option('-l, --latest <file path>', 'path to the latest VS Code to test')
......@@ -43,32 +43,42 @@ if (parseInt(process.version.substr(1)) < 6) {
// Setting up environment variables
process.env.VSCODE_LATEST_PATH = program.latest;
if (program.stable) process.env.VSCODE_STABLE_PATH = program.stable;
if (program.stable) {
process.env.VSCODE_STABLE_PATH = program.stable;
}
process.env.SMOKETEST_REPO = testRepoLocalDir;
if (program.stable && program.stable.toLowerCase().startsWith('insiders')) process.env.VSCODE_EDITION = 'insiders';
if (program.stable && program.stable.toLowerCase().startsWith('insiders')) {
process.env.VSCODE_EDITION = 'insiders';
}
// Setting up 'vscode-smoketest-express' project
var os = process.platform;
if (os === 'darwin') os = 'osx';
else if (os === 'win32') os = 'win';
var promises = [];
try {
promises.push(getKeybindings(`${keybindingsUrl}/doc.keybindings.${os}.json`, `${tempFolder}/keybindings.json`));
promises.push(cleanOrClone(testRepoUrl, testRepoLocalDir));
Promise.all(promises).then(() => { execute('npm install', testRepoLocalDir).then(() => runTests()); });
} catch (e) {
throw new Error('Error caught running the smoke test: ' + e);
let os = process.platform.toString();
if (os === 'darwin') {
os = 'osx';
}
else if (os === 'win32') {
os = 'win';
}
function fail(errorMessage) {
var promises: Promise<any>[] = [];
promises.push(getKeybindings(`${keybindingsUrl}/doc.keybindings.${os}.json`, `${tempFolder}/keybindings.json`));
promises.push(cleanOrClone(testRepoUrl, testRepoLocalDir));
Promise.all(promises)
.then(() => execute('npm install', testRepoLocalDir))
.then(() => runTests())
.catch(reason => {
throw new Error('Error caught running the smoke test: ' + reason);
});
function fail(errorMessage): void {
console.error(errorMessage);
process.exit(1);
}
function runTests() {
console.log('Running tests...')
function runTests(): void {
console.log('Running tests...');
const spawn = require('child_process').spawn;
var proc = spawn(process.execPath, [
'out/mocha-runner.js'
......@@ -79,7 +89,9 @@ function runTests() {
proc.stderr.on('data', data => {
var date = new Date().toLocaleString();
fs.appendFile(`${tempFolder}/errors.log`, `${date}: ${data.toString()}`, (err) => {
if (err) throw new Error(`Could not write stderr to errors.log with the following error: ${err}`);
if (err) {
throw new Error(`Could not write stderr to errors.log with the following error: ${err}`);
};
});
});
proc.on('exit', (code) => {
......@@ -87,7 +99,7 @@ function runTests() {
});
}
function cleanOrClone(repo, dir) {
function cleanOrClone(repo: string, dir: string): Promise<any> {
console.log('Cleaning or cloning test project repository...');
return new Promise((res, rej) => {
if (!folderExists(dir)) {
......@@ -97,47 +109,57 @@ function cleanOrClone(repo, dir) {
});
} else {
git.cwd(dir);
git.fetch((err) => {
if (err) rej(err);
git.fetch(err => {
if (err) {
rej(err);
}
resetAndClean();
});
}
var resetAndClean = () => {
git.reset(['FETCH_HEAD', '--hard'], (err) => {
if (err) rej(err);
git.clean('f', ['-d'], (err) => {
if (err) rej(err);
git.reset(['FETCH_HEAD', '--hard'], err => {
if (err) {
rej(err);
}
git.clean('f', ['-d'], err => {
if (err) {
rej(err);
}
console.log('Test project was successfully reset to initial state.');
res();
});
});
}
};
});
}
function execute(cmd, dir) {
function execute(cmd, dir): Promise<any> {
return new Promise((res, rej) => {
console.log(`Running ${cmd}...`);
child_process.exec(cmd, { cwd: dir, stdio: [0, 1, 2] }, (error, stdout, stderr) => {
if (error) rej(error);
if (stderr) console.error(stderr);
if (error) {
rej(error);
}
if (stderr) {
console.error(stderr);
}
console.log(stdout);
res();
});
});
}
function getKeybindings(url, location) {
function getKeybindings(url: string, location: string): Promise<any> {
console.log(`Fetching keybindings from ${url}...`);
return new Promise((resolve, reject) => {
https.get(url, (res) => {
if (res.statusCode != 200) {
if (res.statusCode !== 200) {
reject(`Failed to obtain key bindings with response code: ${res.statusCode}`);
}
var buffer = [];
var buffer: Buffer[] = [];
res.on('data', (chunk) => buffer.push(chunk));
res.on('end', () => {
fs.writeFile(location, Buffer.concat(buffer), 'utf8', () => {
......@@ -151,7 +173,7 @@ function getKeybindings(url, location) {
});
}
function folderExists(folder) {
function folderExists(folder: string): boolean {
try {
fs.accessSync(folder, 'rw');
return true;
......@@ -160,7 +182,7 @@ function folderExists(folder) {
}
}
function binaryExists(filePath) {
function binaryExists(filePath: string): boolean {
try {
fs.accessSync(filePath, 'x');
return true;
......
......@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
const MochaTest = require('mocha');
const path = require('path');
const mochaTest = new MochaTest({
timeout: 360000,
......@@ -12,8 +11,7 @@ const mochaTest = new MochaTest({
slow: 50000,
useColors: true
});
mochaTest.addFile(path.join(process.cwd(), 'out/test.js'));
mochaTest.addFile(require('path').join(process.cwd(), 'out/test.js'));
mochaTest.run((failures) => {
process.exit(failures);
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册