Don't expose Order instances to reporters

This commit is contained in:
Steve Gravrock
2025-09-14 09:44:58 -07:00
parent 27297de3b8
commit 6ab83e25d1
4 changed files with 43 additions and 25 deletions

View File

@@ -9564,13 +9564,7 @@ getJasmineRequireObj().Runner = function(j$) {
// In parallel mode, the jasmineStarted event is separately dispatched
// by jasmine-npm. This event only reaches reporters in non-parallel.
totalSpecsDefined,
/**
* Information about the ordering (random or not) of this execution of the suite.
* @typedef Order
* @property {boolean} random - Whether the suite is running in random order
* @property {string} seed - The random seed
*/
order: order,
order: orderForReporting(order),
parallel: false
});
@@ -9622,7 +9616,7 @@ getJasmineRequireObj().Runner = function(j$) {
totalTime: jasmineTimer.elapsed(),
incompleteReason: incompleteReason,
incompleteCode: incompleteCode,
order: order,
order: orderForReporting(order),
failedExpectations: this.#topSuite.result.failedExpectations,
deprecationWarnings: this.#topSuite.result.deprecationWarnings
};
@@ -9632,6 +9626,22 @@ getJasmineRequireObj().Runner = function(j$) {
}
}
/**
* Information about the ordering (random or not) of this execution of the suite.
* @typedef Order
* @property {boolean} random - Whether the suite is running in random order
* @property {string} seed - The random seed
*/
function orderForReporting(order) {
// Don't expose the actual Order object to reporters. That class is private
// and instances are not cloneable.
if (order.random) {
return { random: true, seed: order.seed };
} else {
return { random: false };
}
}
return Runner;
};

View File

@@ -1,6 +1,6 @@
describe('DelayedFunctionScheduler', function() {
'use strict';
it('schedules a function for later execution', function() {
const scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');

View File

@@ -1571,7 +1571,7 @@ describe('Env integration', function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 1,
order: jasmine.any(jasmineUnderTest.Order),
order: { random: true, seed: jasmine.any(String) },
parallel: false
});
@@ -1606,7 +1606,7 @@ describe('Env integration', function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 1,
order: jasmine.any(jasmineUnderTest.Order),
order: { random: true, seed: jasmine.any(String) },
parallel: false
});
@@ -1671,7 +1671,7 @@ describe('Env integration', function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 6,
order: jasmine.any(jasmineUnderTest.Order),
order: { random: false },
parallel: false
});
@@ -1953,12 +1953,10 @@ describe('Env integration', function() {
expect(reporter.jasmineStarted).toHaveBeenCalled();
const startedArg = reporter.jasmineStarted.calls.argsFor(0)[0];
expect(startedArg.order.random).toEqual(true);
expect(startedArg.order.seed).toEqual('123456');
expect(startedArg.order).toEqual({ random: true, seed: '123456' });
const doneArg = reporter.jasmineDone.calls.argsFor(0)[0];
expect(doneArg.order.random).toEqual(true);
expect(doneArg.order.seed).toEqual('123456');
expect(doneArg.order).toEqual({ random: true, seed: '123456' });
});
it('coerces the random seed to a string if it is a number', async function() {
@@ -2078,7 +2076,7 @@ describe('Env integration', function() {
expect(reporter.jasmineStarted).toHaveBeenCalledWith({
totalSpecsDefined: 1,
order: jasmine.any(jasmineUnderTest.Order),
order: { random: true, seed: jasmine.any(String) },
parallel: false
});

View File

@@ -106,13 +106,7 @@ getJasmineRequireObj().Runner = function(j$) {
// In parallel mode, the jasmineStarted event is separately dispatched
// by jasmine-npm. This event only reaches reporters in non-parallel.
totalSpecsDefined,
/**
* Information about the ordering (random or not) of this execution of the suite.
* @typedef Order
* @property {boolean} random - Whether the suite is running in random order
* @property {string} seed - The random seed
*/
order: order,
order: orderForReporting(order),
parallel: false
});
@@ -164,7 +158,7 @@ getJasmineRequireObj().Runner = function(j$) {
totalTime: jasmineTimer.elapsed(),
incompleteReason: incompleteReason,
incompleteCode: incompleteCode,
order: order,
order: orderForReporting(order),
failedExpectations: this.#topSuite.result.failedExpectations,
deprecationWarnings: this.#topSuite.result.deprecationWarnings
};
@@ -174,5 +168,21 @@ getJasmineRequireObj().Runner = function(j$) {
}
}
/**
* Information about the ordering (random or not) of this execution of the suite.
* @typedef Order
* @property {boolean} random - Whether the suite is running in random order
* @property {string} seed - The random seed
*/
function orderForReporting(order) {
// Don't expose the actual Order object to reporters. That class is private
// and instances are not cloneable.
if (order.random) {
return { random: true, seed: order.seed };
} else {
return { random: false };
}
}
return Runner;
};