Calculate total suite run time inside the env and report in jasmineDone

This commit is contained in:
Gregg Van Hove
2019-06-14 14:59:33 -07:00
parent 15f969bee7
commit 3e888105f0
9 changed files with 66 additions and 104 deletions

1
.gitignore vendored
View File

@@ -12,6 +12,7 @@ site/
tags
Gemfile.lock
package-lock.json
yarn.lock
pkg/*
.sass-cache/*
src/html/.sass-cache/*

View File

@@ -1495,6 +1495,9 @@ getJasmineRequireObj().Env = function(j$) {
);
}
var jasmineTimer = new j$.Timer();
jasmineTimer.start();
/**
* Information passed to the {@link Reporter#jasmineStarted} event.
* @typedef JasmineStartedInfo
@@ -1530,6 +1533,7 @@ getJasmineRequireObj().Env = function(j$) {
* Information passed to the {@link Reporter#jasmineDone} event.
* @typedef JasmineDoneInfo
* @property {OverallStatus} overallStatus - The overall result of the suite: 'passed', 'failed', or 'incomplete'.
* @property {Int} totalTime - The total time (in ms) that it took to execute the suite
* @property {IncompleteReason} incompleteReason - Explanation of why the suite was incomplete.
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
@@ -1538,6 +1542,7 @@ getJasmineRequireObj().Env = function(j$) {
reporter.jasmineDone(
{
overallStatus: overallStatus,
totalTime: jasmineTimer.elapsed(),
incompleteReason: incompleteReason,
order: order,
failedExpectations: topSuite.result.failedExpectations,

View File

@@ -61,22 +61,6 @@ describe('HtmlReporter', function() {
).toEqual(1);
});
it('starts the timer when jasmine begins', function() {
var env = new jasmine.Env(),
startTimerSpy = jasmine.createSpy('start-timer-spy'),
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
createElement: function() {
return document.createElement.apply(document, arguments);
},
timer: { start: startTimerSpy }
});
reporter.jasmineStarted({});
expect(startTimerSpy).toHaveBeenCalled();
});
describe('when a spec is done', function() {
it('logs errors to the console and prints a special symbol if it is an empty spec', function() {
if (typeof console === 'undefined') {
@@ -343,7 +327,6 @@ describe('HtmlReporter', function() {
it('reports the run time', function() {
var env = new jasmineUnderTest.Env(),
container = document.createElement('div'),
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
getContainer = function() {
return container;
},
@@ -355,16 +338,14 @@ describe('HtmlReporter', function() {
},
createTextNode: function() {
return document.createTextNode.apply(document, arguments);
},
timer: timer
}
});
reporter.initialize();
reporter.jasmineStarted({});
timer.elapsed.and.returnValue(100);
reporter.jasmineDone({});
reporter.jasmineDone({ totalTime: 100 });
var duration = container.querySelector(
'.jasmine-alert .jasmine-duration'

View File

@@ -1,52 +1,10 @@
/* eslint-env node, es6 */
const path = require('path'),
jasmineBrowser = require('jasmine-browser-runner'),
jasmineCore = require('../../lib/jasmine-core'),
useSauce = process.env.USE_SAUCE === 'true';
jasmineCore = require('../../lib/jasmine-core');
var config = require(path.resolve('spec/support/jasmine-browser.json'));
var config = require(path.resolve('spec/support/jasmine-browser.js'));
config.clearReporters = true;
config.jasmineCore = jasmineCore;
function buildWebdriver() {
const webdriver = require('selenium-webdriver'),
Capability = webdriver.Capability;
if (useSauce) {
const username = process.env['SAUCE_USERNAME'],
accessKey = process.env['SAUCE_ACCESS_KEY'];
return new webdriver.Builder()
.withCapabilities({
name: `jasmine-core ${new Date().toISOString()}`,
[Capability.PLATFORM]: process.env['SAUCE_OS'],
[Capability.BROWSER_NAME]: process.env['JASMINE_BROWSER'],
[Capability.VERSION]: process.env['SAUCE_BROWSER_VERSION'],
build: `Core ${process.env['TRAVIS_BUILD_NUMBER'] || 'Ran locally'}`,
tags: ['Jasmine-Core'],
'tunnel-identifier': process.env['TRAVIS_JOB_NUMBER']
? process.env['TRAVIS_JOB_NUMBER'].toString()
: null
})
.usingServer(`http://${username}:${accessKey}@localhost:4445/wd/hub`)
.build();
} else {
return new webdriver.Builder()
.forBrowser(process.env['JASMINE_BROWSER'] || 'firefox')
.build();
}
}
const driver = buildWebdriver();
jasmineBrowser
.runSpecs(config, driver)
.then(function(runDetails) {
process.exitCode = runDetails.overallStatus === 'passed' ? 0 : 1;
if (useSauce) {
driver.executeScript(`sauce:job-result=${process.exitCode === 0}`);
}
})
.catch(error => {
console.error(error);
})
.then(function() {
return driver ? driver.close() : true;
});
jasmineBrowser.runSpecs(config);

