2012-11-02 13:03:09 +08:00
|
|
|
/*
|
|
|
|
* grunt-contrib-jasmine
|
|
|
|
* http://gruntjs.com/
|
|
|
|
*
|
2015-01-02 03:30:19 +08:00
|
|
|
* Copyright (c) 2015 GruntJS Team
|
2012-11-02 13:03:09 +08:00
|
|
|
* Licensed under the MIT license.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports = function(grunt) {
|
|
|
|
|
2012-11-02 13:03:09 +08:00
|
|
|
// node api
|
|
|
|
var fs = require('fs'),
|
2014-01-29 09:12:51 +08:00
|
|
|
path = require('path');
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
// npm lib
|
2014-01-29 09:12:51 +08:00
|
|
|
var phantomjs = require('grunt-lib-phantomjs').init(grunt),
|
|
|
|
chalk = require('chalk'),
|
|
|
|
_ = require('lodash');
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
// local lib
|
2013-02-06 06:13:10 +08:00
|
|
|
var jasmine = require('./lib/jasmine').init(grunt, phantomjs);
|
2013-01-09 03:28:26 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
var junitTemplate = path.join(__dirname, '/jasmine/templates/JUnit.tmpl');
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2013-03-30 06:18:51 +08:00
|
|
|
var status = {};
|
2014-03-21 23:15:08 +08:00
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
var symbols = {
|
2015-04-24 06:36:23 +08:00
|
|
|
none: {
|
|
|
|
check: '',
|
|
|
|
error: '',
|
|
|
|
splat: ''
|
2014-03-21 23:15:08 +08:00
|
|
|
},
|
2015-04-24 06:36:23 +08:00
|
|
|
short: {
|
|
|
|
check: '.',
|
|
|
|
error: 'X',
|
|
|
|
splat: '*'
|
2014-02-28 06:02:10 +08:00
|
|
|
},
|
2015-04-24 06:36:23 +08:00
|
|
|
full: {
|
|
|
|
check: '✓',
|
|
|
|
error: 'X',
|
|
|
|
splat: '*'
|
2014-02-28 06:02:10 +08:00
|
|
|
}
|
2014-01-29 09:12:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//With node.js on Windows: use symbols available in terminal default fonts
|
|
|
|
//https://github.com/visionmedia/mocha/pull/641
|
|
|
|
if (process && process.platform === 'win32') {
|
|
|
|
symbols = {
|
2015-04-24 06:36:23 +08:00
|
|
|
none: {
|
|
|
|
check: '',
|
|
|
|
error: '',
|
|
|
|
splat: ''
|
2014-03-21 23:15:08 +08:00
|
|
|
},
|
2015-04-24 06:36:23 +08:00
|
|
|
short: {
|
|
|
|
check: '.',
|
|
|
|
error: '\u00D7',
|
|
|
|
splat: '*'
|
2014-02-28 06:02:10 +08:00
|
|
|
},
|
2015-04-24 06:36:23 +08:00
|
|
|
full: {
|
|
|
|
check: '\u221A',
|
|
|
|
error: '\u00D7',
|
|
|
|
splat: '*'
|
2014-02-28 06:02:10 +08:00
|
|
|
}
|
2014-01-29 09:12:51 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:03:09 +08:00
|
|
|
grunt.registerMultiTask('jasmine', 'Run jasmine specs headlessly through PhantomJS.', function() {
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
// Merge task-specific options with these defaults.
|
2012-11-02 13:03:09 +08:00
|
|
|
var options = this.options({
|
2015-04-24 06:36:23 +08:00
|
|
|
version: '2.0.1',
|
|
|
|
timeout: 10000,
|
|
|
|
styles: [],
|
|
|
|
specs: [],
|
|
|
|
helpers: [],
|
|
|
|
vendor: [],
|
|
|
|
polyfills: [],
|
|
|
|
outfile: '_SpecRunner.html',
|
|
|
|
host: '',
|
|
|
|
template: path.join(__dirname, '/jasmine/templates/DefaultRunner.tmpl'),
|
|
|
|
templateOptions: {},
|
|
|
|
junit: {},
|
2014-02-27 04:12:10 +08:00
|
|
|
ignoreEmpty: grunt.option('force') === true,
|
2014-02-28 06:06:29 +08:00
|
|
|
display: 'full',
|
2015-04-24 06:36:23 +08:00
|
|
|
summary: false
|
2014-01-29 09:12:51 +08:00
|
|
|
});
|
2013-01-10 13:14:50 +08:00
|
|
|
|
2012-11-02 13:03:09 +08:00
|
|
|
if (grunt.option('debug')) {
|
2012-11-02 13:03:09 +08:00
|
|
|
grunt.log.debug(options);
|
2012-11-02 13:03:09 +08:00
|
|
|
}
|
|
|
|
|
2012-11-02 13:03:09 +08:00
|
|
|
setup(options);
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
// The filter returned no spec files so skip phantom.
|
|
|
|
if (!jasmine.buildSpecrunner(this.filesSrc, options)) {
|
2013-06-19 11:26:34 +08:00
|
|
|
return removePhantomListeners();
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
// If we're just building (e.g. for web), skip phantom.
|
2014-10-20 16:14:21 +08:00
|
|
|
if (this.flags.build) {
|
|
|
|
removePhantomListeners();
|
|
|
|
return;
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
var done = this.async();
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomRunner(options, function(err, status) {
|
2013-03-11 23:08:43 +08:00
|
|
|
var success = !err && status.failed === 0;
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
if (err) {
|
|
|
|
grunt.log.error(err);
|
|
|
|
}
|
|
|
|
if (status.failed === 0) {
|
|
|
|
grunt.log.ok('0 failures');
|
|
|
|
} else {
|
|
|
|
grunt.log.error(status.failed + ' failures');
|
|
|
|
}
|
2013-03-11 23:08:43 +08:00
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
teardown(options, function() {
|
2013-06-16 02:50:37 +08:00
|
|
|
done(success);
|
|
|
|
});
|
2012-11-02 13:03:09 +08:00
|
|
|
});
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
function phantomRunner(options, cb) {
|
2012-11-02 13:03:09 +08:00
|
|
|
var file = options.outfile;
|
|
|
|
|
|
|
|
if (options.host) {
|
2015-02-27 16:11:19 +08:00
|
|
|
if (!(/\/$/).test(options.host)) {
|
2015-04-24 06:36:23 +08:00
|
|
|
options.host += '/';
|
2015-02-27 16:11:19 +08:00
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
file = options.host + options.outfile;
|
|
|
|
}
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
grunt.verbose.subhead('Testing jasmine specs via phantom').or.writeln('Testing jasmine specs via PhantomJS');
|
|
|
|
grunt.log.writeln('');
|
2012-11-02 13:03:09 +08:00
|
|
|
|
|
|
|
phantomjs.spawn(file, {
|
2015-04-24 06:36:23 +08:00
|
|
|
failCode: 90,
|
|
|
|
options: options,
|
|
|
|
done: function(err) {
|
|
|
|
cb(err, status);
|
2012-11-02 13:03:09 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-06-16 02:50:37 +08:00
|
|
|
function teardown(options, cb) {
|
2013-06-19 11:26:34 +08:00
|
|
|
removePhantomListeners();
|
2013-06-16 02:50:37 +08:00
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
if (!options.keepRunner && fs.statSync(options.outfile).isFile()) {
|
|
|
|
fs.unlink(options.outfile);
|
|
|
|
}
|
|
|
|
|
2013-06-18 18:17:24 +08:00
|
|
|
if (!options.keepRunner) {
|
|
|
|
jasmine.cleanTemp(cb);
|
|
|
|
} else {
|
|
|
|
cb();
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 11:26:34 +08:00
|
|
|
function removePhantomListeners() {
|
|
|
|
phantomjs.removeAllListeners();
|
|
|
|
phantomjs.listenersAny().length = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:03:09 +08:00
|
|
|
function setup(options) {
|
2014-01-29 09:12:51 +08:00
|
|
|
var indentLevel = 1,
|
|
|
|
tabstop = 2,
|
|
|
|
thisRun = {},
|
|
|
|
suites = {},
|
|
|
|
currentSuite;
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2013-03-30 06:18:51 +08:00
|
|
|
status = {
|
2015-04-24 06:36:23 +08:00
|
|
|
failed: 0
|
2013-03-30 06:18:51 +08:00
|
|
|
};
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
function indent(times) {
|
|
|
|
return new Array(+times * tabstop).join(' ');
|
|
|
|
}
|
|
|
|
|
2014-10-07 10:36:13 +08:00
|
|
|
phantomjs.on('fail.load', function() {
|
|
|
|
grunt.log.writeln();
|
|
|
|
grunt.warn('PhantomJS failed to load your page.', 90);
|
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('fail.timeout', function() {
|
2012-11-02 13:03:09 +08:00
|
|
|
grunt.log.writeln();
|
|
|
|
grunt.warn('PhantomJS timed out, possibly due to an unfinished async spec.', 90);
|
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('console', function(msg) {
|
2014-01-31 04:26:29 +08:00
|
|
|
thisRun.cleanConsole = false;
|
2015-04-24 06:36:23 +08:00
|
|
|
if (options.display === 'full') {
|
2014-02-27 04:12:10 +08:00
|
|
|
grunt.log.writeln('\n' + chalk.yellow('log: ') + msg);
|
|
|
|
}
|
2013-11-21 08:50:53 +08:00
|
|
|
});
|
2014-01-29 09:12:51 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
phantomjs.on('error.onError', function(string, trace) {
|
2013-03-09 10:04:51 +08:00
|
|
|
if (trace && trace.length) {
|
2014-01-29 09:12:51 +08:00
|
|
|
grunt.log.error(chalk.red(string) + ' at ');
|
2012-11-02 13:03:09 +08:00
|
|
|
trace.forEach(function(line) {
|
2015-04-24 06:36:23 +08:00
|
|
|
var file = line.file.replace(/^file:/, '');
|
|
|
|
var message = grunt.util._('%s:%d %s').sprintf(path.relative('.', file), line.line, line.function);
|
2014-01-29 09:12:51 +08:00
|
|
|
grunt.log.error(chalk.red(message));
|
2012-11-02 13:03:09 +08:00
|
|
|
});
|
|
|
|
} else {
|
2015-04-24 06:36:23 +08:00
|
|
|
grunt.log.error('Error caught from PhantomJS. More info can be found by opening the Spec Runner in a browser.');
|
2013-06-16 03:08:34 +08:00
|
|
|
grunt.warn(string);
|
2012-11-02 13:03:09 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
phantomjs.onAny(function() {
|
|
|
|
var args = [this.event].concat(grunt.util.toArray(arguments));
|
|
|
|
grunt.event.emit.apply(grunt.event, args);
|
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('jasmine.jasmineStarted', function() {
|
|
|
|
grunt.verbose.writeln('Jasmine Runner Starting...');
|
|
|
|
thisRun.startTime = (new Date()).getTime();
|
|
|
|
thisRun.executedSpecs = 0;
|
|
|
|
thisRun.passedSpecs = 0;
|
|
|
|
thisRun.failedSpecs = 0;
|
|
|
|
thisRun.skippedSpecs = 0;
|
2015-01-09 01:37:01 +08:00
|
|
|
thisRun.summary = [];
|
2014-01-29 09:12:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
phantomjs.on('jasmine.suiteStarted', function(suiteMetaData) {
|
|
|
|
currentSuite = suiteMetaData.id;
|
|
|
|
suites[currentSuite] = {
|
2015-04-24 06:36:23 +08:00
|
|
|
name: suiteMetaData.fullName,
|
|
|
|
timestamp: new Date(suiteMetaData.startTime),
|
|
|
|
errors: 0,
|
|
|
|
tests: 0,
|
|
|
|
failures: 0,
|
|
|
|
testcases: []
|
2014-01-29 09:12:51 +08:00
|
|
|
};
|
2015-04-24 06:36:23 +08:00
|
|
|
if (options.display === 'full') {
|
2014-02-27 04:12:10 +08:00
|
|
|
grunt.log.write(indent(indentLevel++));
|
|
|
|
grunt.log.writeln(chalk.bold(suiteMetaData.description));
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('jasmine.suiteDone', function(suiteMetaData) {
|
2014-07-02 00:19:48 +08:00
|
|
|
suites[suiteMetaData.id].time = suiteMetaData.duration / 1000;
|
2014-07-20 20:30:06 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
if (indentLevel > 1) {
|
2014-04-28 02:45:56 +08:00
|
|
|
indentLevel--;
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('jasmine.specStarted', function(specMetaData) {
|
|
|
|
thisRun.executedSpecs++;
|
2014-01-31 04:26:29 +08:00
|
|
|
thisRun.cleanConsole = true;
|
2015-04-24 06:36:23 +08:00
|
|
|
if (options.display === 'full') {
|
2014-02-27 04:12:10 +08:00
|
|
|
grunt.log.write(indent(indentLevel) + '- ' + chalk.grey(specMetaData.description) + '...');
|
2015-04-24 06:36:23 +08:00
|
|
|
} else if (options.display === 'short') {
|
2014-02-27 04:12:10 +08:00
|
|
|
grunt.log.write(chalk.grey('.'));
|
|
|
|
}
|
2014-01-29 09:12:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
phantomjs.on('jasmine.specDone', function(specMetaData) {
|
|
|
|
var specSummary = {
|
2015-04-24 06:36:23 +08:00
|
|
|
assertions: 0,
|
|
|
|
classname: suites[currentSuite].name,
|
|
|
|
name: specMetaData.description,
|
|
|
|
time: specMetaData.duration / 1000,
|
|
|
|
failureMessages: []
|
2014-01-29 09:12:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
suites[currentSuite].tests++;
|
|
|
|
|
|
|
|
var color = 'yellow',
|
|
|
|
symbol = 'splat';
|
2015-04-24 06:36:23 +08:00
|
|
|
if (specMetaData.status === 'passed') {
|
2014-01-29 09:12:51 +08:00
|
|
|
thisRun.passedSpecs++;
|
|
|
|
color = 'green';
|
|
|
|
symbol = 'check';
|
2015-04-24 06:36:23 +08:00
|
|
|
} else if (specMetaData.status === 'failed') {
|
2014-01-29 09:12:51 +08:00
|
|
|
thisRun.failedSpecs++;
|
|
|
|
status.failed++;
|
|
|
|
color = 'red';
|
|
|
|
symbol = 'error';
|
|
|
|
suites[currentSuite].failures++;
|
|
|
|
suites[currentSuite].errors += specMetaData.failedExpectations.length;
|
2015-04-24 06:36:23 +08:00
|
|
|
specSummary.failureMessages = specMetaData.failedExpectations.map(function(error) {
|
2014-01-29 09:12:51 +08:00
|
|
|
return error.message;
|
|
|
|
});
|
2015-01-09 01:37:01 +08:00
|
|
|
thisRun.summary.push({
|
2014-02-28 06:06:29 +08:00
|
|
|
suite: suites[currentSuite].name,
|
|
|
|
name: specMetaData.description,
|
2015-04-24 06:36:23 +08:00
|
|
|
errors: specMetaData.failedExpectations.map(function(error) {
|
2014-02-28 06:06:29 +08:00
|
|
|
return {
|
2014-07-20 20:30:06 +08:00
|
|
|
message: error.message,
|
|
|
|
stack: error.stack
|
2014-02-28 06:06:29 +08:00
|
|
|
};
|
|
|
|
})
|
|
|
|
});
|
2013-02-24 09:14:11 +08:00
|
|
|
} else {
|
2014-01-29 09:12:51 +08:00
|
|
|
thisRun.skippedSpecs++;
|
2013-02-24 09:14:11 +08:00
|
|
|
}
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
suites[currentSuite].testcases.push(specSummary);
|
|
|
|
|
2014-01-31 04:26:29 +08:00
|
|
|
// If we're writing to a proper terminal, make it fancy.
|
|
|
|
if (process.stdout.clearLine) {
|
2015-04-24 06:36:23 +08:00
|
|
|
if (options.display === 'full') {
|
2014-02-27 04:12:10 +08:00
|
|
|
process.stdout.clearLine();
|
|
|
|
process.stdout.cursorTo(0);
|
|
|
|
grunt.log.writeln(
|
|
|
|
indent(indentLevel) +
|
2014-03-20 07:20:42 +08:00
|
|
|
chalk[color].bold(symbols.full[symbol]) + ' ' +
|
2014-02-27 04:12:10 +08:00
|
|
|
chalk.grey(specMetaData.description)
|
|
|
|
);
|
2015-04-24 06:36:23 +08:00
|
|
|
} else if (options.display === 'short') {
|
2014-02-27 04:12:10 +08:00
|
|
|
process.stdout.moveCursor(-1);
|
2014-02-28 06:02:10 +08:00
|
|
|
grunt.log.write(chalk[color].bold(symbols.short[symbol]));
|
2014-02-27 04:12:10 +08:00
|
|
|
}
|
2014-01-31 04:26:29 +08:00
|
|
|
} else {
|
|
|
|
// If we haven't written out since we've started
|
|
|
|
if (thisRun.cleanConsole) {
|
|
|
|
// then append to the current line.
|
2014-03-21 23:15:08 +08:00
|
|
|
if (options.display !== 'none') {
|
|
|
|
grunt.log.writeln('...' + symbols[options.display][symbol]);
|
|
|
|
}
|
2014-01-31 04:26:29 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise reprint the current spec and status.
|
2014-03-21 23:15:08 +08:00
|
|
|
if (options.display !== 'none') {
|
|
|
|
grunt.log.writeln(
|
|
|
|
indent(indentLevel) + '...' +
|
|
|
|
chalk.grey(specMetaData.description) + '...' +
|
|
|
|
symbols[options.display][symbol]
|
|
|
|
);
|
|
|
|
}
|
2014-01-31 04:26:29 +08:00
|
|
|
}
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
specMetaData.failedExpectations.forEach(function(error, i) {
|
|
|
|
var specIndex = ' (' + (i + 1) + ')';
|
|
|
|
if (options.display === 'full') {
|
2014-02-27 04:12:10 +08:00
|
|
|
grunt.log.writeln(indent(indentLevel + 1) + chalk.red(error.message + specIndex));
|
|
|
|
}
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.emit('onError', error.message, error.stack);
|
|
|
|
});
|
|
|
|
|
2012-11-02 13:03:09 +08:00
|
|
|
});
|
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
phantomjs.on('jasmine.jasmineDone', function() {
|
2014-01-29 09:12:51 +08:00
|
|
|
var dur = (new Date()).getTime() - thisRun.startTime;
|
2015-04-24 06:36:23 +08:00
|
|
|
var specQuantity = thisRun.executedSpecs + (thisRun.executedSpecs === 1 ? ' spec ' : ' specs ');
|
2014-01-29 09:12:51 +08:00
|
|
|
|
|
|
|
grunt.verbose.writeln('Jasmine runner finished');
|
|
|
|
|
|
|
|
if (thisRun.executedSpecs === 0) {
|
|
|
|
// log.error will print the message but not fail the task, warn will do both.
|
2015-04-24 06:36:23 +08:00
|
|
|
var log = options.ignoreEmpty ? grunt.log.error : grunt.warn;
|
2014-01-29 09:12:51 +08:00
|
|
|
|
|
|
|
log('No specs executed, is there a configuration error?');
|
2013-06-16 00:38:39 +08:00
|
|
|
}
|
2014-03-21 23:15:08 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
if (options.display === 'short') {
|
2014-02-27 04:12:10 +08:00
|
|
|
grunt.log.writeln();
|
|
|
|
}
|
2014-01-29 09:12:51 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
if (options.summary && thisRun.summary.length) {
|
2014-02-28 06:06:29 +08:00
|
|
|
grunt.log.writeln();
|
2015-01-09 01:37:01 +08:00
|
|
|
logSummary(thisRun.summary);
|
2014-02-28 06:06:29 +08:00
|
|
|
}
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
if (options.junit && options.junit.path) {
|
|
|
|
writeJunitXml(suites);
|
2013-02-24 09:14:11 +08:00
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
grunt.log.writeln('\n' + specQuantity + 'in ' + (dur / 1000) + 's.');
|
2012-11-02 13:03:09 +08:00
|
|
|
});
|
2014-03-21 23:15:08 +08:00
|
|
|
|
2014-02-27 04:12:10 +08:00
|
|
|
function logSummary(tests) {
|
|
|
|
grunt.log.writeln('Summary (' + tests.length + ' tests failed)');
|
2015-04-24 06:36:23 +08:00
|
|
|
_.forEach(tests, function(test) {
|
|
|
|
grunt.log.writeln(chalk.red(symbols.options.display.error) + ' ' + test.suite + ' ' + test.name);
|
|
|
|
_.forEach(test.errors, function(error) {
|
2014-07-20 20:30:06 +08:00
|
|
|
grunt.log.writeln(indent(2) + chalk.red(error.message));
|
|
|
|
logStack(error.stack, 2);
|
2014-02-27 04:12:10 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2012-11-02 13:03:09 +08:00
|
|
|
|
2014-07-20 20:30:06 +08:00
|
|
|
function logStack(stack, indentLevel) {
|
|
|
|
var lines = (stack || '').split('\n');
|
|
|
|
for (var i = 0; i < lines.length && i < 11; i++) {
|
2015-04-24 06:36:23 +08:00
|
|
|
grunt.log.writeln(indent(indentLevel) + lines[i]);
|
2014-07-20 20:30:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
function writeJunitXml(testsuites) {
|
2014-05-20 13:43:40 +08:00
|
|
|
var template = grunt.file.read(options.junit.template || junitTemplate);
|
2014-01-29 09:12:51 +08:00
|
|
|
if (options.junit.consolidate) {
|
|
|
|
var xmlFile = path.join(options.junit.path, 'TEST-' + testsuites.suite1.name.replace(/[^\w]/g, '') + '.xml');
|
|
|
|
grunt.file.write(xmlFile, grunt.util._.template(template, { testsuites: _.values(testsuites)}));
|
|
|
|
} else {
|
2015-04-24 06:36:23 +08:00
|
|
|
_.forEach(testsuites, function(suiteData) {
|
2014-01-29 09:12:51 +08:00
|
|
|
var xmlFile = path.join(options.junit.path, 'TEST-' + suiteData.name.replace(/[^\w]/g, '') + '.xml');
|
|
|
|
grunt.file.write(xmlFile, _.template(template, { testsuites: [suiteData] }));
|
|
|
|
});
|
2013-01-08 07:04:44 +08:00
|
|
|
}
|
2014-01-29 09:12:51 +08:00
|
|
|
}
|
2013-01-08 07:04:44 +08:00
|
|
|
|
2015-04-24 06:36:23 +08:00
|
|
|
phantomjs.on('jasmine.done', function() {
|
2012-11-02 13:03:09 +08:00
|
|
|
phantomjs.halt();
|
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('jasmine.done.PhantomReporter', function() {
|
2012-11-02 13:03:09 +08:00
|
|
|
phantomjs.emit('jasmine.done');
|
|
|
|
});
|
|
|
|
|
2014-01-29 09:12:51 +08:00
|
|
|
phantomjs.on('jasmine.done_fail', function(url) {
|
2012-11-02 13:03:09 +08:00
|
|
|
grunt.log.error();
|
|
|
|
grunt.warn('PhantomJS unable to load "' + url + '" URI.', 90);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-03-30 06:18:51 +08:00
|
|
|
};
|