Skip to content

Commit

Permalink
Revert "Merge master into prebid-7 (#8336)"
Browse files Browse the repository at this point in the history
This reverts commit 90df3ff.
  • Loading branch information
patmmccann authored Apr 28, 2022
1 parent 90df3ff commit d6b9791
Show file tree
Hide file tree
Showing 88 changed files with 2,228 additions and 3,954 deletions.
12 changes: 11 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ aliases:

- &run_endtoend_test
name: BrowserStack End to end testing
command: gulp e2e-test
command: echo "127.0.0.1 test.localhost" | sudo tee -a /etc/hosts && gulp e2e-test --host=test.localhost

# Download and run BrowserStack local
- &setup_browserstack
Expand Down Expand Up @@ -82,6 +82,16 @@ workflows:
commit:
jobs:
- build
nightly:
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
- master
jobs:
- e2etest

experimental:
pipelines: true
123 changes: 71 additions & 52 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var prebid = require('./package.json');
var dateString = 'Updated : ' + (new Date()).toISOString().substring(0, 10);
var banner = '/* <%= prebid.name %> v<%= prebid.version %>\n' + dateString + '*/\n';
var port = 9999;
const INTEG_SERVER_HOST = argv.host ? argv.host : 'localhost';
const INTEG_SERVER_PORT = 4444;
const FAKE_SERVER_HOST = argv.host ? argv.host : 'localhost';
const FAKE_SERVER_PORT = 4444;
const { spawn } = require('child_process');

// these modules must be explicitly listed in --modules to be included in the build, won't be part of "all" modules
Expand Down Expand Up @@ -167,9 +167,9 @@ function gulpBundle(dev) {
return bundle(dev).pipe(gulp.dest('build/' + (dev ? 'dev' : 'dist')));
}

