Files
jasmine/spec/core/jasmineNamespaceSpec.js
Steve Gravrock 4ddb07ac2d Drop support for Firefox 102, 115, and 128 (old ESRs)
These browsers have bugs that occasionally cause typed array comparisons
to pass when they should fail, or vice versa:

* for...in loops sometimes omit keys, such that two typed arrays with
  different lengths appear to have the same set of keys.
* Typed arrays sometimes have mulitple undefined keys (which is to say that
  the key itself is undefined). Two typed arrays with identical length and
  contents can compare unequal because of the spurious undefined keys.)

Those problems could be avoided by comparing keys 0...length-1 rather than
the actual set of exposed keys, but that would be a pretty nasty breaking
change for anyone whose code tacks extra properties onto typed arrays. So
far these bugs haven't been seen in anything newer than FF 128. Since the
affected browsers are all past end of life, the most sensible thing is to
just stop testing against them.
2026-03-14 09:11:53 -07:00

155 lines
4.2 KiB
JavaScript

describe('The jasmine namespace', function() {
it('includes all expected properties', function() {
const actualKeys = new Set(Object.keys(jasmineUnderTest));
// toEqual doesn't generate diffs for set comparisons. Check this way
// instead so we get readable failure output.
expect(setDifference(expectedKeys(), actualKeys)).toEqual(new Set());
});
it('does not include any unexpected properties', function() {
const actualKeys = new Set(Object.keys(jasmineUnderTest));
// toEqual doesn't generate diffs for set comparisons. Check this way
// instead so we get readable failure output.
expect(setDifference(actualKeys, expectedKeys())).toEqual(new Set());
});
describe('Warning about monkey patching', function() {
beforeEach(function() {
spyOn(console, 'error');
});
for (const key of expectedKeys(false)) {
if (!key.startsWith('MAX_') && key !== 'private' && key !== 'getEnv') {
describe(`jasmine.${key}`, function() {
let orig;
beforeEach(function() {
orig = jasmineUnderTest[key];
});
afterEach(function() {
jasmineUnderTest[key] = orig;
});
it('warns if monkey patched', function() {
const patch = {};
jasmineUnderTest[key] = patch;
verifyDeprecation();
expect(jasmineUnderTest[key]).toBe(patch);
});
});
}
}
// These specs rely on jasmineRequire being exposed. That only happens
// in browsers.
if (typeof document !== 'undefined') {
const statics = ['addMatchers', 'clock', 'createSpyObj'];
for (const name of statics) {
describe(`jasmine.${name}`, function() {
let bootedCore, env, orig;
beforeEach(function() {
bootedCore = jasmineRequire.core(jasmineRequire);
env = bootedCore.getEnv();
jasmineRequire.interface(bootedCore, env);
orig = bootedCore[name];
});
afterEach(function() {
bootedCore[name] = orig;
env.cleanup_();
});
it(`warns if jasmine.${name} is monkey patched`, function() {
const patch = {};
bootedCore[name] = patch;
verifyDeprecation();
expect(bootedCore[name]).toBe(patch);
});
});
}
}
});
function expectedKeys(includeHtml) {
if (includeHtml === undefined) {
includeHtml = typeof window !== 'undefined';
}
// Does not include properties added by requireInterface(), since that isn't
// called by defineJasmineUnderTest.js/nodeDefineJasmineUnderTest.js.
const result = new Set([
'MAX_PRETTY_PRINT_ARRAY_LENGTH',
'MAX_PRETTY_PRINT_CHARS',
'MAX_PRETTY_PRINT_DEPTH',
'debugLog',
'getEnv',
'isSpy',
'ParallelReportDispatcher',
'private',
'spyOnGlobalErrorsAsync',
'Timer',
'version',
// Asymmetric equality testers
'allOf',
'any',
'anything',
'arrayContaining',
'arrayWithExactContents',
'empty',
'falsy',
'is',
'mapContaining',
'notEmpty',
'objectContaining',
'setContaining',
'stringContaining',
'stringMatching',
'truthy',
// Currently undocumented but used in browser boot files, so it's
// effectively public
'getGlobal'
]);
if (includeHtml) {
// jasmine-html.js
result.add('HtmlReporter');
result.add('HtmlReporterV2');
result.add('HtmlReporterV2Urls');
result.add('HtmlSpecFilter');
result.add('QueryString');
}
return result;
}
// Can't use Set#difference yet because it isn't available in Node <22
function setDifference(a, b) {
const result = new Set();
for (const v of a) {
if (!b.has(v)) {
result.add(v);
}
}
return result;
}
function verifyDeprecation() {
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledOnceWith(
jasmine.stringContaining('DEPRECATION: Monkey patching detected.')
);
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledOnceWith(
jasmine.stringContaining('jasmineNamespaceSpec.js')
);
}
});