diff --git a/gulpfile.js b/gulpfile.js index e1dd1517f91..141cac6d585 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,13 +6,19 @@ var jscs = require('gulp-jscs'); var header = require('gulp-header'); var del = require('del'); var ecstatic = require('ecstatic'); -var browserify = require('gulp-browserify'); +var gulpBrowserify = require('gulp-browserify'); var gutil = require("gulp-util"); var gulpJsdoc2md = require("gulp-jsdoc-to-markdown"); var concat = require("gulp-concat"); var zip = require('gulp-zip'); var mocha = require('gulp-mocha'); var preprocessify = require('preprocessify'); +/** for automated unit testing */ +var browserSync = require("browser-sync"), + browserify = require("browserify"), + source = require("vinyl-source-stream"), + mochaPhantomJS = require("gulp-mocha-phantomjs"); + var releaseDir = './dist/'; var csaSrcLocation = './src/prebid.js'; @@ -93,18 +99,12 @@ gulp.task('clean-dist', function(cb) { }); -//longer tests go here, to be run only when specfcifcally testing -gulp.task('runAdvancedTests', function() { - -}); - gulp.task('codeQuality', ['jshint', 'jscs'], function() {}); -gulp.task('testAll', ['runBasicTests', 'runAdvancedTests'], function() {}); gulp.task('default', ['build'], function() {}); -gulp.task('serve', ['build-dev', 'watch'], function () { +gulp.task('serve', ['build-dev', 'watch', 'browser-sync'], function () { var port = 9999; require('http').createServer(ecstatic({ root: __dirname @@ -112,22 +112,22 @@ gulp.task('serve', ['build-dev', 'watch'], function () { console.log('Server started at http://localhost:' + port + '/'); }); -gulp.task('build-dev', ['jscs', 'clean-dist'], function () { - gulp.src(['src/prebid.js']) - .pipe(browserify({ - debug: false - })) +gulp.task('build-dev', ['jscs', 'clean-dist', 'browserify', 'unit-tests'], function () { + gulp.src(['src/prebid.js']) + .pipe(gulpBrowserify({ + debug: false + })) .pipe(header(banner, { pkg: pkg })) - .pipe(gulp.dest(releaseDir)); + .pipe(gulp.dest(releaseDir)); }); gulp.task('build-minify', ['clean-dist', 'quality'], function(cb){ gulp.src(['src/prebid.js']) - .pipe(browserify({ + .pipe(gulpBrowserify({ transform : preprocessify({ NODE_ENV: 'production'}) } @@ -155,6 +155,7 @@ gulp.task('quality', ['jscs'], function(cb){ gulp.task('watch', function () { gulp.watch(['src/**/*.js'], ['build-dev']); + //gulp.watch(["test/tests.js", "src/*"], ["browserify", "unit-tests"]); }); @@ -179,3 +180,34 @@ gulp.task('zip', ['quality', 'clean-dist', 'build-minify'], function () { .pipe(gulp.dest('./')); }); +gulp.task("browser-sync", function () { + "use strict"; + browserSync({ + server: { + //serve tests and the root as base dirs + baseDir: ["./test/", "./"], + //make tests.html the index file + index: "automatedRunnner.html" + } + }); +}); + +//see http://fettblog.eu/gulp-browserify-multiple-bundles/ +gulp.task("browserify", function() { + "use strict"; + return browserify("./test/test.js") + .bundle() + .on("error", function (err) { + console.log(err.toString()); + this.emit("end"); + }) + .pipe(source("tests-browserify.js")) + .pipe(gulp.dest("test/")) + .pipe(browserSync.reload({stream:true})); +}); + +gulp.task("unit-tests", function () { + "use strict"; + return gulp.src("./test/automatedRunnner.html") + .pipe(mochaPhantomJS()); +}); diff --git a/package.json b/package.json index 877b23765d0..ac139a0ba43 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "author": [], "license": "NONE", "devDependencies": { + "browser-sync": "^2.11.0", + "browserify": "^12.0.1", "del": "^1.1.1", "ecstatic": "^0.8.0", "gulp": "^3.9.0", @@ -19,6 +21,7 @@ "gulp-jsdoc-to-markdown": "^1.1.1", "gulp-jshint": "^1.9.2", "gulp-mocha": "^2.1.3", + "gulp-mocha-phantomjs": "^0.10.1", "gulp-notify": "^2.2.0", "gulp-rename": "^1.2.2", "gulp-sourcemaps": "^1.5.0", @@ -28,7 +31,10 @@ "gulp-zip": "^3.0.2", "jsdoc-to-markdown": "^1.1.1", "jshint-stylish": "^2.0.1", - "preprocessify": "0.0.6" + "mocha": "^2.3.4", + "mocha-phantomjs": "^4.0.2", + "preprocessify": "0.0.6", + "vinyl-source-stream": "^1.1.0" }, "dependencies": {} } diff --git a/src/bidmanager.js b/src/bidmanager.js index 27e12b9c4ab..f52062d08e4 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -168,7 +168,7 @@ exports.addBidResponse = function(adUnitCode, bid) { //if there is any key value pairs to map do here var keyValues = {}; if (bid.bidderCode && bid.cpm !== 0) { - keyValues = getKeyValueTargetingPairs(bid.bidderCode, bid); + keyValues = this.getKeyValueTargetingPairs(bid.bidderCode, bid); bid.adserverTargeting = keyValues; } @@ -213,7 +213,7 @@ exports.createEmptyBidResponseObj = function() { }; }; -function getKeyValueTargetingPairs(bidderCode, custBidObj) { +exports.getKeyValueTargetingPairs = function(bidderCode, custBidObj) { //retrive key value settings var keyValues = {}; var bidder_settings = pbjs.bidderSettings || {}; @@ -260,7 +260,7 @@ function getKeyValueTargetingPairs(bidderCode, custBidObj) { } return keyValues; -} +}; function setKeys(keyValues, bidderSettings, custBidObj) { var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]; diff --git a/test/automatedRunnner.html b/test/automatedRunnner.html new file mode 100644 index 00000000000..2f82a9a36da --- /dev/null +++ b/test/automatedRunnner.html @@ -0,0 +1,29 @@ + + + +
+ +