function nodeBundle(modules, dev = false) {
function nodeBundle(modules) {
return new Promise((resolve, reject) => {
bundle(dev, modules)
bundle(false, modules)
.on('error', (err) => {
reject(err);
})
Expand Down Expand Up @@ -243,18 +243,41 @@ function testTaskMaker(options = {}) {
if (options.notest) {
done();
} else if (options.e2e) {
const integ = startIntegServer();
startLocalServer();
runWebdriver(options)
let wdioCmd = path.join(__dirname, 'node_modules/.bin/wdio');
let wdioConf = path.join(__dirname, 'wdio.conf.js');
let wdioOpts;

if (options.file) {
wdioOpts = [
wdioConf,
`--spec`,
`${options.file}`
]
} else {
wdioOpts = [
wdioConf
];
}

// run fake-server
const fakeServer = spawn('node', ['./test/fake-server/index.js', `--port=${FAKE_SERVER_PORT}`]);
fakeServer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
fakeServer.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});

execa(wdioCmd, wdioOpts, { stdio: 'inherit' })
.then(stdout => {
// kill fake server
integ.kill('SIGINT');
fakeServer.kill('SIGINT');
done();
process.exit(0);
})
.catch(err => {
// kill fake server
integ.kill('SIGINT');
fakeServer.kill('SIGINT');
done(new Error(`Tests failed with error: ${err}`));
process.exit(1);
});
Expand All @@ -273,26 +296,6 @@ function testTaskMaker(options = {}) {

const test = testTaskMaker();

function runWebdriver({file}) {
process.env.TEST_SERVER_HOST = argv.host || 'localhost';
let wdioCmd = path.join(__dirname, 'node_modules/.bin/wdio');
let wdioConf = path.join(__dirname, 'wdio.conf.js');
let wdioOpts;

if (file) {
wdioOpts = [
wdioConf,
`--spec`,
`${file}`
]
} else {
wdioOpts = [
wdioConf
];
}
return execa(wdioCmd, wdioOpts, { stdio: 'inherit' });
}

function newKarmaCallback(done) {
return function (exitCode) {
if (exitCode) {
Expand Down Expand Up @@ -332,29 +335,41 @@ function buildPostbid() {
.pipe(gulp.dest('build/postbid/'));
}

function startIntegServer(dev = false) {
const args = ['./test/fake-server/index.js', `--port=${INTEG_SERVER_PORT}`, `--host=${INTEG_SERVER_HOST}`];
if (dev) {
args.push('--dev=true')
function setupE2e(done) {
if (!argv.host) {
throw new gutil.PluginError({
plugin: 'E2E test',
message: gutil.colors.red('Host should be defined e.g. ap.localhost, anlocalhost. localhost cannot be used as safari browserstack is not able to connect to localhost')
});
}
const srv = spawn('node', args);
srv.stdout.on('data', (data) => {
process.env.TEST_SERVER_HOST = argv.host;
if (argv.https) {
process.env.TEST_SERVER_PROTOCOL = argv.https;
}
argv.e2e = true;
done();
}

function injectFakeServerEndpoint() {
return gulp.src(['build/dist/*.js'])
.pipe(replace('https://ib.adnxs.com/ut/v3/prebid', `http://${FAKE_SERVER_HOST}:${FAKE_SERVER_PORT}`))
.pipe(gulp.dest('build/dist'));
}

function injectFakeServerEndpointDev() {
return gulp.src(['build/dev/*.js'])
.pipe(replace('https://ib.adnxs.com/ut/v3/prebid', `http://${FAKE_SERVER_HOST}:${FAKE_SERVER_PORT}`))
.pipe(gulp.dest('build/dev'));
}

function startFakeServer() {
const fakeServer = spawn('node', ['./test/fake-server/index.js', `--port=${FAKE_SERVER_PORT}`]);
fakeServer.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
srv.stderr.on('data', (data) => {
fakeServer.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
return srv;
}

function startLocalServer(options = {}) {
connect.server({
https: argv.https,
port: port,
host: INTEG_SERVER_HOST,
root: './',
livereload: options.livereload
});
}

// Watch Task with Live Reload
Expand All @@ -370,7 +385,13 @@ function watchTaskMaker(options = {}) {
'modules/**/*.js',
].concat(options.alsoWatch));

startLocalServer(options);
connect.server({
https: argv.https,
port: port,
host: FAKE_SERVER_HOST,
root: './',
livereload: options.livereload
});

mainWatcher.on('all', options.task());
done();
Expand Down Expand Up @@ -406,13 +427,11 @@ gulp.task('build-postbid', gulp.series(escapePostbidConfig, buildPostbid));
gulp.task('serve', gulp.series(clean, lint, gulp.parallel('build-bundle-dev', watch, test)));
gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast)));
gulp.task('serve-and-test', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast, testTaskMaker({watch: true}))));
gulp.task('serve-e2e', gulp.series(clean, 'build-bundle-prod', gulp.parallel(() => startIntegServer(), startLocalServer)))
gulp.task('serve-e2e-dev', gulp.series(clean, 'build-bundle-dev', gulp.parallel(() => startIntegServer(true), startLocalServer)))
gulp.task('serve-fake', gulp.series(clean, gulp.parallel('build-bundle-dev', watch), injectFakeServerEndpointDev, test, startFakeServer));

gulp.task('default', gulp.series(clean, 'build-bundle-prod'));

gulp.task('e2e-test-only', () => runWebdriver({file: argv.file}))
gulp.task('e2e-test', gulp.series(clean, 'build-bundle-prod', testTaskMaker({e2e: true})));
gulp.task('e2e-test', gulp.series(clean, setupE2e, gulp.parallel('build-bundle-prod', watch), injectFakeServerEndpoint, test));
// other tasks
gulp.task(bundleToStdout);
gulp.task('bundle', gulpBundle.bind(null, false)); // used for just concatenating pre-built files with no build step
Expand Down
110 changes: 43 additions & 67 deletions modules/adomikAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import adapterManager from '../src/adapterManager.js';
import {logInfo} from '../src/utils.js';
import {find, findIndex} from '../src/polyfill.js';

// Events used in adomik analytics adapter.
// Events used in adomik analytics adapter
const auctionInit = CONSTANTS.EVENTS.AUCTION_INIT;
const auctionEnd = CONSTANTS.EVENTS.AUCTION_END;
const bidRequested = CONSTANTS.EVENTS.BID_REQUESTED;
Expand All @@ -30,13 +30,17 @@ let adomikAdapter = Object.assign(adapter({}),
break;

case bidResponse:
adomikAdapter.saveBidResponse(args);
adomikAdapter.bucketEvents.push({
type: 'response',
event: adomikAdapter.buildBidResponse(args)
});
break;

case bidWon:
args.id = args.adId;
args.placementCode = args.adUnitCode;
adomikAdapter.sendWonEvent(args);
adomikAdapter.sendWonEvent({
id: args.adId,
placementCode: args.adUnitCode
});
break;

case bidRequested:
Expand Down Expand Up @@ -65,28 +69,16 @@ adomikAdapter.initializeBucketEvents = function() {
adomikAdapter.bucketEvents = [];
}

adomikAdapter.saveBidResponse = function(args) {
let responseSaved = adomikAdapter.bucketEvents.find((bucketEvent) =>
bucketEvent.type == 'response' && bucketEvent.event.id == args.id
);
if (responseSaved) { return true; }
adomikAdapter.bucketEvents.push({
type: 'response',
event: adomikAdapter.buildBidResponse(args)
});
}

adomikAdapter.maxPartLength = function () {
return (ua.includes(' MSIE ')) ? 1600 : 60000;
};

adomikAdapter.sendTypedEvent = function() {
let [testId, testValue] = adomikAdapter.getKeyValues();
const groupedTypedEvents = adomikAdapter.buildTypedEvents();

const bulkEvents = {
testId: testId,
testValue: testValue,
testId: adomikAdapter.currentContext.testId,
testValue: adomikAdapter.currentContext.testValue,
uid: adomikAdapter.currentContext.uid,
ahbaid: adomikAdapter.currentContext.id,
hostname: window.location.hostname,
Expand Down Expand Up @@ -122,8 +114,10 @@ adomikAdapter.sendTypedEvent = function() {
const stringBulkEvents = JSON.stringify(bulkEvents)
logInfo('Events sent to adomik prebid analytic ' + stringBulkEvents);

// Encode object in base64
const encodedBuf = window.btoa(stringBulkEvents);

// Create final url and split it (+endpoint length)
const encodedUri = encodeURIComponent(encodedBuf);
const maxLength = adomikAdapter.maxPartLength();
const splittedUrl = encodedUri.match(new RegExp(`.{1,${maxLength}}`, 'g'));
Expand All @@ -136,18 +130,16 @@ adomikAdapter.sendTypedEvent = function() {
};

adomikAdapter.sendWonEvent = function (wonEvent) {
let [testId, testValue] = adomikAdapter.getKeyValues();
let keyValues = { testId: testId, testValue: testValue };
let samplingInfo = { sampling: adomikAdapter.currentContext.sampling };
wonEvent = { ...adomikAdapter.buildBidResponse(wonEvent), ...keyValues, ...samplingInfo };

const stringWonEvent = JSON.stringify(wonEvent);
let keyValues = { testId: adomikAdapter.currentContext.testId, testValue: adomikAdapter.currentContext.testValue }
wonEvent = {...wonEvent, ...keyValues}
const stringWonEvent = JSON.stringify(wonEvent)
logInfo('Won event sent to adomik prebid analytic ' + stringWonEvent);

// Encode object in base64
const encodedBuf = window.btoa(stringWonEvent);
const encodedUri = encodeURIComponent(encodedBuf);
const img = new Image(1, 1);
img.src = `https://${adomikAdapter.currentContext.url}/?q=${encodedUri}&id=${adomikAdapter.currentContext.id}&won=true`;
img.src = `https://${adomikAdapter.currentContext.url}/?q=${encodedUri}&id=${adomikAdapter.currentContext.id}&won=true`
}

adomikAdapter.buildBidResponse = function (bid) {
Expand Down Expand Up @@ -209,49 +201,33 @@ adomikAdapter.buildTypedEvents = function () {
return groupedTypedEvents;
}

adomikAdapter.getKeyValues = function () {
let preventTest = sessionStorage.getItem(window.location.hostname + '_NoAdomikTest')
let inScope = sessionStorage.getItem(window.location.hostname + '_AdomikTestInScope')
let keyValues = JSON.parse(sessionStorage.getItem(window.location.hostname + '_AdomikTest'))
let testId;
let testValue;
if (typeof (keyValues) === 'object' && keyValues != undefined && !preventTest && inScope) {
testId = keyValues.testId
testValue = keyValues.testOptionLabel
}
return [testId, testValue]
}

adomikAdapter.enable = function(options) {
adomikAdapter.currentContext = {
uid: options.id,
url: options.url,
id: '',
timeouted: false,
sampling: options.sampling
}
logInfo('Adomik Analytics enabled with config', options);
adomikAdapter.adapterEnableAnalytics(options);
};

adomikAdapter.checkOptions = function(options) {
if (typeof options !== 'undefined') {
if (options.id && options.url) { adomikAdapter.enable(options); } else { logInfo('Adomik Analytics disabled because id and/or url is missing from config', options); }
} else { logInfo('Adomik Analytics disabled because config is missing'); }
};

adomikAdapter.checkSampling = function(options) {
_sampled = typeof options === 'undefined' ||
typeof options.sampling === 'undefined' ||
(options.sampling > 0 && Math.random() < parseFloat(options.sampling));
if (_sampled) { adomikAdapter.checkOptions(options) } else { logInfo('Adomik Analytics ignored for sampling', options.sampling); }
};

adomikAdapter.adapterEnableAnalytics = adomikAdapter.enableAnalytics;

adomikAdapter.enableAnalytics = function ({ provider, options }) {
logInfo('Adomik Analytics enableAnalytics', provider);
adomikAdapter.checkSampling(options);
adomikAdapter.enableAnalytics = function (config) {
adomikAdapter.currentContext = {};
const initOptions = config.options;

_sampled = typeof config === 'undefined' ||
typeof config.sampling === 'undefined' ||
Math.random() < parseFloat(config.sampling);

if (_sampled) {
if (initOptions) {
adomikAdapter.currentContext = {
uid: initOptions.id,
url: initOptions.url,
testId: initOptions.testId,
testValue: initOptions.testValue,
id: '',
timeouted: false,
sampling: config.sampling
}
logInfo('Adomik Analytics enabled with config', initOptions);
adomikAdapter.adapterEnableAnalytics(config);
}
} else {
logInfo('Adomik Analytics ignored for sampling', config.sampling);
}
};

adapterManager.registerAnalyticsAdapter({
Expand Down
2 changes: 1 addition & 1 deletion modules/adotBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BIDDER_CODE = 'adot';
const ADAPTER_VERSION = 'v2.0.0';
const BID_METHOD = 'POST';
const BIDDER_URL = 'https://dsp.adotmob.com/headerbidding{PUBLISHER_PATH}/bidrequest';
const REQUIRED_VIDEO_PARAMS = ['mimes', 'protocols'];
const REQUIRED_VIDEO_PARAMS = ['mimes', 'minduration', 'maxduration', 'protocols'];
const DOMAIN_REGEX = new RegExp('//([^/]*)');
const FIRST_PRICE = 1;
const IMP_BUILDER = { banner: buildBanner, video: buildVideo, native: buildNative };
Expand Down
Loading

0 comments on commit d6b9791

Please sign in to comment.