index.js 2.0 KB
Newer Older
J
Johannes Rieken 已提交
1 2 3 4 5 6 7 8 9 10 11
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

const { app, BrowserWindow, ipcMain } = require('electron');
const { tmpdir } = require('os');
const { join } = require('path');

const optimist = require('optimist')
	.describe('grep', 'only run tests matching <pattern>').string('grep').alias('grep', 'g').string('g')
J
Johannes Rieken 已提交
12
	.describe('run', 'only run tests from <file>').string('run')
J
Johannes Rieken 已提交
13
	.describe('runGrep', 'only run tests matching <file_pattern>').boolean('runGrep')
14
	.describe('build', 'run with build output (out-build)').boolean('build')
J
Johannes Rieken 已提交
15
	.describe('coverage', 'generate coverage report').boolean('coverage')
16
	.describe('debug', 'open dev tools, keep window open, reuse app data').string('debug');
J
Johannes Rieken 已提交
17

J
Johannes Rieken 已提交
18
const argv = optimist.argv;
J
Johannes Rieken 已提交
19

J
Johannes Rieken 已提交
20
if (!argv.debug) {
21 22
	app.setPath('userData', join(tmpdir(), `vscode-tests-${Date.now()}`));
}
J
Johannes Rieken 已提交
23 24 25 26 27 28

app.on('ready', () => {

	const win = new BrowserWindow({
		height: 600,
		width: 800,
29
		show: false,
30 31 32 33
		webPreferences: {
			backgroundThrottling: false,
			webSecurity: false
		}
J
Johannes Rieken 已提交
34 35 36
	});

	win.webContents.on('did-finish-load', () => {
J
Johannes Rieken 已提交
37
		if (argv.debug) {
38
			win.show();
J
Johannes Rieken 已提交
39 40
			win.webContents.openDevTools('right');
		}
J
Johannes Rieken 已提交
41
		win.webContents.send('run', argv);
J
Johannes Rieken 已提交
42 43
	});

J
Johannes Rieken 已提交
44
	win.loadURL(`file://${__dirname}/renderer.html`);
J
Johannes Rieken 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65


	const _failures = [];
	ipcMain.on('fail', (e, test) => {
		_failures.push(test);
		process.stdout.write('X');
	});
	ipcMain.on('pass', () => {
		process.stdout.write('.');
	});

	ipcMain.on('done', () => {

		console.log(`\nDone with ${_failures.length} failures.\n`);

		for (const fail of _failures) {
			console.error(fail.title);
			console.error(fail.stack);
			console.error('\n');
		}

J
Johannes Rieken 已提交
66
		if (!argv.debug) {
J
Johannes Rieken 已提交
67 68 69 70
			app.exit(_failures.length > 0 ? 1 : 0);
		}
	});
});