Skip to content

Commit

Permalink
Merge pull request #142 from MailOnline/next-release
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
carpasse committed Feb 1, 2019
2 parents 4beb2f7 + 2f60ea8 commit 17fbd64
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/adUnit/VastAdUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class VastAdUnit extends VideoAdUnit {
case errorEvt: {
this.error = data;
this.errorCode = this.error && this.error.code ? this.error.code : 405;
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error));
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error, {
adUnit: this,
vastChain: this.vastChain
}));
this[_protected].finish();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/adUnit/VideoAdUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class VideoAdUnit extends Emitter {
*
* @throws if ad unit is finished.
*
* @param {Function} callback - will be called on ad unit error passing the Error instance as the only argument if available.
* @param {Function} callback - will be called on ad unit error passing the Error instance and an object with the adUnit and the {@link VastChain}.
*/
onError (callback) {
if (typeof callback !== 'function') {
Expand Down
5 changes: 4 additions & 1 deletion src/adUnit/VpaidAdUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ class VpaidAdUnit extends VideoAdUnit {
this.error = vpaidGeneralError(payload);
this.errorCode = this.error.code;

this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error));
this[_protected].onErrorCallbacks.forEach((callback) => callback(this.error, {
adUnit: this,
vastChain: this.vastChain
}));

this[_protected].finish();

Expand Down
10 changes: 8 additions & 2 deletions src/adUnit/__tests__/VastAdUnit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ describe('VastAdUnit', () => {
type: errorEvt
});
expect(onErrorCallback).toHaveBeenCalledTimes(1);
expect(onErrorCallback).toHaveBeenCalledWith(adUnit.error);
expect(onErrorCallback).toHaveBeenCalledWith(adUnit.error, {
adUnit,
vastChain
});
});

test('start must select a mediaFile and update the src and the assetUri', async () => {
Expand Down Expand Up @@ -492,7 +495,10 @@ describe('VastAdUnit', () => {

videoElement.dispatchEvent(new Event('error'));
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(mediaError);
expect(callback).toHaveBeenCalledWith(mediaError, {
adUnit,
vastChain
});
expect(adUnit.error).toBe(mediaError);
expect(adUnit.errorCode).toBe(405);
expect(adUnit.isFinished()).toBe(true);
Expand Down
11 changes: 8 additions & 3 deletions src/adUnit/__tests__/VpaidAdUnit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,10 @@ describe('VpaidAdUnit', () => {
} catch (error) {
expect(error).toBe(handshakeVersionError);
expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(handshakeVersionError);
expect(callback).toHaveBeenCalledWith(handshakeVersionError, {
adUnit,
vastChain: adUnit.vastChain
});
}
});

Expand All @@ -709,10 +712,12 @@ describe('VpaidAdUnit', () => {
adUnit.creativeAd.emit(adError);

expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(expect.any(Error));
expect(callback).toHaveBeenCalledWith(expect.objectContaining({
message: 'VPAID general error'
}));
}), {
adUnit,
vastChain: adUnit.vastChain
});
});
});
});
Expand Down
22 changes: 18 additions & 4 deletions src/runner/__tests__/runWaterfall.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,16 @@ describe('runWaterfall', () => {
await deferred.promise;

expect(onError).toHaveBeenCalledTimes(3);
expect(onError).toHaveBeenCalledWith(runError);
expect(onError).toHaveBeenCalledWith(requestError);
expect(onError).toHaveBeenCalledWith(runError, {
adUnit: undefined,
vastChain: vastAdChain
});

expect(onError).toHaveBeenCalledWith(requestError, {
adUnit: undefined,
vastChain: undefined
});

expect(requestAd).toHaveBeenCalledTimes(1);
expect(requestAd).toHaveBeenCalledWith(adTag, expect.any(Object));
expect(requestNextAd).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -340,10 +348,16 @@ describe('runWaterfall', () => {
const simulateAdUnitError = adUnit.onError.mock.calls[0][0];
const mockError = new Error('mock error');

simulateAdUnitError(mockError);
simulateAdUnitError(mockError, {
adUnit,
vastChain: vastAdChain
});

expect(onError).toHaveBeenCalledTimes(1);
expect(onError).toHaveBeenCalledWith(mockError);
expect(onError).toHaveBeenCalledWith(mockError, {
adUnit,
vastChain: adUnit.vastChain
});
});
});

Expand Down
10 changes: 8 additions & 2 deletions src/runner/runWaterfall.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => {
});
}

onError(error);
onError(error, {
adUnit,
vastChain
});

if (vastChain && !isCanceled()) {
if (runEpoch) {
Expand Down Expand Up @@ -143,7 +146,7 @@ const waterfall = async (fetchVastChain, placeholder, options, isCanceled) => {
* Defaults to `5`.
* @param {runWaterfall~onAdReady} [options.onAdReady] - will be called once the ad is ready with the ad unit.
* @param {runWaterfall~onAdStart} [options.onAdStart] - will be called once the ad starts with the ad unit.
* @param {runWaterfall~onError} [options.onError] - will be called if there is an error with the video ad with the error instance.
* @param {runWaterfall~onError} [options.onError] - will be called if there is an error with the video ad with the error instance and an obj with the {@link VastChain} and the ad unit if it exists.
* @param {runWaterfall~onRunFinish} [options.onRunFinish] - will be called whenever the ad run finishes.
* @param {boolean} [options.viewability] - if true it will pause the ad whenever is not visible for the viewer.
* Defaults to `false`
Expand Down Expand Up @@ -223,6 +226,9 @@ export default runWaterfall;
*
* @callback RunWaterfall~onError
* @param {Error} error - the ad unit error.
* @param {Object} [data] - Data object that will contain:
* @param {VastChain} [data.vastChain] - The {@link VastChain} that caused the error.
* @param {VideoAdUnit} [data.adUnit] - Ad unit instance it can be a {@link VastAdUnit} or a {@link VpaidAdUnit}. Will only be added if the vastChain had an ad.
*/

/**
Expand Down

0 comments on commit 17fbd64

Please sign in to comment.