Skip to content

Commit

Permalink
Merge pull request #104 from MailOnline/fix/QA_fixes
Browse files Browse the repository at this point in the history
fix: 🐜 destroy video ad container on run finish
  • Loading branch information
carpasse authored Nov 27, 2018
2 parents ff1cff7 + 7ffc9a0 commit 8c9d5b3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/runner/__tests__/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ describe('run', () => {
expect(startVideoAd).toHaveBeenCalledWith(vastAdChain, adContainer, options);
});

test('must destroy the ad container on adUnit finish', async () => {
adContainer.destroy = jest.fn();

expect(await run(vastAdChain, placeholder, options)).toBe(adUnit);
expect(adContainer.destroy).toHaveBeenCalledTimes(0);

adUnit.cancel();
expect(adContainer.destroy).toHaveBeenCalledTimes(1);
});

test('must propagate adUnit creation errors', async () => {
expect.assertions(1);
const testError = new Error('Ad container creation error');

createVideoAdContainer.mockImplementation(() => {
throw testError;
});

try {
await run(vastAdChain, placeholder, options);
} catch (error) {
expect(error).toBe(testError);
}
});

test('must destroy the adContainer if there is a problem starting the adUnit', async () => {
const adUnitError = new Error('boom');

Expand Down
4 changes: 4 additions & 0 deletions src/runner/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const run = async (vastChain, placeholder, options) => {

const adUnit = await adUnitPromise;

adUnit.onFinish(() => {
videoAdContainer.destroy();
});

return adUnit;
} catch (error) {
if (videoAdContainer) {
Expand Down

0 comments on commit 8c9d5b3

Please sign in to comment.