Files
jasmine/src/core/JsApiReporter.js
Steve Gravrock 4371081763 Deprecate jsApiReporter and remove it from boot1.js
jsApiReporter was initially added as part of the pre-1.0 Ruby based browser
runner. It looks like it was designed to resolve a race condition betweeen
jasmine-core's startup in the browser and the Ruby runner's startup. Modern
runners handle that either by buffering messages in a custom reporter (e.g.
jasmine-browser-runner's BatchReporter) or by calling env.execute() after a
communication channel has been set up (e.g. the old Jasmine ruby gem). In
any other context, a custom reporter is easier to use than jsApiReporter
because it doesn't require polling.

Adding jsApiReporter to the env imposes small but measurable penalties in
time and space, both of which are proportional to the size of the test
suite.

Other than jasmine-py and Testdouble's jasmine-rails gem, neither of which
ever supported jasmine-core 4 or later, I can find scant evidence of
interest and no evidence of usage after about 2012.
2025-11-28 08:08:50 -08:00

134 lines
3.4 KiB
JavaScript

getJasmineRequireObj().JsApiReporter = function(j$) {
'use strict';
// TODO: remove in 7.0.
/**
* @name jsApiReporter
* @classdesc {@link Reporter} added by default in `boot.js` to record results for retrieval in javascript code. An instance is made available as `jsApiReporter` on the global object.
* @class
* @hideconstructor
* @deprecated In most cases jsApiReporter can simply be removed. If necessary, it can be replaced with a {@link Reporter|custom reporter}.
*/
function JsApiReporter(options) {
const timer = options.timer || new j$.Timer();
let status = 'loaded';
this.started = false;
this.finished = false;
this.runDetails = {};
this.jasmineStarted = function() {
this.started = true;
status = 'started';
timer.start();
};
let executionTime;
this.jasmineDone = function(runDetails) {
this.finished = true;
this.runDetails = runDetails;
executionTime = timer.elapsed();
status = 'done';
};
/**
* Get the current status for the Jasmine environment.
* @name jsApiReporter#status
* @since 2.0.0
* @function
* @return {String} - One of `loaded`, `started`, or `done`
*/
this.status = function() {
return status;
};
const suites = [],
suites_hash = {};
this.suiteStarted = function(result) {
suites_hash[result.id] = result;
};
this.suiteDone = function(result) {
storeSuite(result);
};
/**
* Get the results for a set of suites.
*
* Retrievable in slices for easier serialization.
* @name jsApiReporter#suiteResults
* @since 2.1.0
* @function
* @param {Number} index - The position in the suites list to start from.
* @param {Number} length - Maximum number of suite results to return.
* @return {SuiteResult[]}
*/
this.suiteResults = function(index, length) {
return suites.slice(index, index + length);
};
function storeSuite(result) {
suites.push(result);
suites_hash[result.id] = result;
}
/**
* Get all of the suites in a single object, with their `id` as the key.
* @name jsApiReporter#suites
* @since 2.0.0
* @function
* @return {Object} - Map of suite id to {@link SuiteResult}
*/
this.suites = function() {
return suites_hash;
};
const specs = [];
this.specDone = function(result) {
specs.push(result);
};
/**
* Get the results for a set of specs.
*
* Retrievable in slices for easier serialization.
* @name jsApiReporter#specResults
* @since 2.0.0
* @function
* @param {Number} index - The position in the specs list to start from.
* @param {Number} length - Maximum number of specs results to return.
* @return {SpecDoneEvent[]}
*/
this.specResults = function(index, length) {
return specs.slice(index, index + length);
};
/**
* Get all spec results.
* @name jsApiReporter#specs
* @since 2.0.0
* @function
* @return {SpecDoneEvent[]}
*/
this.specs = function() {
return specs;
};
/**
* Get the number of milliseconds it took for the full Jasmine suite to run.
* @name jsApiReporter#executionTime
* @since 2.0.0
* @function
* @return {Number}
*/
this.executionTime = function() {
return executionTime;
};
}
return JsApiReporter;
};