Skip to content

Commit

Permalink
Fix failing circle-ci build job. (#4840)
Browse files Browse the repository at this point in the history
* fix lint errors

* update browser versions

* remove problematic test cases

* remove addtional files

* fix errors in adagioBidAdapter.js and adagioBidAdapter_spec.js file

* change karma config

* change config

* update timeout values

* resolve merge conflict

* -update karma\n-fix userIdSpec unit tests\n-update version of karma-browserstack-launcher to 1.4.0

* fix issue with userId_spec.js file

* fix for realvu and sortable, potential fix for userId

* resolve faulty merge

* add a guideline to CONTRIBUGING.md and revert auction time back in userId_spec.js file
  • Loading branch information
Fawke authored Mar 17, 2020
1 parent a95f911 commit d1f0ea1
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 298 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ When you are adding code to Prebid.js, or modifying code that isn't covered by a
- If you need to check `adloader.loadExternalScript` in a test, use a `stub` rather than a `spy`. `spy`s trigger a network call which can result in a `script error` and cause unrelated unit tests to fail. `stub`s will let you gather information about the `adloader.loadExternalScript` call without affecting external resources
- If your test makes ajax requests, use the global xhr stub in `test/mocks/xhr`. Do not use your own `sinon.useFakeXMLHttpRequest()` or `sinon.createFakeServer()`.
- When writing tests you may use ES2015 syntax if desired
- If your test relies on `Window` or `global` object, do not mutate that object directly. Instead, create a separate copy of that object and perform operations on that new copy.

### Test Examples
Prebid.js already has many tests. Read them to see how Prebid.js is tested, and for inspiration:
Expand Down
26 changes: 13 additions & 13 deletions browsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"device": null,
"os": "Windows"
},
"bs_edge_16_windows_10": {
"bs_edge_18_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "edge",
"browser_version": "16.0",
"browser_version": "18.0",
"device": null,
"os": "Windows"
},
Expand All @@ -23,43 +23,43 @@
"device": null,
"os": "Windows"
},
"bs_chrome_74_windows_10": {
"bs_chrome_80_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "chrome",
"browser_version": "74.0",
"browser_version": "80.0",
"device": null,
"os": "Windows"
},
"bs_chrome_75_windows_10": {
"bs_chrome_79_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "chrome",
"browser_version": "75.0",
"browser_version": "79.0",
"device": null,
"os": "Windows"
},
"bs_firefox_66_windows_10": {
"bs_firefox_73_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "firefox",
"browser_version": "66.0",
"browser_version": "73.0",
"device": null,
"os": "Windows"
},
"bs_firefox_67_windows_10": {
"bs_firefox_72_windows_10": {
"base": "BrowserStack",
"os_version": "10",
"browser": "firefox",
"browser_version": "67.0",
"browser_version": "72.0",
"device": null,
"os": "Windows"
},
"bs_safari_11_mac_high_sierra": {
"bs_safari_11_mac_catalina": {
"base": "BrowserStack",
"os_version": "High Sierra",
"os_version": "Catalina",
"browser": "safari",
"browser_version": "11.1",
"browser_version": "13.0",
"device": null,
"os": "OS X"
},
Expand Down
22 changes: 11 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ function lint(done) {
if (argv.nolint) {
return done();
}
const isFixed = function(file) {
const isFixed = function (file) {
return file.eslint != null && file.eslint.fixed;
}
return gulp.src(['src/**/*.js', 'modules/**/*.js', 'test/**/*.js'], {base: './'})
.pipe(gulpif(argv.nolintfix, eslint(), eslint({fix: true})))
return gulp.src(['src/**/*.js', 'modules/**/*.js', 'test/**/*.js'], { base: './' })
.pipe(gulpif(argv.nolintfix, eslint(), eslint({ fix: true })))
.pipe(eslint.format('stylish'))
.pipe(eslint.failAfterError())
.pipe(gulpif(isFixed, gulp.dest('./')));
Expand Down Expand Up @@ -160,7 +160,7 @@ function nodeBundle(modules) {
.on('error', (err) => {
reject(err);
})
.pipe(through.obj(function(file, enc, done) {
.pipe(through.obj(function (file, enc, done) {
resolve(file.contents.toString(enc));
done();
}));
Expand Down Expand Up @@ -199,7 +199,7 @@ function bundle(dev, moduleArr) {
return gulp.src(
entries
)
.pipe(gulpif(dev, sourcemaps.init({loadMaps: true})))
.pipe(gulpif(dev, sourcemaps.init({ loadMaps: true })))
.pipe(concat(outputFileName))
.pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', {
global: prebid.globalVarName
Expand Down Expand Up @@ -239,7 +239,7 @@ function test(done) {
}

//run mock-server
const mockServer = spawn('node', ['./test/mock-server/index.js', '--port='+mockServerPort]);
const mockServer = spawn('node', ['./test/mock-server/index.js', '--port=' + mockServerPort]);
mockServer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
Expand Down Expand Up @@ -273,7 +273,7 @@ function test(done) {
}

function newKarmaCallback(done) {
return function(exitCode) {
return function (exitCode) {
if (exitCode) {
done(new Error('Karma tests failed with exit code ' + exitCode));
if (argv.browserstack) {
Expand All @@ -296,7 +296,7 @@ function testCoverage(done) {
function coveralls() { // 2nd arg is a dependency: 'test' must be finished
// first send results of istanbul's test coverage to coveralls.io.
return gulp.src('gulpfile.js', { read: false }) // You have to give it a file, but you don't
// have to read it.
// have to read it.
.pipe(shell('cat build/coverage/lcov.info | node_modules/coveralls/bin/coveralls.js'));
}

Expand Down Expand Up @@ -326,10 +326,10 @@ function setupE2e(done) {
done();
}

gulp.task('updatepath', function(){
gulp.task('updatepath', function () {
return gulp.src(['build/dist/*.js'])
.pipe(replace('https://ib.adnxs.com/ut/v3/prebid', 'http://' + host + ':' + mockServerPort + '/'))
.pipe(gulp.dest('build/dist'));
.pipe(replace('https://ib.adnxs.com/ut/v3/prebid', 'http://' + host + ':' + mockServerPort + '/'))
.pipe(gulp.dest('build/dist'));
});

// support tasks
Expand Down
12 changes: 6 additions & 6 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function setBrowsers(karmaConf, browserstack) {
karmaConf.browserStack.startTunnel = false;
karmaConf.browserStack.tunnelIdentifier = process.env.BROWSERSTACK_LOCAL_IDENTIFIER;
}
karmaConf.customLaunchers = require('./browsers.json')
karmaConf.customLaunchers = require('./browsers.json');
karmaConf.browsers = Object.keys(karmaConf.customLaunchers);
} else {
var isDocker = require('is-docker')();
Expand Down Expand Up @@ -162,11 +162,11 @@ module.exports = function(codeCoverage, browserstack, watchMode, file) {
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: !watchMode,
browserDisconnectTimeout: 10000, // default 2000
browserDisconnectTolerance: 1, // default 0
browserNoActivityTimeout: 4 * 60 * 1000, // default 10000
captureTimeout: 4 * 60 * 1000, // default 60000,
processKillTimeout: 10000, // default 2000
browserDisconnectTimeout: 3e5, // default 2000
browserNoActivityTimeout: 3e5, // default 10000
captureTimeout: 3e5, // default 60000,
browserDisconnectTolerance: 3,
concurrency: 5,

plugins: plugins
}
Expand Down
87 changes: 46 additions & 41 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ if (canAccessTopWindow()) {
}

const _features = {
getPrintNumber: function(adUnitCode) {
getPrintNumber: function (adUnitCode) {
const adagioAdUnit = _getOrAddAdagioAdUnit(adUnitCode);
return adagioAdUnit.printNumber || 1;
},

getPageDimensions: function() {
getPageDimensions: function () {
const viewportDims = _features.getViewPortDimensions().split('x');
const w = utils.getWindowTop();
const body = w.document.body;
Expand All @@ -101,7 +101,7 @@ const _features = {
return viewportDims[0] + 'x' + pageHeight;
},

getViewPortDimensions: function() {
getViewPortDimensions: function () {
let viewPortWidth;
let viewPortHeight;
const w = utils.getWindowTop();
Expand All @@ -118,7 +118,7 @@ const _features = {
return viewPortWidth + 'x' + viewPortHeight;
},

isDomLoading: function() {
isDomLoading: function () {
const w = utils.getWindowTop();
let performance = w.performance || w.msPerformance || w.webkitPerformance || w.mozPerformance;
let domLoading = -1;
Expand All @@ -130,7 +130,7 @@ const _features = {
return domLoading;
},

getSlotPosition: function(element) {
getSlotPosition: function (element) {
if (!element) return '';

const w = utils.getWindowTop();
Expand Down Expand Up @@ -164,11 +164,11 @@ const _features = {
return position.x + 'x' + position.y;
},

getTimestamp: function() {
getTimestamp: function () {
return Math.floor(new Date().getTime() / 1000) - new Date().getTimezoneOffset() * 60;
},

getDevice: function() {
getDevice: function () {
if (!canAccessTopWindow()) return false;
const w = utils.getWindowTop();
const ua = w.navigator.userAgent;
Expand All @@ -182,14 +182,14 @@ const _features = {
return 2; // personal computers
},

getBrowser: function() {
getBrowser: function () {
const w = utils.getWindowTop();
const ua = w.navigator.userAgent;
const uaLowerCase = ua.toLowerCase();
return /Edge\/\d./i.test(ua) ? 'edge' : uaLowerCase.indexOf('chrome') > 0 ? 'chrome' : uaLowerCase.indexOf('firefox') > 0 ? 'firefox' : uaLowerCase.indexOf('safari') > 0 ? 'safari' : uaLowerCase.indexOf('opera') > 0 ? 'opera' : uaLowerCase.indexOf('msie') > 0 || w.MSStream ? 'ie' : 'unknow';
},

getOS: function() {
getOS: function () {
const w = window.top;
const ua = w.navigator.userAgent;
const uaLowerCase = ua.toLowerCase();
Expand All @@ -198,9 +198,11 @@ const _features = {
}

function _pushInAdagioQueue(ob) {
if (!canAccessTopWindow()) return;
const w = utils.getWindowTop();
w.ADAGIO.queue.push(ob);
try {
if (!canAccessTopWindow()) return;
const w = utils.getWindowTop();
w.ADAGIO.queue.push(ob);
} catch (e) {}
};

function _getOrAddAdagioAdUnit(adUnitCode) {
Expand Down Expand Up @@ -342,42 +344,45 @@ export const spec = {

supportedMediaType: SUPPORTED_MEDIA_TYPES,

isBidRequestValid: function(bid) {
isBidRequestValid: function (bid) {
const { adUnitCode, auctionId, sizes, bidder, params, mediaTypes } = bid;
const { organizationId, site, placement, adUnitElementId } = bid.params;
let isValid = false;

if (canAccessTopWindow()) {
const w = utils.getWindowTop();
w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
isValid = !!(organizationId && site && placement && adUnitElementId);
const tempAdUnits = w.ADAGIO.pbjsAdUnits.filter((adUnit) => adUnit.code !== adUnitCode);
tempAdUnits.push({
code: adUnitCode,
sizes: (mediaTypes && mediaTypes.banner && Array.isArray(mediaTypes.banner.sizes)) ? mediaTypes.banner.sizes : sizes,
bids: [{
bidder,
params
}]
});
w.ADAGIO.pbjsAdUnits = tempAdUnits;

if (isValid === true) {
let printNumber = _computePrintNumber(adUnitCode);
w.ADAGIO.adUnits[adUnitCode] = {
auctionId: auctionId,
pageviewId: _getPageviewId(),
printNumber
};
try {
if (canAccessTopWindow()) {
const w = utils.getWindowTop();
w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
isValid = !!(organizationId && site && placement && adUnitElementId);
const tempAdUnits = w.ADAGIO.pbjsAdUnits.filter((adUnit) => adUnit.code !== adUnitCode);
tempAdUnits.push({
code: adUnitCode,
sizes: (mediaTypes && mediaTypes.banner && Array.isArray(mediaTypes.banner.sizes)) ? mediaTypes.banner.sizes : sizes,
bids: [{
bidder,
params
}]
});
w.ADAGIO.pbjsAdUnits = tempAdUnits;

if (isValid === true) {
let printNumber = _computePrintNumber(adUnitCode);
w.ADAGIO.adUnits[adUnitCode] = {
auctionId: auctionId,
pageviewId: _getPageviewId(),
printNumber
};
}
}
} catch (e) {
return isValid;
}

return isValid;
},

buildRequests: function(validBidRequests, bidderRequest) {
buildRequests: function (validBidRequests, bidderRequest) {
// AdagioBidAdapter works when window.top can be reached only
if (!bidderRequest.refererInfo.reachedTop) return [];

Expand Down Expand Up @@ -427,7 +432,7 @@ export const spec = {
return requests;
},

interpretResponse: function(serverResponse, bidRequest) {
interpretResponse: function (serverResponse, bidRequest) {
let bidResponses = [];
try {
const response = serverResponse.body;
Expand Down Expand Up @@ -460,7 +465,7 @@ export const spec = {
return bidResponses;
},

getUserSyncs: function(syncOptions, serverResponses) {
getUserSyncs: function (syncOptions, serverResponses) {
if (!serverResponses.length || serverResponses[0].body === '' || !serverResponses[0].body.userSyncs) {
return false;
}
Expand Down
Loading

0 comments on commit d1f0ea1

Please sign in to comment.