Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Upgrade sinon to 3.x (#1491)" #1563

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"proxyquire": "^1.7.10",
"querystringify": "0.0.3",
"requirejs": "^2.1.20",
"sinon": "^3.2.0",
"sinon": "^1.12.1",
"string-replace-webpack-plugin": "^0.1.3",
"through2": "^2.0.3",
"uglify-js": "^2.8.10",
Expand Down
22 changes: 0 additions & 22 deletions test/mocks/sandbox.js

This file was deleted.

1 change: 0 additions & 1 deletion test/mocks/videoCacheStub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sinon from 'sinon';
import * as videoCache from 'src/videoCache';

/**
Expand Down
4 changes: 2 additions & 2 deletions test/spec/AnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ FEATURE: Analytics Adapters API
adapter = new AnalyticsAdapter(config);
spyTestGlobal = sinon.spy(window, config.global);

sinon.stub(events, 'getEvents').returns([]); // these tests shouldn't be affected by previous tests
sinon.stub(events, 'getEvents', () => []); // these tests shouldn't be affected by previous tests
});

afterEach(() => {
Expand Down Expand Up @@ -139,7 +139,7 @@ FEATURE: Analytics Adapters API
const args = { more: 'info' };

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

afterEach(() => {
Expand Down
88 changes: 44 additions & 44 deletions test/spec/bidmanager_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import useSandbox from 'test/mocks/sandbox';
import * as utils from 'src/utils';
import * as bidmanager from 'src/bidmanager';
import * as bidfactory from 'src/bidfactory';
import * as fixtures from 'test/fixtures/fixtures';
import * as assert from 'assert';
var assert = require('assert');

/* use this method to test individual files instead of the whole prebid.js project */

// TODO refactor to use the spec files
var utils = require('../../src/utils');
var bidmanager = require('../../src/bidmanager');
var bidfactory = require('../../src/bidfactory');
var fixtures = require('../fixtures/fixtures');

describe('replaceTokenInString', function () {
it('should replace all given tokens in a String', function () {
Expand Down Expand Up @@ -414,9 +417,6 @@ describe('bidmanager.js', function () {
before(() => {
$$PREBID_GLOBAL$$.adUnits = fixtures.getAdUnits();
});

const getSandbox = useSandbox()

it('should return proper price bucket increments for dense mode', () => {
const bid = Object.assign({},
bidfactory.createBid(2),
Expand Down Expand Up @@ -501,13 +501,11 @@ describe('bidmanager.js', function () {
});

it('should add banner bids that have no width or height but single adunit size', () => {
getSandbox().stub(utils, 'getBidderRequest').callsFake(() => {
return {
bids: [{
sizes: [[300, 250]],
}]
}
});
sinon.stub(utils, 'getBidderRequest', () => ({
bids: [{
sizes: [[300, 250]],
}]
}));

const bid = Object.assign({},
bidfactory.createBid(1),
Expand All @@ -524,18 +522,18 @@ describe('bidmanager.js', function () {
assert.equal(bid.adId, addedBid.adId);
assert.equal(addedBid.width, 300);
assert.equal(addedBid.height, 250);

utils.getBidderRequest.restore();
});

it('should not add native bids that do not have required assets', () => {
getSandbox().stub(utils, 'getBidRequest').callsFake(() => {
return {
bidder: 'appnexusAst',
nativeParams: {
title: {'required': true},
},
mediaType: 'native',
}
});
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
nativeParams: {
title: {'required': true},
},
mediaType: 'native',
}));

const bid = Object.assign({},
bidfactory.createBid(1),
Expand All @@ -549,18 +547,18 @@ describe('bidmanager.js', function () {
const bidsRecCount = $$PREBID_GLOBAL$$._bidsReceived.length;
bidmanager.addBidResponse('adUnit-code', bid);
assert.equal(bidsRecCount, $$PREBID_GLOBAL$$._bidsReceived.length);

utils.getBidRequest.restore();
});

it('should add native bids that do have required assets', () => {
getSandbox().stub(utils, 'getBidRequest').callsFake(() => {
return {
bidder: 'appnexusAst',
nativeParams: {
title: {'required': true},
},
mediaType: 'native',
}
});
sinon.stub(utils, 'getBidRequest', () => ({
bidder: 'appnexusAst',
nativeParams: {
title: {'required': true},
},
mediaType: 'native',
}));

const bid = Object.assign({},
bidfactory.createBid(1),
Expand All @@ -574,19 +572,19 @@ describe('bidmanager.js', function () {
const bidsRecCount = $$PREBID_GLOBAL$$._bidsReceived.length;
bidmanager.addBidResponse('adUnit-code', bid);
assert.equal(bidsRecCount + 1, $$PREBID_GLOBAL$$._bidsReceived.length);

utils.getBidRequest.restore();
});

it('installs publisher-defined renderers on bids', () => {
getSandbox().stub(utils, 'getBidderRequest').callsFake(() => {
return {
bids: [{
renderer: {
url: 'renderer.js',
render: (bid) => bid
}
}]
};
});
sinon.stub(utils, 'getBidderRequest', () => ({
bids: [{
renderer: {
url: 'renderer.js',
render: (bid) => bid
}
}]
}));

const bid = Object.assign({}, bidfactory.createBid(1), {
bidderCode: 'appnexusAst',
Expand All @@ -596,6 +594,8 @@ describe('bidmanager.js', function () {
bidmanager.addBidResponse('adUnit-code', bid);
const addedBid = $$PREBID_GLOBAL$$._bidsReceived.pop();
assert.equal(addedBid.renderer.url, 'renderer.js');

utils.getBidderRequest.restore();
});
});
});
34 changes: 20 additions & 14 deletions test/spec/modules/adkernelBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ describe('Adkernel adapter', () => {
let bidRequest;

beforeEach(() => {
sandbox.stub(utils, 'getTopWindowLocation').returns({
protocol: 'https:',
hostname: 'example.com',
host: 'example.com',
pathname: '/index.html',
href: 'http://example.com/index.html'
sandbox.stub(utils, 'getTopWindowLocation', () => {
return {
protocol: 'https:',
hostname: 'example.com',
host: 'example.com',
pathname: '/index.html',
href: 'http://example.com/index.html'
};
});

ajaxStub.onCall(0).callsArgWith(1, JSON.stringify(bidResponse1));
Expand Down Expand Up @@ -196,12 +198,14 @@ describe('Adkernel adapter', () => {
let bidRequest;

beforeEach(() => {
sandbox.stub(utils, 'getTopWindowLocation').returns({
protocol: 'https:',
hostname: 'example.com',
host: 'example.com',
pathname: '/index.html',
href: 'http://example.com/index.html'
sandbox.stub(utils, 'getTopWindowLocation', () => {
return {
protocol: 'https:',
hostname: 'example.com',
host: 'example.com',
pathname: '/index.html',
href: 'http://example.com/index.html'
};
});
ajaxStub.onCall(0).callsArgWith(1, JSON.stringify(videoBidResponse));
doRequest([bid_video]);
Expand Down Expand Up @@ -320,8 +324,10 @@ describe('Adkernel adapter', () => {
'//sync.adkernel.com/user-sync?zone=2&r=%2F%2Frtb.adkernel.com%2Fuser-synced%3Fuid%3D%7BUID%7D',
'//sync.adkernel.com/user-sync?zone=1&r=%2F%2Frtb.adkernel.com%2Fuser-synced%3Fuid%3D%7BUID%7D'];
let userSyncUrls = [];
sandbox.stub(utils, 'createInvisibleIframe').returns({});
sandbox.stub(utils, 'addEventHandler').callsFake((el, ev, cb) => {
sandbox.stub(utils, 'createInvisibleIframe', () => {
return {};
});
sandbox.stub(utils, 'addEventHandler', (el, ev, cb) => {
userSyncUrls.push(el.src);
cb(); // instant callback
});
Expand Down
Loading