Skip to content

Commit ff085df

Browse files
committed
Merge branch 'pr-console-error' of github.com:ddterm/jasmine
Merges jasmine#2110 from @amezin
2 parents 316a8fa + 00f1800 commit ff085df

10 files changed

Lines changed: 95 additions & 91 deletions

File tree

‎lib/jasmine-core/jasmine.js‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ getJasmineRequireObj().base = function(j$, private$, jasmineGlobal) {
449449
);
450450
};
451451

452+
private$.consoleError = function(...args) {
453+
// eslint-disable-next-line no-console
454+
console.error(...args);
455+
};
456+
452457
/**
453458
* Get an {@link AsymmetricEqualityTester} that will succeed if the actual
454459
* value being compared matches every provided equality tester.
@@ -1523,10 +1528,10 @@ getJasmineRequireObj().Env = function(j$, private$) {
15231528

15241529
// If we get here, all results have been reported and there's nothing we
15251530
// can do except log the result and hope the user sees it.
1526-
// eslint-disable-next-line no-console
1527-
console.error('Jasmine received a result after the suite finished:');
1528-
// eslint-disable-next-line no-console
1529-
console.error(expectationResult);
1531+
private$.consoleError(
1532+
'Jasmine received a result after the suite finished:'
1533+
);
1534+
private$.consoleError(expectationResult);
15301535
}
15311536

15321537
const asyncExpectationFactory = function(actual, spec, runableType) {
@@ -3794,8 +3799,7 @@ getJasmineRequireObj().Deprecator = function(j$, private$) {
37943799

37953800
Deprecator.prototype.log_ = function(runnable, deprecation, options) {
37963801
if (private$.isError(deprecation)) {
3797-
// eslint-disable-next-line no-console
3798-
console.error(deprecation);
3802+
private$.consoleError(deprecation);
37993803
return;
38003804
}
38013805

@@ -3817,8 +3821,7 @@ getJasmineRequireObj().Deprecator = function(j$, private$) {
38173821
context += '\n' + verboseNote;
38183822
}
38193823

3820-
// eslint-disable-next-line no-console
3821-
console.error('DEPRECATION: ' + deprecation + context);
3824+
private$.consoleError('DEPRECATION: ' + deprecation + context);
38223825
};
38233826

38243827
Deprecator.prototype.stackTrace_ = function() {
@@ -8544,8 +8547,7 @@ getJasmineRequireObj().QueueRunner = function(j$, private$) {
85448547
}
85458548

85468549
function fallbackOnMultipleDone() {
8547-
// eslint-disable-next-line no-console
8548-
console.error(
8550+
private$.consoleError(
85498551
new Error(
85508552
"An asynchronous function called its 'done' " +
85518553
'callback more than once, in a QueueRunner without a onMultipleDone ' +
@@ -8669,8 +8671,7 @@ getJasmineRequireObj().QueueRunner = function(j$, private$) {
86698671
// Any error we catch here is probably due to a bug in Jasmine,
86708672
// and it's not likely to end up anywhere useful if we let it
86718673
// propagate. Log it so it can at least show up when debugging.
8672-
// eslint-disable-next-line no-console
8673-
console.error(error);
8674+
private$.consoleError(error);
86748675
}
86758676
}
86768677
);

‎spec/core/DeprecatorSpec.js‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/* eslint no-console: 0 */
21
describe('Deprecator', function() {
32
describe('#deprecate', function() {
43
beforeEach(function() {
5-
spyOn(console, 'error');
4+
spyOn(privateUnderTest, 'consoleError');
65
});
76

87
it('logs the mesage without context when the runnable is the top suite', function() {
@@ -14,7 +13,9 @@ describe('Deprecator', function() {
1413
omitStackTrace: true
1514
});
1615

17-
expect(console.error).toHaveBeenCalledWith('DEPRECATION: the message');
16+
expect(privateUnderTest.consoleError).toHaveBeenCalledWith(
17+
'DEPRECATION: the message'
18+
);
1819
});
1920

2021
it('logs the message in a descendant suite', function() {
@@ -32,7 +33,7 @@ describe('Deprecator', function() {
3233
omitStackTrace: true
3334
});
3435

35-
expect(console.error).toHaveBeenCalledWith(
36+
expect(privateUnderTest.consoleError).toHaveBeenCalledWith(
3637
'DEPRECATION: the message (in suite: the suite)'
3738
);
3839
});
@@ -51,7 +52,7 @@ describe('Deprecator', function() {
5152
omitStackTrace: true
5253
});
5354

54-
expect(console.error).toHaveBeenCalledWith(
55+
expect(privateUnderTest.consoleError).toHaveBeenCalledWith(
5556
'DEPRECATION: the message (in spec: the spec)'
5657
);
5758
});
@@ -78,10 +79,10 @@ describe('Deprecator', function() {
7879
})
7980
);
8081
expect(runnable.addDeprecationWarning).not.toHaveBeenCalled();
81-
expect(console.error).toHaveBeenCalledWith(
82+
expect(privateUnderTest.consoleError).toHaveBeenCalledWith(
8283
jasmine.stringMatching(/the message/)
8384
);
84-
expect(console.error).not.toHaveBeenCalledWith(
85+
expect(privateUnderTest.consoleError).not.toHaveBeenCalledWith(
8586
jasmine.stringMatching(/a spec/)
8687
);
8788
});
@@ -176,8 +177,8 @@ describe('Deprecator', function() {
176177
expect(
177178
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
178179
).toContain(verboseDeprecationsNote());
179-
expect(console.error).toHaveBeenCalledTimes(1);
180-
expect(console.error.calls.argsFor(0)[0]).toContain(
180+
expect(privateUnderTest.consoleError).toHaveBeenCalledTimes(1);
181+
expect(privateUnderTest.consoleError.calls.argsFor(0)[0]).toContain(
181182
verboseDeprecationsNote()
182183
);
183184
});
@@ -196,8 +197,8 @@ describe('Deprecator', function() {
196197
expect(
197198
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
198199
).not.toContain(verboseDeprecationsNote());
199-
expect(console.error).toHaveBeenCalledTimes(1);
200-
expect(console.error.calls.argsFor(0)[0]).not.toContain(
200+
expect(privateUnderTest.consoleError).toHaveBeenCalledTimes(1);
201+
expect(privateUnderTest.consoleError.calls.argsFor(0)[0]).not.toContain(
201202
verboseDeprecationsNote()
202203
);
203204
});
@@ -230,11 +231,13 @@ describe('Deprecator', function() {
230231
expect(runnable.addDeprecationWarning.calls.argsFor(0)[0].stack).toBe(
231232
originalStack
232233
);
233-
expect(console.error).toHaveBeenCalledTimes(1);
234-
expect(console.error.calls.argsFor(0)[0].message).toEqual(
235-
'the deprecation'
234+
expect(privateUnderTest.consoleError).toHaveBeenCalledTimes(1);
235+
expect(
236+
privateUnderTest.consoleError.calls.argsFor(0)[0].message
237+
).toEqual('the deprecation');
238+
expect(privateUnderTest.consoleError.calls.argsFor(0)[0].stack).toEqual(
239+
originalStack
236240
);
237-
expect(console.error.calls.argsFor(0)[0].stack).toEqual(originalStack);
238241
});
239242

240243
it('reports the deprecation every time, regardless of config.verboseDeprecations', function() {
@@ -255,7 +258,7 @@ describe('Deprecator', function() {
255258
deprecator.addDeprecationWarning(runnable, deprecation);
256259

257260
expect(runnable.addDeprecationWarning).toHaveBeenCalledTimes(2);
258-
expect(console.error).toHaveBeenCalledTimes(2);
261+
expect(privateUnderTest.consoleError).toHaveBeenCalledTimes(2);
259262
});
260263

261264
it('omits the note about verboseDeprecations', function() {
@@ -278,8 +281,8 @@ describe('Deprecator', function() {
278281
expect(
279282
runnable.addDeprecationWarning.calls.argsFor(0)[0].message
280283
).not.toContain(verboseDeprecationsNote());
281-
expect(console.error).toHaveBeenCalledTimes(1);
282-
expect(console.error.calls.argsFor(0)[0]).not.toContain(
284+
expect(privateUnderTest.consoleError).toHaveBeenCalledTimes(1);
285+
expect(privateUnderTest.consoleError.calls.argsFor(0)[0]).not.toContain(
283286
verboseDeprecationsNote()
284287
);
285288
});
@@ -305,9 +308,13 @@ describe('Deprecator', function() {
305308
message: jasmine.stringMatching(/^the message/),
306309
omitStackTrace: false
307310
});
308-
expect(console.error).toHaveBeenCalledTimes(1);
309-
expect(console.error.calls.argsFor(0)[0]).toContain('the message');
310-
expect(console.error.calls.argsFor(0)[0]).toContain('DeprecatorSpec.js');
311+
expect(privateUnderTest.consoleError).toHaveBeenCalledTimes(1);
312+
expect(privateUnderTest.consoleError.calls.argsFor(0)[0]).toContain(
313+
'the message'
314+
);
315+
expect(privateUnderTest.consoleError.calls.argsFor(0)[0]).toContain(
316+
'DeprecatorSpec.js'
317+
);
311318
}
312319

313320
function testNoStackTrace(options) {

‎spec/core/baseSpec.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('base helpers', function() {
152152
if (typeof process !== 'undefined' && process.emitWarning) {
153153
spyOn(process, 'emitWarning'); // Node 22
154154
}
155-
spyOn(console, 'error'); // Node <22
155+
spyOn(privateUnderTest, 'consoleError'); // Node <22
156156

157157
let id = setTimeout(f1, max);
158158
setTimeout(function() {

0 commit comments

Comments
 (0)