From a42fa5d5c2b3b71a3f589bdf254ac25fe4885d70 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 10 Dec 2015 10:33:18 -0800 Subject: [PATCH 1/4] Parse spec arguments using yargs library --- spec/api-browser-window-spec.coffee | 2 +- spec/api-crash-reporter-spec.coffee | 2 +- spec/package.json | 5 +++-- spec/static/index.html | 3 +-- spec/static/main.js | 3 ++- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/api-browser-window-spec.coffee b/spec/api-browser-window-spec.coffee index 86beb1fdc60..38c8217041e 100644 --- a/spec/api-browser-window-spec.coffee +++ b/spec/api-browser-window-spec.coffee @@ -8,7 +8,7 @@ os = require 'os' {remote, screen} = require 'electron' {ipcMain, BrowserWindow} = remote.require 'electron' -isCI = remote.process.argv[2] == '--ci' +isCI = remote.getGlobal('isCi') describe 'browser-window module', -> fixtures = path.resolve __dirname, 'fixtures' diff --git a/spec/api-crash-reporter-spec.coffee b/spec/api-crash-reporter-spec.coffee index 676dbf9d692..789ba6e01f5 100644 --- a/spec/api-crash-reporter-spec.coffee +++ b/spec/api-crash-reporter-spec.coffee @@ -18,7 +18,7 @@ describe 'crash-reporter module', -> return if process.mas # The crash-reporter test is not reliable on CI machine. - isCI = remote.process.argv[2] == '--ci' + isCI = remote.getGlobal('isCi') return if isCI it 'should send minidump when renderer crashes', (done) -> diff --git a/spec/package.json b/spec/package.json index 38bd8379670..79e7d954eb8 100644 --- a/spec/package.json +++ b/spec/package.json @@ -5,13 +5,14 @@ "version": "0.1.0", "devDependencies": { "basic-auth": "^1.0.0", - "multiparty": "4.1.2", "graceful-fs": "3.0.5", "mocha": "2.1.0", + "multiparty": "4.1.2", "q": "0.9.7", "temp": "0.8.1", "walkdir": "0.0.7", - "ws": "0.7.2" + "ws": "0.7.2", + "yargs": "^3.31.0" }, "optionalDependencies": { "ffi": "2.0.0", diff --git a/spec/static/index.html b/spec/static/index.html index ea86f6ee302..f958e1b7ed0 100644 --- a/spec/static/index.html +++ b/spec/static/index.html @@ -18,8 +18,7 @@ var remote = electron.remote; var ipcRenderer = electron.ipcRenderer; - var argv = remote.process.argv; - var isCi = argv[2] == '--ci'; + var isCi = remote.getGlobal('isCi') if (!isCi) { var win = remote.getCurrentWindow(); diff --git a/spec/static/main.js b/spec/static/main.js index be3690cd9e7..2a637274a25 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -42,7 +42,8 @@ ipcMain.on('echo', function(event, msg) { event.returnValue = msg; }); -if (process.argv[2] == '--ci') { +global.isCi = !!argv.ci; +if (global.isCi) { process.removeAllListeners('uncaughtException'); process.on('uncaughtException', function(error) { console.error(error, error.stack); From 69c0a33c859a0c0424b593c7c203e1a48d53eadc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 10 Dec 2015 10:33:43 -0800 Subject: [PATCH 2/4] Pass mocha grep command line option through to spec app --- spec/static/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/static/main.js b/spec/static/main.js index 2a637274a25..e83e79c1934 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -5,6 +5,12 @@ const dialog = electron.dialog; const BrowserWindow = electron.BrowserWindow; const path = require('path'); +const url = require('url'); + +var argv = require('yargs') + .boolean('ci') + .string('g').alias('g', 'grep') + .argv; var window = null; process.port = 0; // will be used by crash-reporter spec. @@ -68,7 +74,13 @@ app.on('ready', function() { javascript: true // Test whether web-preferences crashes. }, }); - window.loadURL('file://' + __dirname + '/index.html'); + window.loadURL(url.format({ + pathname: __dirname + '/index.html', + protocol: 'file', + query: { + grep: argv.grep + } + })); window.on('unresponsive', function() { var chosen = dialog.showMessageBox(window, { type: 'warning', From 065887e712334bf3ef1679f4602093314da32c2a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 10 Dec 2015 10:35:51 -0800 Subject: [PATCH 3/4] Pass through mocha invert option from test CLI --- spec/static/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/static/main.js b/spec/static/main.js index e83e79c1934..4de123830ee 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -10,6 +10,7 @@ const url = require('url'); var argv = require('yargs') .boolean('ci') .string('g').alias('g', 'grep') + .boolean('i').alias('i', 'invert') .argv; var window = null; @@ -78,7 +79,8 @@ app.on('ready', function() { pathname: __dirname + '/index.html', protocol: 'file', query: { - grep: argv.grep + grep: argv.grep, + invert: argv.invert ? 'true': '' } })); window.on('unresponsive', function() { From 49b6e5bcacb974919dad4b8ab5a2609e3b915338 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 10 Dec 2015 10:44:11 -0800 Subject: [PATCH 4/4] Add npm test script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a5d56e3a990..ea29419925e 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "private": true, "scripts": { - "preinstall": "node -e 'process.exit(0)'" + "preinstall": "node -e 'process.exit(0)'", + "test": "python ./script/test.py" } }