From 4ddf98c73a863aedf0f953a71d1d1934cea16d91 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Thu, 13 Oct 2016 16:33:19 -0700 Subject: [PATCH 01/12] style(package): update dependencies --- examples/apps/infinite-scrolling/app.js | 6 ++--- examples/apps/interstitial/app.js | 2 +- examples/apps/lazy-render/app.js | 8 +++---- examples/apps/responsive/app.js | 8 +++---- examples/apps/responsive/button.js | 2 +- examples/apps/routing/app.js | 15 +++++++----- examples/apps/routing/page.js | 2 +- examples/apps/single-request/app.js | 16 ++++++------- examples/apps/single-request/button.js | 2 +- examples/apps/static-ad/app.js | 6 ++--- package.json | 32 ++++++++++++------------- src/Bling.js | 2 +- test/Bling.spec.js | 20 ++++++++-------- 13 files changed, 62 insertions(+), 59 deletions(-) diff --git a/examples/apps/infinite-scrolling/app.js b/examples/apps/infinite-scrolling/app.js index baaab47..f5b4b45 100644 --- a/examples/apps/infinite-scrolling/app.js +++ b/examples/apps/infinite-scrolling/app.js @@ -71,8 +71,8 @@ class App extends Component { while (contentCnt < page * 3) { // eslint-disable-line no-unmodified-loop-condition contents.push(
diff --git a/examples/apps/interstitial/app.js b/examples/apps/interstitial/app.js index 9a7c78c..813e981 100644 --- a/examples/apps/interstitial/app.js +++ b/examples/apps/interstitial/app.js @@ -19,8 +19,8 @@ class App extends Component { return (
diff --git a/examples/apps/lazy-render/app.js b/examples/apps/lazy-render/app.js index 297f962..d4aef02 100644 --- a/examples/apps/lazy-render/app.js +++ b/examples/apps/lazy-render/app.js @@ -15,8 +15,8 @@ class App extends Component { return (
@@ -24,20 +24,20 @@ class App extends Component {
diff --git a/examples/apps/responsive/app.js b/examples/apps/responsive/app.js index e8745c7..dafefac 100644 --- a/examples/apps/responsive/app.js +++ b/examples/apps/responsive/app.js @@ -60,26 +60,26 @@ class App extends Component { return (
diff --git a/examples/apps/responsive/button.js b/examples/apps/responsive/button.js index 87f9af8..af1a4d7 100644 --- a/examples/apps/responsive/button.js +++ b/examples/apps/responsive/button.js @@ -16,8 +16,8 @@ export default class Button extends Component { render() { return ( diff --git a/examples/apps/routing/app.js b/examples/apps/routing/app.js index c26516b..fe47e7f 100644 --- a/examples/apps/routing/app.js +++ b/examples/apps/routing/app.js @@ -1,6 +1,6 @@ /* eslint-disable react/no-multi-comp */ import React, {Component, PropTypes} from "react"; -import createHistory from "history/lib/createHashHistory"; +import createHistory from "history/createHashHistory"; import {Bling as Gpt} from "react-gpt"; // eslint-disable-line import/no-unresolved import "../log"; import Home from "./home"; @@ -17,9 +17,12 @@ class App extends Component { children: PropTypes.node } + createHref(path) { + return `${window.location.origin}${window.location.pathname}#${path}`; + } + render() { - const {location, history, children} = this.props; - const createHref = history.createHref; + const {location, children} = this.props; const adUnitPath = `/4595/nfl.test.open${location.pathname}`; const props = { ...this.props, @@ -29,9 +32,9 @@ class App extends Component { return (
diff --git a/examples/apps/single-request/app.js b/examples/apps/single-request/app.js index 5d2919d..b581cd9 100644 --- a/examples/apps/single-request/app.js +++ b/examples/apps/single-request/app.js @@ -46,50 +46,50 @@ class App extends Component { return (
diff --git a/examples/apps/single-request/button.js b/examples/apps/single-request/button.js index 87f9af8..af1a4d7 100644 --- a/examples/apps/single-request/button.js +++ b/examples/apps/single-request/button.js @@ -16,8 +16,8 @@ export default class Button extends Component { render() { return ( diff --git a/examples/apps/static-ad/app.js b/examples/apps/static-ad/app.js index 22f74e6..673526b 100644 --- a/examples/apps/static-ad/app.js +++ b/examples/apps/static-ad/app.js @@ -21,17 +21,17 @@ class App extends Component { return (
`} + slotSize={[728, 90]} + style={styles.adBorder} />
diff --git a/package.json b/package.json index c90b035..7bc6921 100644 --- a/package.json +++ b/package.json @@ -34,18 +34,18 @@ "dependencies": { "debounce": "^1.0.0", "deep-equal": "^1.0.1", - "eventemitter3": "^1.1.1", + "eventemitter3": "^2.0.2", "fbjs": "^0.8.1", "hoist-non-react-statics": "^1.0.5" }, "devDependencies": { "babel-cli": "^6.5.1", "babel-core": "^6.5.1", - "babel-eslint": "^6.0.3", + "babel-eslint": "^7.0.0", "babel-loader": "^6.2.3", "babel-plugin-transform-decorators-legacy": "^1.3.4", - "babel-plugin-webpack-alias": "^1.1.1", - "babel-preset-es2015-without-strict": "^0.0.2", + "babel-plugin-webpack-alias": "^2.1.1", + "babel-preset-es2015-without-strict": "^0.0.4", "babel-preset-react": "^6.5.0", "babel-preset-stage-0": "^6.5.0", "babel-register": "^6.7.2", @@ -54,25 +54,25 @@ "conventional-changelog-cli": "^1.2.0", "core-js": "^2.2.2", "cz-conventional-changelog": "^1.1.6", - "eslint": "2.8.0", - "eslint-config-nfl": "8.0.1", - "eslint-plugin-import": "1.5.0", - "eslint-plugin-mocha": "2.2.0", - "eslint-plugin-react": "5.0.1", + "eslint": "3.7.1", + "eslint-config-nfl": "10.0.0", + "eslint-plugin-import": "2.0.1", + "eslint-plugin-mocha": "4.7.0", + "eslint-plugin-react": "6.4.1", "express": "^4.13.4", - "history": "^2.0.1", + "history": "^4.3.0", "isparta-loader": "^2.0.0", - "karma": "^0.13.19", + "karma": "^1.3.0", "karma-chai-sinon": "^0.1.5", - "karma-chrome-launcher": "^0.2.2", - "karma-cli": "^0.1.2", - "karma-coverage": "^0.5.3", - "karma-mocha": "^0.2.1", + "karma-chrome-launcher": "^2.0.0", + "karma-cli": "^1.0.1", + "karma-coverage": "^1.1.1", + "karma-mocha": "^1.2.0", "karma-mocha-reporter": "^2.0.0", "karma-sourcemap-loader": "^0.3.6", "karma-tap-reporter": "0.0.6", "karma-webpack": "^1.7.0", - "mocha": "^2.3.4", + "mocha": "^3.1.2", "phantom": "^2.0.4", "querystring": "^0.2.0", "radium": "^0.18.1", diff --git a/src/Bling.js b/src/Bling.js index c6c24c1..e9e5b94 100644 --- a/src/Bling.js +++ b/src/Bling.js @@ -722,7 +722,7 @@ class Bling extends Component { } this._divId = id || Bling._adManager.generateDivId(); - return
; + return
; } } diff --git a/test/Bling.spec.js b/test/Bling.spec.js index 2f8f7fc..cd7e734 100644 --- a/test/Bling.spec.js +++ b/test/Bling.spec.js @@ -297,13 +297,13 @@ describe("Bling", () => { ); @@ -322,8 +322,8 @@ describe("Bling", () => { const instance = ReactTestUtils.renderIntoDocument( ); }); @@ -350,13 +350,13 @@ describe("Bling", () => { ); @@ -373,8 +373,8 @@ describe("Bling", () => { const instance = ReactTestUtils.renderIntoDocument( ); }); @@ -392,8 +392,8 @@ describe("Bling", () => { const instance = ReactTestUtils.renderIntoDocument( ); }); @@ -425,8 +425,8 @@ describe("Bling", () => { const instance = ReactTestUtils.renderIntoDocument( ); }); @@ -459,14 +459,14 @@ describe("Bling", () => { ); From 7ef392852bdda158e60b380456b501389006e64e Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Thu, 13 Oct 2016 17:18:38 -0700 Subject: [PATCH 02/12] docs: add badge --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 918cc54..e51933f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # React GPT +[![npm package](https://img.shields.io/npm/v/react-gpt.svg?style=flat-square)](https://www.npmjs.org/package/react-gpt) +[![build status](https://img.shields.io/travis/nfl/react-gpt/master.svg?style=flat-square)](https://travis-ci.org/nfl/react-gpt) +[![dependency status](https://img.shields.io/david/nfl/react-gpt.svg?style=flat-square)](https://david-dm.org/nfl/react-gpt) A [React](https://github.com/facebook/react) component for [Google Publisher Tags](https://developers.google.com/doubleclick-gpt/?hl=en). From bbeda906ec66f30cb80eec9c952bba593e20c1bf Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Thu, 13 Oct 2016 17:30:57 -0700 Subject: [PATCH 03/12] ci(travis): add travis build --- .travis.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1077651 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +language: node_js +sudo: false +node_js: + - "4" + - "5" +cache: + directories: + - node_modules +env: + global: + - LOGS_DIR=/tmp/react-gpt-build/logs +matrix: + fast_finish: true + include: + - node_js: stable +before_install: + - export CHROME_BIN=chromium-browser + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start +before_script: + - mkdir -p $LOGS_DIR +script: + - npm test From 9ea10caabaf9fd5127490888a8daf7cbffffb9e4 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Thu, 13 Oct 2016 17:46:02 -0700 Subject: [PATCH 04/12] ci(codecov): add code coverage report --- .travis.yml | 2 ++ README.md | 1 + karma.conf.ci.js | 17 +++++++++++++++++ karma.conf.js | 7 +++++++ package.json | 1 + 5 files changed, 28 insertions(+) create mode 100644 karma.conf.ci.js diff --git a/.travis.yml b/.travis.yml index 1077651..817a8c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,3 +21,5 @@ before_script: - mkdir -p $LOGS_DIR script: - npm test +after_success: + - cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js diff --git a/README.md b/README.md index e51933f..6e0396a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![npm package](https://img.shields.io/npm/v/react-gpt.svg?style=flat-square)](https://www.npmjs.org/package/react-gpt) [![build status](https://img.shields.io/travis/nfl/react-gpt/master.svg?style=flat-square)](https://travis-ci.org/nfl/react-gpt) [![dependency status](https://img.shields.io/david/nfl/react-gpt.svg?style=flat-square)](https://david-dm.org/nfl/react-gpt) +[![codecov.io](https://img.shields.io/codecov/c/github/nfl/react-gpt/master.svg?style=flat-square)](https://codecov.io/github/nfl/react-gpt?branch=master) A [React](https://github.com/facebook/react) component for [Google Publisher Tags](https://developers.google.com/doubleclick-gpt/?hl=en). diff --git a/karma.conf.ci.js b/karma.conf.ci.js new file mode 100644 index 0000000..989e447 --- /dev/null +++ b/karma.conf.ci.js @@ -0,0 +1,17 @@ +/* eslint-disable camelcase */ +module.exports = function (config) { + config.set({ + singleRun: true + }); + + console.log("running default test on Chrome"); + config.set({ + customLaunchers: { + Chrome_CI: { + base: "Chrome", + flags: ["--no-sandbox"] + } + }, + browsers: ["Chrome_CI"] + }); +}; diff --git a/karma.conf.js b/karma.conf.js index 486a839..924a316 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -32,6 +32,9 @@ module.exports = function (config) { subdir: "html" }, { type: "text" + }, { + type: "lcovonly", + subdir: "." }] }, @@ -83,4 +86,8 @@ module.exports = function (config) { singleRun: false }); + + if (process.env.CI) { + require("./karma.conf.ci.js")(config); + } }; diff --git a/package.json b/package.json index 7bc6921..b9d207d 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "babel-preset-stage-0": "^6.5.0", "babel-register": "^6.7.2", "chai": "^3.4.1", + "codecov.io": "^0.1.6", "commitizen": "^2.8.1", "conventional-changelog-cli": "^1.2.0", "core-js": "^2.2.2", From 4922e7275a7b1e5761150f75b74e4d2f4015cb88 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Thu, 13 Oct 2016 17:57:35 -0700 Subject: [PATCH 05/12] chore(license): add license file --- LICENSE | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..423f8ac --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 NFL + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 742b226427cff885551f23a8091ba2b399e85137 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Fri, 14 Oct 2016 12:17:19 -0700 Subject: [PATCH 06/12] trigger build --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 817a8c5..5be4c5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,6 @@ node_js: cache: directories: - node_modules -env: - global: - - LOGS_DIR=/tmp/react-gpt-build/logs matrix: fast_finish: true include: @@ -17,8 +14,6 @@ before_install: - export CHROME_BIN=chromium-browser - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start -before_script: - - mkdir -p $LOGS_DIR script: - npm test after_success: From a9337eee35637f8948bfad41a3d5adccadef95dc Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Fri, 14 Oct 2016 13:08:08 -0700 Subject: [PATCH 07/12] remove codecov badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6e0396a..e51933f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ [![npm package](https://img.shields.io/npm/v/react-gpt.svg?style=flat-square)](https://www.npmjs.org/package/react-gpt) [![build status](https://img.shields.io/travis/nfl/react-gpt/master.svg?style=flat-square)](https://travis-ci.org/nfl/react-gpt) [![dependency status](https://img.shields.io/david/nfl/react-gpt.svg?style=flat-square)](https://david-dm.org/nfl/react-gpt) -[![codecov.io](https://img.shields.io/codecov/c/github/nfl/react-gpt/master.svg?style=flat-square)](https://codecov.io/github/nfl/react-gpt?branch=master) A [React](https://github.com/facebook/react) component for [Google Publisher Tags](https://developers.google.com/doubleclick-gpt/?hl=en). From f3acd62c56cb17fc58081219bca077744e1fd046 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Sat, 15 Oct 2016 16:13:25 -0700 Subject: [PATCH 08/12] add codecov badge back --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e51933f..6e0396a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![npm package](https://img.shields.io/npm/v/react-gpt.svg?style=flat-square)](https://www.npmjs.org/package/react-gpt) [![build status](https://img.shields.io/travis/nfl/react-gpt/master.svg?style=flat-square)](https://travis-ci.org/nfl/react-gpt) [![dependency status](https://img.shields.io/david/nfl/react-gpt.svg?style=flat-square)](https://david-dm.org/nfl/react-gpt) +[![codecov.io](https://img.shields.io/codecov/c/github/nfl/react-gpt/master.svg?style=flat-square)](https://codecov.io/github/nfl/react-gpt?branch=master) A [React](https://github.com/facebook/react) component for [Google Publisher Tags](https://developers.google.com/doubleclick-gpt/?hl=en). From f97958872b9bd5e75bce27c876bd5a338be2a409 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Thu, 24 Nov 2016 08:36:34 -0800 Subject: [PATCH 09/12] docs: fix typo --- docs/api/ReactGPT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/ReactGPT.md b/docs/api/ReactGPT.md index 1f4c8a0..8b94433 100644 --- a/docs/api/ReactGPT.md +++ b/docs/api/ReactGPT.md @@ -8,7 +8,7 @@ A React component which renders [GPT](https://support.google.com/dfp_sb/answer/1 `Bling` tries to cover as much [Slot API](https://developers.google.com/doubleclick-gpt/reference#googletagslot) as possible as `props`. -- `is`(optional) - An optional string to be used as container div id. +- `id`(optional) - An optional string to be used as container div id. - `adUnitPath`(required) - An string indicating ad unit path which will be used to create an ad slot. - `targeting`(optional) - An optional object which includes ad targeting key-value pairs. - `slotSize`(optional) - An optional array of width and height size for the ad slot. This will be preceded by the sizeMapping if specified. From e0213024fd36c7c2348df36e250f52716d2d5ba8 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Sat, 21 Jan 2017 12:24:48 -0800 Subject: [PATCH 10/12] docs: update 'slotSize' prop comment --- docs/api/ReactGPT.md | 2 +- src/Bling.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/ReactGPT.md b/docs/api/ReactGPT.md index 8b94433..a366274 100644 --- a/docs/api/ReactGPT.md +++ b/docs/api/ReactGPT.md @@ -11,7 +11,7 @@ A React component which renders [GPT](https://support.google.com/dfp_sb/answer/1 - `id`(optional) - An optional string to be used as container div id. - `adUnitPath`(required) - An string indicating ad unit path which will be used to create an ad slot. - `targeting`(optional) - An optional object which includes ad targeting key-value pairs. -- `slotSize`(optional) - An optional array of width and height size for the ad slot. This will be preceded by the sizeMapping if specified. +- `slotSize`(optional) - An optional prop to specify the ad slot size which accepts [googletag.GeneralSize](https://developers.google.com/doubleclick-gpt/reference#googletag.GeneralSize) as a type. This will be preceded by the sizeMapping if specified. - `sizeMapping`(optional) - An optional array of object which contains an array of viewport size and slot size. This needs to be set if the ad needs to serve different ad sizes per different viewport sizes (responsive ad). Setting the `slot` to any dimension that's not configured in DFP results in rendering an empty ad. The ad slot size which is provided for the viewport size of [0, 0] will be used as default ad size if none of viewport size matches. - `outOfPage`(optional) - An optional flag to indicate whether an ad slot should be out-of-page slot. - `companionAdService`(optional) - An optional flag to indicate whether companion ad service should be enabled for the ad. If an object is passed, it takes as a configuration expecting `enableSyncLoading` or `refreshUnfilledSlots`. diff --git a/src/Bling.js b/src/Bling.js index e9e5b94..de8feff 100644 --- a/src/Bling.js +++ b/src/Bling.js @@ -41,7 +41,7 @@ class Bling extends Component { */ targeting: PropTypes.object, /** - * An optional array of width and height size for the ad slot. Additionally it accepts `fluid` for native ads. + * An optional prop to specify the ad slot size which accepts [googletag.GeneralSize](https://developers.google.com/doubleclick-gpt/reference#googletag.GeneralSize) as a type. * This will be preceded by the sizeMapping if specified. * * @property slotSize From fc374b62d1f630f3323c70e4196a6151699f622c Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Mon, 20 Feb 2017 17:51:47 -0800 Subject: [PATCH 11/12] fix: fix calling the same pubads API on Bling not overriding the previous one --- src/createManager.js | 7 +- src/utils/apiList.js | 9 +- src/utils/mockGPT.js | 202 +++++++++++++++++++++---------------------- test/Bling.spec.js | 19 ++++ 4 files changed, 127 insertions(+), 110 deletions(-) diff --git a/src/createManager.js b/src/createManager.js index 37c70fb..e3eeda9 100644 --- a/src/createManager.js +++ b/src/createManager.js @@ -94,7 +94,7 @@ export class AdManager extends EventEmitter { Object.keys(this._pubadsProxyQueue).forEach(method => { if ((this.googletag && !this.googletag.pubadsReady && APIToCallBeforeServiceEnabled.indexOf(method) > -1) || this.pubadsReady) { - this.pubadsProxy(this._pubadsProxyQueue[method]); + this._pubadsProxyQueue[method].forEach((params) => this.pubadsProxy(params)); delete this._pubadsProxyQueue[method]; } }); @@ -468,7 +468,10 @@ export class AdManager extends EventEmitter { if (!this._pubadsProxyQueue) { this._pubadsProxyQueue = {}; } - this._pubadsProxyQueue[method] = params; + if (!this._pubadsProxyQueue[method]) { + this._pubadsProxyQueue[method] = []; + } + this._pubadsProxyQueue[method].push(params); } else { this._callPubads(params); } diff --git a/src/utils/apiList.js b/src/utils/apiList.js index 2e757ad..e2ff40c 100644 --- a/src/utils/apiList.js +++ b/src/utils/apiList.js @@ -2,7 +2,7 @@ // This file is generated by `npm run update-apilist`. // Note that only APIs that's documented in https://developers.google.com/doubleclick-gpt/reference is officially supported. -export const gptVersion = 95; +export const gptVersion = 110; export const gptAPI = [ ["getVersion", "function"], ["cmd", "object"], @@ -15,7 +15,6 @@ export const gptAPI = [ ["defineSlot", "function"], ["defineUnit", "function"], ["destroySlots", "function"], - ["getSlots", "function"], ["display", "function"], ["companionAds", "function"], ["content", "function"], @@ -30,7 +29,7 @@ export const gptAPI = [ ["slot_manager_instance", "object"], ["pubadsReady", "boolean"] ]; -export const pubadsVersion = 95; +export const pubadsVersion = 110; export const pubadsAPI = [ ["set", "function"], ["get", "function"], @@ -124,7 +123,7 @@ export const slotAPI = [ ["visibilityChanged", "function"], ["setFirstLook", "function"], ["getFirstLook", "function"], - ["getDefinedId", "function"], ["getEscapedQemQueryId", "function"], - ["setSafeFrameConfig", "function"] + ["setSafeFrameConfig", "function"], + ["getCsiId", "function"] ]; diff --git a/src/utils/mockGPT.js b/src/utils/mockGPT.js index 6c03561..80ce4da 100644 --- a/src/utils/mockGPT.js +++ b/src/utils/mockGPT.js @@ -1,22 +1,24 @@ import {gptAPI, pubadsAPI, slotAPI, gptVersion, pubadsVersion} from "./apiList"; import Events from "../Events"; -function createMock(list) { +function createMock(list, obj) { return list.reduce((mock, [api, type]) => { - if (type === "function") { - mock[api] = (...args) => { - if (args.length) { - return args[0]; - } - return {}; - }; - } else if (type === "boolean") { - mock[api] = true; - } else { - mock[api] = {}; + if (typeof mock[api] === "undefined") { + if (type === "function") { + mock[api] = (...args) => { + if (args.length) { + return args[0]; + } + return {}; + }; + } else if (type === "boolean") { + mock[api] = true; + } else { + mock[api] = {}; + } } return mock; - }, {}); + }, obj || {}); } function getSize(slot) { @@ -29,131 +31,129 @@ function getSize(slot) { return item; } -const SlotMock = function (adUnitPath, size, divId) { - this.adUnitPath = adUnitPath; - this.size = size; - this.divId = divId; - this.services = []; - this.attributes = {}; - this.categoryExclusions = []; - this._targeting = {}; -}; -SlotMock.prototype = { - ...createMock(slotAPI), +class SlotMock { + constructor(adUnitPath, size, divId) { + this.adUnitPath = adUnitPath; + this.size = size; + this.divId = divId; + this.services = []; + this.attributes = {}; + this.categoryExclusions = []; + this._targeting = {}; + } defineSizeMapping(sizeMapping) { this.size = sizeMapping; return this; - }, + } addService(service) { this.services.push(service); - }, + } getServices() { return this.services; - }, + } set(key, value) { this.attributes[key] = value; return this; - }, + } get(key) { return this.attributes[key]; - }, + } getAttributeKeys() { return Object.keys(this.attributes); - }, + } setCollapseEmptyDiv(collapse, collapseBeforeAdFetch) { this.collapseEmptyDiv = collapse; this.collapseBeforeAdFetch = collapseBeforeAdFetch; return this; - }, + } getCollapseEmptyDiv() { return this.collapseEmptyDiv; - }, + } setClickUrl(clickUrl) { this.clickUrl = clickUrl; return this; - }, + } getClickUrl() { return this.clickUrl; - }, + } setCategoryExclusion(categoryExclusion) { this.categoryExclusions.push(categoryExclusion); return this; - }, + } getCategoryExclusions() { return this.categoryExclusions; - }, + } clearCategoryExclusions() { this.categoryExclusions = []; return this; - }, + } setTargeting(key, value) { this._targeting[key] = value; return this; - }, + } getAdUnitPath() { return this.adUnitPath; - }, + } clearTargeting() { this._targeting = {}; return this; - }, + } getTargeting(key) { return this._targeting && this._targeting[key]; - }, + } getTargetingKeys() { return this._targeting && Object.keys(this._targeting); - }, + } getSizes() { return this.size; - }, + } getSlotElementId() { return this.divId; } -}; +} +createMock(slotAPI, SlotMock.prototype); -const SizeMappingBuilderMock = function (config = {}) { - this.config = config; -}; -SizeMappingBuilderMock.prototype = { +class SizeMappingBuilderMock { + constructor(config = {}) { + this.config = config; + } addSize(viewportSize, slotSize) { if (!this.mapping) { this.mapping = []; } this.mapping.push([viewportSize, slotSize]); return this; - }, + } build() { return this.mapping; } -}; +} -const BaseService = function () { - this.listeners = {}; -}; -BaseService.prototype = { +class BaseService { + constructor(config = {}) { + this.config = config; + this.listeners = {}; + this.slots = {}; + } addEventListener(eventType, cb) { if (!this.listeners[eventType]) { this.listeners[eventType] = []; } this.listeners[eventType].push(cb); } -}; + getSlots() { + return Object.keys(this.slots).map(key => this.slots[key]); + } +} -const PubAdsServiceMock = function (config = {}) { - this.config = config; - this.version = pubadsVersion; - this.listeners = {}; - this.slots = {}; -}; -PubAdsServiceMock.prototype = { - ...createMock(pubadsAPI), - ...BaseService.prototype, +class PubAdsServiceMock extends BaseService { + constructor(config = {}) { + super(config); + this.version = pubadsVersion; + } getVersion() { return this.version; - }, - getSlots() { - return Object.keys(this.slots).map(key => this.slots[key]); - }, + } refresh(slots) { if (!slots) { slots = Object.keys(this.slots).map(key => this.slots[key]); @@ -178,86 +178,81 @@ PubAdsServiceMock.prototype = { }); }, 0); } -}; +} +createMock(pubadsAPI, PubAdsServiceMock.prototype); -const CompanionAdsServiceMock = function (config = {}) { - this.config = config; - this.listeners = {}; -}; -CompanionAdsServiceMock.prototype = { - ...BaseService.prototype, +class CompanionAdsServiceMock extends BaseService { + constructor(config = {}) { + super(config); + } enableSyncLoading() { this._enableSyncLoading = true; - }, + } setRefreshUnfilledSlots(value) { if (typeof value === "boolean") { this._refreshUnfilledSlots = value; } } -}; - -const ContentServiceMock = function (config = {}) { - this.config = config; - this.listeners = {}; -}; -ContentServiceMock.prototype = { - ...BaseService.prototype, +} +class ContentServiceMock extends BaseService { + constructor(config = {}) { + super(config); + } setContent(slot, content) { slot._content = content; } -}; +} -const GPTMock = function (config = {}) { - this.config = config; - this.version = gptVersion; - this.cmd = {}; - this.cmd.push = cb => {cb();}; -}; -GPTMock.prototype = { - ...createMock(gptAPI), - pubadsReady: false, +class GPTMock { + constructor(config = {}) { + this.config = config; + this.version = gptVersion; + this.cmd = {}; + this.cmd.push = cb => {cb();}; + } + pubadsReady = false; getVersion() { return this.version; - }, + } enableServices() { setTimeout(() => { this.pubadsReady = true; }, 0); - }, + } sizeMapping() { if (!this.sizeMappingBuilder) { this.sizeMappingBuilder = new SizeMappingBuilderMock(this.config); } return this.sizeMappingBuilder; - }, + } pubads() { if (!this._pubads) { this._pubads = new PubAdsServiceMock(this.config); } return this._pubads; - }, + } companionAds() { if (!this._companionAds) { this._companionAds = new CompanionAdsServiceMock(this.config); } return this._companionAds; - }, + } content() { if (!this._content) { this._content = new ContentServiceMock(this.config); } return this._content; - }, + } defineSlot(adUnitPath, size, divId) { const slot = new SlotMock(adUnitPath, size, divId); this.pubads().slots[divId] = slot; return slot; - }, + } defineOutOfPageSlot(adUnitPath, divId) { const slot = new SlotMock(adUnitPath, [1, 1], divId); this.pubads().slots[divId] = slot; return slot; - }, + } display(divId) { const pubads = this.pubads(); setTimeout(() => { @@ -280,7 +275,8 @@ GPTMock.prototype = { }); }, 0); } -}; +} +createMock(gptAPI, GPTMock.prototype); export { GPTMock, diff --git a/test/Bling.spec.js b/test/Bling.spec.js index cd7e734..2c56f16 100644 --- a/test/Bling.spec.js +++ b/test/Bling.spec.js @@ -112,6 +112,25 @@ describe("Bling", () => { ); }); + it("can call pubads API multiple times", (done) => { + const spy = sinon.stub(googletag.pubads(), "setTargeting"); + + Bling.once(Events.RENDER, () => { + expect(spy.calledTwice).to.be.true; + expect(spy.calledWith("key1", "value1")).to.be.true; + expect(spy.calledWith("key2", "value2")).to.be.true; + sinon.restore(spy); + done(); + }); + + Bling.setTargeting("key1", "value1"); + Bling.setTargeting("key2", "value2"); + + ReactTestUtils.renderIntoDocument( + + ); + }); + it("fires once event", (done) => { const events = Object.keys(Events).map(key => Events[key]); From e2d0e333c2afc5168edc056e28670b69acb81956 Mon Sep 17 00:00:00 2001 From: Takashi Aoki Date: Mon, 20 Feb 2017 18:25:05 -0800 Subject: [PATCH 12/12] bump 0.2.3 --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 845d6d1..63690f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ + +## [0.2.3](https://github.com/nfl/react-gpt/compare/v0.2.2...v0.2.3) (2017-02-21) + + +### Bug Fixes + +* fix calling the same pubads API on Bling not overriding the previous one ([fc374b6](https://github.com/nfl/react-gpt/commit/fc374b6)) + + + ## [0.2.2](https://github.com/nfl/react-gpt/compare/v0.2.1...v0.2.2) (2016-10-13) diff --git a/package.json b/package.json index b9d207d..af12074 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-gpt", - "version": "0.2.2", + "version": "0.2.3", "description": "A react display ad component using Google Publisher Tag", "main": "lib/index.js", "contributors": [