View File

@@ -0,0 +1,47 @@
/* eslint-env node, es6 */
module.exports = {
srcDir: 'src',
srcFiles: [
'core/requireCore.js',
'core/base.js',
'core/util.js',
'core/Spec.js',
'core/Env.js',
'core/JsApiReporter.js',
'core/PrettyPrinter.js',
'core/Suite.js',
'core/**/*.js',
'html/**/*.js',
'**/*.js'
],
specDir: 'spec',
specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'],
helpers: [
'helpers/asyncAwait.js',
'helpers/BrowserFlags.js',
'helpers/checkForMap.js',
'helpers/checkForSet.js',
'helpers/checkForSymbol.js',
'helpers/checkForTypedArrays.js',
'helpers/integrationMatchers.js',
'helpers/promises.js',
'helpers/defineJasmineUnderTest.js'
],
random: true,
browser: {
name: process.env.JASMINE_BROWSER || 'firefox',
useSauce: process.env.USE_SAUCE === 'true',
sauce: {
name: `jasmine-core ${new Date().toISOString()}`,
os: process.env.SAUCE_OS,
browserVersion: process.env.SAUCE_BROWSER_VERSION,
build: `Core ${process.env.TRAVIS_BUILD_NUMBER || 'Ran locally'}`,
tags: ['Jasmine-Core'],
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER
? process.env.TRAVIS_JOB_NUMBER.toString()
: null,
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY
}
}
};

View File

@@ -1,33 +0,0 @@
{
"srcDir": "src",
"srcFiles": [
"core/requireCore.js",
"core/base.js",
"core/util.js",
"core/Spec.js",
"core/Env.js",
"core/JsApiReporter.js",
"core/PrettyPrinter.js",
"core/Suite.js",
"core/**/*.js",
"html/**/*.js",
"**/*.js"
],
"specDir": "spec",
"specFiles": [
"**/*[Ss]pec.js",
"!npmPackage/**/*"
],
"helpers": [
"helpers/asyncAwait.js",
"helpers/BrowserFlags.js",
"helpers/checkForMap.js",
"helpers/checkForSet.js",
"helpers/checkForSymbol.js",
"helpers/checkForTypedArrays.js",
"helpers/integrationMatchers.js",
"helpers/promises.js",
"helpers/defineJasmineUnderTest.js"
],
"random": true
}

View File

@@ -2,7 +2,7 @@ var path = require('path'),
jasmineBrowser = require('jasmine-browser-runner'),
jasmineCore = require('../../lib/jasmine-core.js');
var configFile = process.argv[2] || 'jasmine-browser.json';
var configFile = process.argv[2] || 'jasmine-browser.js';
var config = require(path.resolve('spec/support', configFile));
config.jasmineCore = jasmineCore;

View File

@@ -640,6 +640,9 @@ getJasmineRequireObj().Env = function(j$) {
);
}
var jasmineTimer = new j$.Timer();
jasmineTimer.start();
/**
* Information passed to the {@link Reporter#jasmineStarted} event.
* @typedef JasmineStartedInfo
@@ -675,6 +678,7 @@ getJasmineRequireObj().Env = function(j$) {
* Information passed to the {@link Reporter#jasmineDone} event.
* @typedef JasmineDoneInfo
* @property {OverallStatus} overallStatus - The overall result of the suite: 'passed', 'failed', or 'incomplete'.
* @property {Int} totalTime - The total time (in ms) that it took to execute the suite
* @property {IncompleteReason} incompleteReason - Explanation of why the suite was incomplete.
* @property {Order} order - Information about the ordering (random or not) of this execution of the suite.
* @property {Expectation[]} failedExpectations - List of expectations that failed in an {@link afterAll} at the global level.
@@ -683,6 +687,7 @@ getJasmineRequireObj().Env = function(j$) {
reporter.jasmineDone(
{
overallStatus: overallStatus,
totalTime: jasmineTimer.elapsed(),
incompleteReason: incompleteReason,
order: order,
failedExpectations: topSuite.result.failedExpectations,

View File

@@ -52,7 +52,6 @@ jasmineRequire.HtmlReporter = function(j$) {
addToExistingQueryString =
options.addToExistingQueryString || defaultQueryString,
filterSpecs = options.filterSpecs,
timer = options.timer || j$.noopTimer,
htmlReporterMain,
symbols,
deprecationWarnings = [];
@@ -86,7 +85,6 @@ jasmineRequire.HtmlReporter = function(j$) {
var totalSpecsDefined;
this.jasmineStarted = function(options) {
totalSpecsDefined = options.totalSpecsDefined || 0;
timer.start();
};
var summary = createDom('div', { className: 'jasmine-summary' });
@@ -165,7 +163,7 @@ jasmineRequire.HtmlReporter = function(j$) {
createDom(
'span',
{ className: 'jasmine-duration' },
'finished in ' + timer.elapsed() / 1000 + 's'
'finished in ' + doneResult.totalTime / 1000 + 's'
)
);