Skip to content

Commit

Permalink
Replacing all arrow functions in Mocha function calls (prebid#3036)
Browse files Browse the repository at this point in the history
* replace arrow function in describe calls

* replace arrow function in it calls

* replace arrow function in before, beforeEach, after and afterEach calls

* Merge remote-tracking branch 'upstream/master'

# Conflicts:
#	test/spec/modules/improvedigitalBidAdapter_spec.js
  • Loading branch information
thewizarodofoz authored and florevallatmrf committed Sep 6, 2018
1 parent 3e84a33 commit e7e7029
Show file tree
Hide file tree
Showing 173 changed files with 4,110 additions and 4,096 deletions.
4 changes: 2 additions & 2 deletions test/mocks/videoCacheStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as videoCache from 'src/videoCache';
export default function useVideoCacheStub(responses) {
let storeStub;

beforeEach(() => {
beforeEach(function () {
storeStub = sinon.stub(videoCache, 'store');

if (responses.store instanceof Error) {
Expand All @@ -22,7 +22,7 @@ export default function useVideoCacheStub(responses) {
}
});

afterEach(() => {
afterEach(function () {
videoCache.store.restore();
});

Expand Down
36 changes: 18 additions & 18 deletions test/spec/AnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ FEATURE: Analytics Adapters API
let requests;
let adapter;

beforeEach(() => {
beforeEach(function () {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = (request) => requests.push(request);
adapter = new AnalyticsAdapter(config);
});

afterEach(() => {
afterEach(function () {
xhr.restore();
adapter.disableAnalytics();
});

it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, () => {
it(`SHOULD call the endpoint WHEN an event occurs that is to be tracked`, function () {
const eventType = BID_REQUESTED;
const args = { some: 'data' };

Expand All @@ -44,7 +44,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {some: 'data'}, eventType: 'bidRequested'});
});

it(`SHOULD queue the event first and then track it WHEN an event occurs before tracking library is available`, () => {
it(`SHOULD queue the event first and then track it WHEN an event occurs before tracking library is available`, function () {
const eventType = BID_RESPONSE;
const args = { wat: 'wot' };

Expand All @@ -55,16 +55,16 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {wat: 'wot'}, eventType: 'bidResponse'});
});

describe(`WHEN an event occurs after enable analytics\n`, () => {
beforeEach(() => {
describe(`WHEN an event occurs after enable analytics\n`, function () {
beforeEach(function () {
sinon.stub(events, 'getEvents').returns([]); // these tests shouldn't be affected by previous tests
});

afterEach(() => {
afterEach(function () {
events.getEvents.restore();
});

it('SHOULD call global when a bidWon event occurs', () => {
it('SHOULD call global when a bidWon event occurs', function () {
const eventType = BID_WON;
const args = { more: 'info' };

Expand All @@ -75,7 +75,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'});
});

it('SHOULD call global when a adRenderFailed event occurs', () => {
it('SHOULD call global when a adRenderFailed event occurs', function () {
const eventType = AD_RENDER_FAILED;
const args = { call: 'adRenderFailed' };

Expand All @@ -86,7 +86,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {call: 'adRenderFailed'}, eventType: 'adRenderFailed'});
});

it('SHOULD call global when a bidRequest event occurs', () => {
it('SHOULD call global when a bidRequest event occurs', function () {
const eventType = BID_REQUESTED;
const args = { call: 'request' };

Expand All @@ -97,7 +97,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {call: 'request'}, eventType: 'bidRequested'});
});

it('SHOULD call global when a bidResponse event occurs', () => {
it('SHOULD call global when a bidResponse event occurs', function () {
const eventType = BID_RESPONSE;
const args = { call: 'response' };

Expand All @@ -108,7 +108,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {call: 'response'}, eventType: 'bidResponse'});
});

it('SHOULD call global when a bidTimeout event occurs', () => {
it('SHOULD call global when a bidTimeout event occurs', function () {
const eventType = BID_TIMEOUT;
const args = { call: 'timeout' };

Expand All @@ -119,7 +119,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {call: 'timeout'}, eventType: 'bidTimeout'});
});

it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', () => {
it('SHOULD NOT call global again when adapter.enableAnalytics is called with previous timeout', function () {
const eventType = BID_TIMEOUT;
const args = { call: 'timeout' };

Expand All @@ -130,19 +130,19 @@ FEATURE: Analytics Adapters API
expect(requests.length).to.equal(1);
});

describe(`AND sampling is enabled\n`, () => {
describe(`AND sampling is enabled\n`, function () {
const eventType = BID_WON;
const args = { more: 'info' };

beforeEach(() => {
beforeEach(function () {
sinon.stub(Math, 'random').returns(0.5);
});

afterEach(() => {
afterEach(function () {
Math.random.restore();
});

it(`THEN should enable analytics when random number is in sample range`, () => {
it(`THEN should enable analytics when random number is in sample range`, function () {
adapter.enableAnalytics({
options: {
sampling: 0.75
Expand All @@ -155,7 +155,7 @@ FEATURE: Analytics Adapters API
expect(result).to.deep.equal({args: {more: 'info'}, eventType: 'bidWon'});
});

it(`THEN should disable analytics when random number is outside sample range`, () => {
it(`THEN should disable analytics when random number is outside sample range`, function () {
adapter.enableAnalytics({
options: {
sampling: 0.25
Expand Down
10 changes: 5 additions & 5 deletions test/spec/adloader_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ describe('adLoader', function () {
let utilsinsertElementStub;
let utilsLogErrorStub;

beforeEach(() => {
beforeEach(function () {
utilsinsertElementStub = sinon.stub(utils, 'insertElement');
utilsLogErrorStub = sinon.stub(utils, 'logError');
});

afterEach(() => {
afterEach(function () {
utilsinsertElementStub.restore();
utilsLogErrorStub.restore();
});

describe('loadExternalScript', () => {
it('requires moduleCode to be included on the request', () => {
describe('loadExternalScript', function () {
it('requires moduleCode to be included on the request', function () {
adLoader.loadExternalScript('someURL');
expect(utilsLogErrorStub.called).to.be.true;
expect(utilsinsertElementStub.called).to.be.false;
});

it('only allows whitelisted vendors to load scripts', () => {
it('only allows whitelisted vendors to load scripts', function () {
adLoader.loadExternalScript('someURL', 'criteo');
expect(utilsLogErrorStub.called).to.be.false;
expect(utilsinsertElementStub.called).to.be.true;
Expand Down
56 changes: 28 additions & 28 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ function mockAjaxBuilder() {
describe('auctionmanager.js', function () {
let xhr;

before(() => {
before(function () {
xhr = sinon.useFakeXMLHttpRequest();
});

after(() => {
after(function () {
xhr.restore();
});

Expand Down Expand Up @@ -483,8 +483,8 @@ describe('auctionmanager.js', function () {
});
});

describe('adjustBids', () => {
it('should adjust bids if greater than zero and pass copy of bid object', () => {
describe('adjustBids', function () {
it('should adjust bids if greater than zero and pass copy of bid object', function () {
const bid = Object.assign({},
bidfactory.createBid(2),
fixtures.getBidResponses()[5]
Expand Down Expand Up @@ -532,7 +532,7 @@ describe('auctionmanager.js', function () {
});
});

describe('addBidResponse', () => {
describe('addBidResponse', function () {
let createAuctionStub;
let adUnits;
let adUnitCodes;
Expand All @@ -542,23 +542,23 @@ describe('auctionmanager.js', function () {
let bids = TEST_BIDS;
let makeRequestsStub;

before(() => {
before(function () {
makeRequestsStub = sinon.stub(adaptermanager, 'makeBidRequests');

ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockAjaxBuilder);
});

after(() => {
after(function () {
ajaxStub.restore();
adaptermanager.makeBidRequests.restore();
});

describe('when auction timeout is 3000', () => {
describe('when auction timeout is 3000', function () {
let loadScriptStub;
before(() => {
before(function () {
makeRequestsStub.returns(TEST_BID_REQS);
});
beforeEach(() => {
beforeEach(function () {
adUnits = [{
code: ADUNIT_CODE,
bids: [
Expand All @@ -578,7 +578,7 @@ describe('auctionmanager.js', function () {
registerBidder(spec);
});

afterEach(() => {
afterEach(function () {
auctionModule.newAuction.restore();
loadScriptStub.restore();
});
Expand All @@ -605,15 +605,15 @@ describe('auctionmanager.js', function () {
it('should return proper price bucket increments for dense mode when cpm is 20+',
checkPbDg('73.07', '20.00', '20+ caps at 20.00'));

it('should place dealIds in adserver targeting', () => {
it('should place dealIds in adserver targeting', function () {
bids[0].dealId = 'test deal';
auction.callBids();

let registeredBid = auction.getBidsReceived().pop();
assert.equal(registeredBid.adserverTargeting[`hb_deal`], 'test deal', 'dealId placed in adserverTargeting');
});

it('should pass through default adserverTargeting sent from adapter', () => {
it('should pass through default adserverTargeting sent from adapter', function () {
bids[0].adserverTargeting = {};
bids[0].adserverTargeting.extra = 'stuff';
auction.callBids();
Expand All @@ -623,7 +623,7 @@ describe('auctionmanager.js', function () {
assert.equal(registeredBid.adserverTargeting.extra, 'stuff');
});

it('installs publisher-defined renderers on bids', () => {
it('installs publisher-defined renderers on bids', function () {
let renderer = {
url: 'renderer.js',
render: (bid) => bid
Expand Down Expand Up @@ -675,19 +675,19 @@ describe('auctionmanager.js', function () {
});
});

describe('when auction timeout is 20', () => {
describe('when auction timeout is 20', function () {
let loadScriptStub;
let eventsEmitSpy;
let getBidderRequestStub;

before(() => {
before(function () {
bids = [mockBid(), mockBid({ bidderCode: BIDDER_CODE1 })];
let bidRequests = bids.map(bid => mockBidRequest(bid));

makeRequestsStub.returns(bidRequests);
});

beforeEach(() => {
beforeEach(function () {
adUnits = [{
code: ADUNIT_CODE,
bids: [
Expand Down Expand Up @@ -723,20 +723,20 @@ describe('auctionmanager.js', function () {
return req;
});
});
afterEach(() => {
afterEach(function () {
auctionModule.newAuction.restore();
loadScriptStub.restore();
events.emit.restore();
getBidderRequestStub.restore();
});
it('should emit BID_TIMEOUT for timed out bids', () => {
it('should emit BID_TIMEOUT for timed out bids', function () {
auction.callBids();
assert.ok(eventsEmitSpy.calledWith(CONSTANTS.EVENTS.BID_TIMEOUT), 'emitted events BID_TIMEOUT');
});
});
});

describe('addBidResponse', () => {
describe('addBidResponse', function () {
let createAuctionStub;
let adUnits;
let adUnitCodes;
Expand All @@ -748,7 +748,7 @@ describe('auctionmanager.js', function () {
let bids = TEST_BIDS;
let bids1 = [mockBid({ bidderCode: BIDDER_CODE1 })];

before(() => {
before(function () {
let bidRequests = [
mockBidRequest(bids[0]),
mockBidRequest(bids1[0], { adUnitCode: ADUNIT_CODE1 })
Expand All @@ -759,12 +759,12 @@ describe('auctionmanager.js', function () {
ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockAjaxBuilder);
});

after(() => {
after(function () {
ajaxStub.restore();
adaptermanager.makeBidRequests.restore();
});

beforeEach(() => {
beforeEach(function () {
adUnits = [{
code: ADUNIT_CODE,
bids: [
Expand All @@ -788,11 +788,11 @@ describe('auctionmanager.js', function () {
registerBidder(spec1);
});

afterEach(() => {
afterEach(function () {
auctionModule.newAuction.restore();
});

it('should not alter bid adID', () => {
it('should not alter bid adID', function () {
auction.callBids();

const addedBid2 = auction.getBidsReceived().pop();
Expand All @@ -801,7 +801,7 @@ describe('auctionmanager.js', function () {
assert.equal(addedBid1.adId, bids[0].requestId);
});

it('should not add banner bids that have no width or height', () => {
it('should not add banner bids that have no width or height', function () {
bids1[0].width = undefined;
bids1[0].height = undefined;

Expand All @@ -813,7 +813,7 @@ describe('auctionmanager.js', function () {
assert.equal(length, 1);
});

it('should run auction after video bids have been cached', () => {
it('should run auction after video bids have been cached', function () {
sinon.stub(store, 'store').callsArgWith(1, null, [{ uuid: 123 }]);
sinon.stub(config, 'getConfig').withArgs('cache.url').returns('cache-url');

Expand All @@ -832,7 +832,7 @@ describe('auctionmanager.js', function () {
store.store.restore();
});

it('runs auction after video responses with multiple bid objects have been cached', () => {
it('runs auction after video responses with multiple bid objects have been cached', function () {
sinon.stub(store, 'store').callsArgWith(1, null, [{ uuid: 123 }]);
sinon.stub(config, 'getConfig').withArgs('cache.url').returns('cache-url');

Expand Down
Loading

0 comments on commit e7e7029

Please sign in to comment.