From 3e888105f0d7819dfff855dde3c1c64e663c5d6e Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Fri, 14 Jun 2019 14:59:33 -0700 Subject: [PATCH] Calculate total suite run time inside the env and report in `jasmineDone` --- .gitignore | 1 + lib/jasmine-core/jasmine.js | 5 +++ spec/html/HtmlReporterSpec.js | 23 ++----------- spec/support/ci.js | 50 +++-------------------------- spec/support/jasmine-browser.js | 47 +++++++++++++++++++++++++++ spec/support/jasmine-browser.json | 33 ------------------- spec/support/localJasmineBrowser.js | 2 +- src/core/Env.js | 5 +++ src/html/HtmlReporter.js | 4 +-- 9 files changed, 66 insertions(+), 104 deletions(-) create mode 100644 spec/support/jasmine-browser.js delete mode 100644 spec/support/jasmine-browser.json diff --git a/.gitignore b/.gitignore index d8958bd2..4536a071 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ site/ tags Gemfile.lock package-lock.json +yarn.lock pkg/* .sass-cache/* src/html/.sass-cache/* diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index abbd7262..03666af2 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -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, diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 2bff3c1f..da18deb3 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -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' diff --git a/spec/support/ci.js b/spec/support/ci.js index 573a9c6d..79a980df 100644 --- a/spec/support/ci.js +++ b/spec/support/ci.js @@ -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); diff --git a/spec/support/jasmine-browser.js b/spec/support/jasmine-browser.js new file mode 100644 index 00000000..9986ba08 --- /dev/null +++ b/spec/support/jasmine-browser.js @@ -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 + } + } +}; diff --git a/spec/support/jasmine-browser.json b/spec/support/jasmine-browser.json deleted file mode 100644 index de122f43..00000000 --- a/spec/support/jasmine-browser.json +++ /dev/null @@ -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 -} diff --git a/spec/support/localJasmineBrowser.js b/spec/support/localJasmineBrowser.js index ec9affe2..d08261ee 100644 --- a/spec/support/localJasmineBrowser.js +++ b/spec/support/localJasmineBrowser.js @@ -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; diff --git a/src/core/Env.js b/src/core/Env.js index a031f3ff..d3e9e257 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -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, diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 5d838ab3..6bc8d1eb 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -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' ) );