Skip to content

Commit 761582c

Browse files
committed
specs: skip or conditionally spy on console.error when it's not spyable
GJS defines console.error as a non-writable, non-configurable property. SpyRegistry checks the property descriptor and throws: Error: <spyOn> : error is not declared writable or has no setter Add guards to skip or conditionally execute tests that spy on console.error when the property is not spyable. This affects: - DeprecatorSpec: skip all #deprecate tests via beforeEach - DeprecationSpec: skip all integration tests via beforeEach - EnvSpec: skip the deprecation stack test - baseSpec: conditionally spy on console.error in the setTimeout test
1 parent f525545 commit 761582c

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

spec/core/DeprecatorSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
describe('Deprecator', function() {
33
describe('#deprecate', function() {
44
beforeEach(function() {
5+
const descriptor = Object.getOwnPropertyDescriptor(console, 'error');
6+
if (descriptor && !(descriptor.writable || descriptor.set)) {
7+
pending('console.error is not spyable in this environment');
8+
return;
9+
}
10+
511
spyOn(console, 'error');
612
});
713

spec/core/baseSpec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,18 @@ describe('base helpers', function() {
156156
if (typeof process !== 'undefined' && process.emitWarning) {
157157
spyOn(process, 'emitWarning'); // Node 22
158158
}
159-
spyOn(console, 'error'); // Node <22
159+
160+
const consoleErrorDescriptor = Object.getOwnPropertyDescriptor(
161+
console,
162+
'error'
163+
);
164+
if (
165+
!consoleErrorDescriptor ||
166+
consoleErrorDescriptor.writable ||
167+
consoleErrorDescriptor.set
168+
) {
169+
spyOn(console, 'error'); // Node <22
170+
}
160171

161172
let id = setTimeout(f1, max);
162173
setTimeout(function() {

spec/core/integration/DeprecationSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
describe('Deprecation (integration)', function() {
33
let env;
44

5+
function consoleErrorIsSpyable() {
6+
const descriptor = Object.getOwnPropertyDescriptor(console, 'error');
7+
return !descriptor || descriptor.writable || descriptor.set;
8+
}
9+
510
beforeEach(function() {
11+
if (!consoleErrorIsSpyable()) {
12+
pending('console.error is not spyable in this environment');
13+
return;
14+
}
15+
616
env = new privateUnderTest.Env();
717
});
818

spec/core/integration/EnvSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2945,6 +2945,12 @@ describe('Env integration', function() {
29452945
});
29462946

29472947
it('should report deprecation stack with an error object', async function() {
2948+
const descriptor = Object.getOwnPropertyDescriptor(console, 'error');
2949+
if (descriptor && !(descriptor.writable || descriptor.set)) {
2950+
pending('console.error is not spyable in this environment');
2951+
return;
2952+
}
2953+
29482954
const exceptionFormatter = new privateUnderTest.ExceptionFormatter();
29492955
const reporter = jasmine.createSpyObj('reporter', [
29502956
'jasmineDone',

0 commit comments

Comments
 (0)