Initial version of grunt unit-tests
, tests from command-line
FREEBIE
This commit is contained in:
parent
4402a91976
commit
5635095d1a
2 changed files with 63 additions and 1 deletions
62
Gruntfile.js
62
Gruntfile.js
|
@ -1,3 +1,5 @@
|
|||
var path = require('path');
|
||||
|
||||
module.exports = function(grunt) {
|
||||
'use strict';
|
||||
|
||||
|
@ -343,6 +345,66 @@ module.exports = function(grunt) {
|
|||
});
|
||||
});
|
||||
|
||||
grunt.registerTask('unit-tests', 'Run unit tests inside Electron', function() {
|
||||
var environment = grunt.option('env') || 'test';
|
||||
var done = this.async();
|
||||
var failure;
|
||||
|
||||
var Application = require('spectron').Application;
|
||||
var app = new Application({
|
||||
path: path.join(__dirname, 'node_modules', '.bin', 'electron'),
|
||||
args: [path.join(__dirname, 'main.js')],
|
||||
env: {
|
||||
NODE_ENV: environment,
|
||||
HIDE_DEV_TOOLS: true
|
||||
}
|
||||
});
|
||||
|
||||
function getMochaResults() {
|
||||
return window.mochaResults;
|
||||
}
|
||||
|
||||
app.start().then(function() {
|
||||
return app.client.waitUntil(function() {
|
||||
return app.client.execute(getMochaResults).then(function(data) {
|
||||
return Boolean(data.value);
|
||||
});
|
||||
}, 5000, 'Expected to find window.mochaResults set!');
|
||||
}).then(function() {
|
||||
return app.client.execute(getMochaResults);
|
||||
}).then(function(data) {
|
||||
var results = data.value;
|
||||
if (results.failures > 0) {
|
||||
console.error(results.reports);
|
||||
failure = function() {
|
||||
grunt.fail.fatal('Found ' + results.failures + ' failing unit tests.');
|
||||
}
|
||||
} else {
|
||||
console.log(results.passes + ' tests passed.');
|
||||
}
|
||||
}).catch(function (error) {
|
||||
failure = function() {
|
||||
grunt.fail.fatal('Something went wrong: ' + error.stack);
|
||||
}
|
||||
}).then(function () {
|
||||
// We need to use the failure variable and this early stop to clean up before
|
||||
// shutting down. Grunt's fail methods are the only way to set the return value,
|
||||
// but they shut the process down immediately!
|
||||
return app.stop();
|
||||
}).then(function() {
|
||||
if (failure) {
|
||||
failure();
|
||||
}
|
||||
done();
|
||||
}).catch(function (error) {
|
||||
console.error('Second-level error:', error.stack);
|
||||
if (failure) {
|
||||
failure();
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
grunt.registerMultiTask('test-release', 'Test packaged releases', function() {
|
||||
var dir = grunt.option('dir') || 'dist';
|
||||
var environment = grunt.option('env') || 'production';
|
||||
|
|
2
main.js
2
main.js
|
@ -146,7 +146,7 @@ function createWindow () {
|
|||
mainWindow.loadURL(prepareURL([__dirname, 'background.html']));
|
||||
}
|
||||
|
||||
if (config.get('openDevTools')) {
|
||||
if (config.get('openDevTools') && !process.env.HIDE_DEV_TOOLS) {
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue