diff --git a/modules/adagioAnalyticsAdapter.js b/modules/adagioAnalyticsAdapter.js index 99661583743..2615e357ff8 100644 --- a/modules/adagioAnalyticsAdapter.js +++ b/modules/adagioAnalyticsAdapter.js @@ -85,7 +85,7 @@ function removeDuplicates(arr, getKey) { const seen = {}; return arr.filter(item => { const key = getKey(item); - return seen.hasOwnProperty(key) ? false : (seen[key] = true); + return Object.prototype.hasOwnProperty.call(seen, key) ? false : (seen[key] = true); }); }; @@ -231,7 +231,7 @@ function handlerAuctionInit(event) { mediaTypeKey => mediaTypeKey ).map(mediaType => getMediaTypeAlias(mediaType)).sort(); const bannerSizes = removeDuplicates( - mediaTypes.filter(mediaType => mediaType.hasOwnProperty(BANNER) && mediaType[BANNER].hasOwnProperty('sizes')) + mediaTypes.filter(mediaType => Object.prototype.hasOwnProperty.call(mediaType, BANNER) && Object.prototype.hasOwnProperty.call(mediaType[BANNER], 'sizes')) .map(mediaType => mediaType[BANNER].sizes.map(size => size.join('x'))) .flat(), bannerSize => bannerSize diff --git a/package-lock.json b/package-lock.json index e43979de911..09b879b299c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -93,7 +93,7 @@ "plugin-error": "^2.0.1", "puppeteer": "^24.10.0", "resolve-from": "^5.0.0", - "sinon": "^20.0.0", + "sinon": "^22.0.0", "through2": "^4.0.2", "typescript": "^5.8.2", "typescript-eslint": "^8.26.1", @@ -3597,17 +3597,20 @@ } }, "node_modules/@sinonjs/samsam": { - "version": "8.0.2", + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-10.0.2.tgz", + "integrity": "sha512-8lVwD1Df1BmzoaOLhMcGGcz/Jyr5QY2KSB75/YK1QgKzoabTeLdIVyhXNZK9ojfSKSdirbXqdbsXXqP9/Ve8+A==", "dev": true, "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^3.0.1", - "lodash.get": "^4.4.2", "type-detect": "^4.1.0" } }, "node_modules/@sinonjs/samsam/node_modules/type-detect": { "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", "dev": true, "license": "MIT", "engines": { @@ -16512,11 +16515,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.get": { - "version": "4.4.2", - "dev": true, - "license": "MIT" - }, "node_modules/lodash.isequal": { "version": "4.5.0", "dev": true, @@ -19745,46 +19743,40 @@ "license": "ISC" }, "node_modules/sinon": { - "version": "20.0.0", + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-22.0.0.tgz", + "integrity": "sha512-sq/6DpdXOrLyfbKlXLg/Usc7xu8YXPeLkOFZRvA3bNUSA2lhbrZ06yuXbH1fkzBPCbz9O10+7hznzUsjaYNm0Q==", "dev": true, "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^13.0.5", - "@sinonjs/samsam": "^8.0.1", - "diff": "^7.0.0", - "supports-color": "^7.2.0" + "@sinonjs/fake-timers": "^15.4.0", + "@sinonjs/samsam": "^10.0.2", + "diff": "^9.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/sinon" } }, - "node_modules/sinon/node_modules/diff": { - "version": "7.0.0", + "node_modules/sinon/node_modules/@sinonjs/fake-timers": { + "version": "15.4.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-15.4.0.tgz", + "integrity": "sha512-DsG+8/LscQIQg68J6Ef3dv10u6nVyetYn923s3/sus5eaGfTo1of5WMZSLf0UJc9KDuKPilPH0UDJCjvNbDNCA==", "dev": true, "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/sinon/node_modules/has-flag": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" + "dependencies": { + "@sinonjs/commons": "^3.0.1" } }, - "node_modules/sinon/node_modules/supports-color": { - "version": "7.2.0", + "node_modules/sinon/node_modules/diff": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz", + "integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==", "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, + "license": "BSD-3-Clause", "engines": { - "node": ">=8" + "node": ">=0.3.1" } }, "node_modules/sirv": { @@ -25095,16 +25087,19 @@ } }, "@sinonjs/samsam": { - "version": "8.0.2", + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-10.0.2.tgz", + "integrity": "sha512-8lVwD1Df1BmzoaOLhMcGGcz/Jyr5QY2KSB75/YK1QgKzoabTeLdIVyhXNZK9ojfSKSdirbXqdbsXXqP9/Ve8+A==", "dev": true, "requires": { "@sinonjs/commons": "^3.0.1", - "lodash.get": "^4.4.2", "type-detect": "^4.1.0" }, "dependencies": { "type-detect": { "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", "dev": true } } @@ -33574,10 +33569,6 @@ "version": "4.4.0", "dev": true }, - "lodash.get": { - "version": "4.4.2", - "dev": true - }, "lodash.isequal": { "version": "4.5.0", "dev": true @@ -35638,30 +35629,31 @@ "dev": true }, "sinon": { - "version": "20.0.0", + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-22.0.0.tgz", + "integrity": "sha512-sq/6DpdXOrLyfbKlXLg/Usc7xu8YXPeLkOFZRvA3bNUSA2lhbrZ06yuXbH1fkzBPCbz9O10+7hznzUsjaYNm0Q==", "dev": true, "requires": { "@sinonjs/commons": "^3.0.1", - "@sinonjs/fake-timers": "^13.0.5", - "@sinonjs/samsam": "^8.0.1", - "diff": "^7.0.0", - "supports-color": "^7.2.0" + "@sinonjs/fake-timers": "^15.4.0", + "@sinonjs/samsam": "^10.0.2", + "diff": "^9.0.0" }, "dependencies": { - "diff": { - "version": "7.0.0", - "dev": true - }, - "has-flag": { - "version": "4.0.0", - "dev": true - }, - "supports-color": { - "version": "7.2.0", + "@sinonjs/fake-timers": { + "version": "15.4.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-15.4.0.tgz", + "integrity": "sha512-DsG+8/LscQIQg68J6Ef3dv10u6nVyetYn923s3/sus5eaGfTo1of5WMZSLf0UJc9KDuKPilPH0UDJCjvNbDNCA==", "dev": true, "requires": { - "has-flag": "^4.0.0" + "@sinonjs/commons": "^3.0.1" } + }, + "diff": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz", + "integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==", + "dev": true } } }, diff --git a/package.json b/package.json index 06f1b309008..73c9e29bfc2 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "plugin-error": "^2.0.1", "puppeteer": "^24.10.0", "resolve-from": "^5.0.0", - "sinon": "^20.0.0", + "sinon": "^22.0.0", "through2": "^4.0.2", "typescript": "^5.8.2", "typescript-eslint": "^8.26.1", diff --git a/test/spec/libraries/cmp/cmpClient_spec.js b/test/spec/libraries/cmp/cmpClient_spec.js index f647a1fa9b6..ee9ac1916c0 100644 --- a/test/spec/libraries/cmp/cmpClient_spec.js +++ b/test/spec/libraries/cmp/cmpClient_spec.js @@ -192,7 +192,7 @@ describe('cmpClient', () => { }); sinon.assert.calledWithMatch(messenger, sinon.match((arg) => { return arg.mockApiCall.command === 'cmd' && - !arg.mockApiCall.hasOwnProperty('parameter'); + !Object.prototype.hasOwnProperty.call(arg.mockApiCall, 'parameter'); })) }); @@ -202,7 +202,7 @@ describe('cmpClient', () => { command: 'cmd', callback: cb }); - sinon.assert.calledWithMatch(messenger, sinon.match(arg => !arg.mockApiCall.hasOwnProperty('callback'))); + sinon.assert.calledWithMatch(messenger, sinon.match(arg => !Object.prototype.hasOwnProperty.call(arg.mockApiCall, 'callback'))); sinon.assert.called(cb); }); diff --git a/test/spec/modules/adagioRtdProvider_spec.js b/test/spec/modules/adagioRtdProvider_spec.js index 800590e8826..4a66e381d2a 100644 --- a/test/spec/modules/adagioRtdProvider_spec.js +++ b/test/spec/modules/adagioRtdProvider_spec.js @@ -38,14 +38,30 @@ describe('Adagio Rtd Provider', function () { let sandbox; let clock; + const storageMethodRestores = []; + + function setStorageMethod(methodName, impl) { + const original = storage[methodName]; + storage[methodName] = impl; + storageMethodRestores.push(() => { + storage[methodName] = original; + }); + } + beforeEach(function () { sandbox = sinon.createSandbox(); clock = sandbox.useFakeTimers(); + if (Object.getPrototypeOf(storage) == null) { + Object.setPrototypeOf(storage, Object.prototype); + } }); afterEach(function () { clock.restore(); sandbox.restore(); + while (storageMethodRestores.length) { + storageMethodRestores.pop()(); + } }); describe('submodule `init`', function () { @@ -104,13 +120,19 @@ describe('Adagio Rtd Provider', function () { }); it('load an external script if localStorageIsEnabled is enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, true) + setStorageMethod('localStorageIsEnabled', (cb) => { + const enabled = Boolean(1); + cb(enabled); + }) adagioRtdSubmodule.init(config); expect(loadExternalScriptStub.called).to.be.true; }); it('do not load an external script if localStorageIsEnabled is disabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, false) + setStorageMethod('localStorageIsEnabled', (cb) => { + const enabled = Boolean(0); + cb(enabled); + }) adagioRtdSubmodule.init(config); expect(loadExternalScriptStub.called).to.be.false; }); @@ -128,10 +150,9 @@ describe('Adagio Rtd Provider', function () { it('store new session data for further usage', function () { const storageValue = JSON.stringify({ abTest: {} }); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); + setStorageMethod('getDataFromLocalStorage', (key, cb) => cb(storageValue)); + clock.setSystemTime(1714116520710); sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') @@ -141,7 +162,7 @@ describe('Adagio Rtd Provider', function () { session: { v: 2, new: true, - id: utils.generateUUID(), + id: sinon.match.string, rnd: Math.random(), pages: 1, } @@ -156,8 +177,8 @@ describe('Adagio Rtd Provider', function () { it('store existing session data for further usage', function () { const storageValue = JSON.stringify({ session: session, abTest: {} }); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); + setStorageMethod('getDataFromLocalStorage', (key, cb) => cb(storageValue)); + clock.setSystemTime(1714116520710); sandbox.stub(Math, 'random').returns(0.8); const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') @@ -180,10 +201,9 @@ describe('Adagio Rtd Provider', function () { it('store new session if old session has expired data for further usage', function () { const storageValue = JSON.stringify({ session: session, abTest: {} }); - sandbox.stub(Date, 'now').returns(1715679344351); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); + clock.setSystemTime(1715679344351); + setStorageMethod('getDataFromLocalStorage', (key, cb) => cb(storageValue)); sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-5678'); const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') @@ -193,7 +213,7 @@ describe('Adagio Rtd Provider', function () { session: { ...session, new: true, - id: utils.generateUUID(), + id: sinon.match.string, rnd: Math.random(), } } @@ -208,10 +228,9 @@ describe('Adagio Rtd Provider', function () { describe('store session data in localStorage for old snippet', function () { it('store new session data for further usage', function () { const storageValue = null; - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); + setStorageMethod('getDataFromLocalStorage', (key, cb) => cb(storageValue)); + clock.setSystemTime(1714116520710); sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') @@ -220,7 +239,7 @@ describe('Adagio Rtd Provider', function () { const expected = { session: { new: true, - id: utils.generateUUID(), + id: sinon.match.string, rnd: Math.random(), pages: 1 } @@ -245,10 +264,9 @@ describe('Adagio Rtd Provider', function () { testVersion: 'clt' } }); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); + setStorageMethod('getDataFromLocalStorage', (key, cb) => cb(storageValue)); + clock.setSystemTime(1714116520710); sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') @@ -258,7 +276,7 @@ describe('Adagio Rtd Provider', function () { session: { new: false, expiry: 1714116520710, - id: utils.generateUUID(), + id: sinon.match.string, rnd: Math.random(), pages: 1, testName: 't', @@ -292,10 +310,9 @@ describe('Adagio Rtd Provider', function () { testVersion: 'srv' } }); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); + setStorageMethod('getDataFromLocalStorage', (key, cb) => cb(storageValue)); + clock.setSystemTime(1714116520710); sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') @@ -305,7 +322,7 @@ describe('Adagio Rtd Provider', function () { session: { new: false, expiry: 1714116520710, - id: utils.generateUUID(), + id: sinon.match.string, rnd: Math.random(), pages: 1, testName: 't', @@ -684,7 +701,7 @@ describe('Adagio Rtd Provider', function () { it('store a copy of computed property', function() { const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - sandbox.stub(Date, 'now').returns(12345); + clock.setSystemTime(12345); _internal.getGuard().clear(); diff --git a/test/spec/modules/instreamTracking_spec.js b/test/spec/modules/instreamTracking_spec.js index e35c4ca973c..3741ad9fee4 100644 --- a/test/spec/modules/instreamTracking_spec.js +++ b/test/spec/modules/instreamTracking_spec.js @@ -148,6 +148,9 @@ describe('Instream Tracking', function () { beforeEach(function () { sandbox = sinon.createSandbox(); clock = sandbox.useFakeTimers({ shouldClearNativeTimers: true }); + if (typeof window.performance.hasOwnProperty !== 'function') { + window.performance.hasOwnProperty = Object.prototype.hasOwnProperty; + } }); afterEach(function () { diff --git a/test/spec/modules/pubxaiRtdProvider_spec.js b/test/spec/modules/pubxaiRtdProvider_spec.js index 76d8782638d..73aaa308786 100644 --- a/test/spec/modules/pubxaiRtdProvider_spec.js +++ b/test/spec/modules/pubxaiRtdProvider_spec.js @@ -396,13 +396,10 @@ describe('pubxaiRtdProvider', () => { }); it('dispatch event', () => { setFloorsApiStatus(FloorsApiStatus.SUCCESS); - assert( - window.dispatchEvent.calledOnceWith( - new CustomEvent(FLOORS_EVENT_HANDLE, { - detail: { status: FloorsApiStatus.SUCCESS }, - }) - ) - ); + assert(window.dispatchEvent.calledOnce); + const eventArg = window.dispatchEvent.firstCall.args[0]; + expect(eventArg.type).to.equal(FLOORS_EVENT_HANDLE); + expect(eventArg.detail).to.deep.equal({ status: FloorsApiStatus.SUCCESS }); }); }); describe('getUrl', () => { diff --git a/test/spec/modules/r2b2AnalytiscAdapter_spec.js b/test/spec/modules/r2b2AnalytiscAdapter_spec.js index db34531f88d..1cee76fba32 100644 --- a/test/spec/modules/r2b2AnalytiscAdapter_spec.js +++ b/test/spec/modules/r2b2AnalytiscAdapter_spec.js @@ -931,8 +931,7 @@ describe('r2b2 Analytics', function () { }); it('bid viewable content', (done) => { - const dateStub = sandbox.stub(Date, 'now'); - dateStub.returns(100); + clock.setSystemTime(100); fireEvents([ [AUCTION_INIT, MOCK.AUCTION_INIT], @@ -940,7 +939,7 @@ describe('r2b2 Analytics', function () { [AD_RENDER_SUCCEEDED, MOCK.AD_RENDER_SUCCEEDED] ]); - dateStub.returns(150); + clock.setSystemTime(150); fireEvents([[BID_VIEWABLE, MOCK.BID_VIEWABLE]]); @@ -961,7 +960,6 @@ describe('r2b2 Analytics', function () { }, 500); clock.tick(500); - dateStub.restore(); }); it('no auction data error', (done) => {