Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native DOMParser and XMLSerializer #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/iab-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
"@ygoto3/omap-vast-parser": "^0.0.3"
},
"devDependencies": {
"ts-node": "^10.9.2",
"@types/xmldom": "^0.1.34",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"uvu": "^0.5.6",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-merge": "^5.10.0"
"webpack-merge": "^5.10.0",
"xmldom": "^0.6.0"
},
"files": [
"dist"
Expand Down
23 changes: 13 additions & 10 deletions packages/iab-client/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import * as assert from 'uvu/assert';
import IABClient, { sortAdsBySequence } from '../src/IABClient';
import { OmapClientEvent, IHttpClient, AdPodInsertionRequest, AdPod, Ad } from "@ygoto3/omap-core";
import { Ad as ParserAd } from '@ygoto3/omap-vast-parser';
import * as ENV from './setup/env';


const test = suite('IABClient');

test.before(ENV.setup);

test('adTagUrl is vmap', async () => {
const adTagUrl = 'https://example.com/vmap';
const httpClient = new MockHttpClient();
httpClient.registerGetFunction(get_function);
const adClient = new IABClient(adTagUrl, httpClient);

let content_pause_requested_count = 0;
let content_resume_requested_count = 0;
let content_can_play_count = 0;
Expand Down Expand Up @@ -67,7 +70,7 @@ test('adTagUrl is vmap', async () => {
const midroll_2_ad_2_creative_1_tracking_midpoint = createPromise();
const midroll_2_ad_2_creative_1_tracking_thirdQuartile = createPromise();
const midroll_2_ad_2_creative_1_tracking_complete = createPromise();

adClient.on(OmapClientEvent.CONTENT_PAUSE_REQUESTED, () => {
content_pause_requested_count++;
});
Expand Down Expand Up @@ -452,7 +455,7 @@ test('adTagUrl is vmap', async () => {

assert.is(content_pause_requested_count, 0, 'Content pause should not be requested');
assert.is(content_resume_requested_count, 0, 'Content resume should not be requested');

adClient.notifyCurrentTime(0);
await preroll_1.promise;

Expand All @@ -467,7 +470,7 @@ test('adTagUrl is vmap', async () => {
assert.ok(true, 'Impression 1 should be sent');
await preroll_1_ad_1_impression_2.promise;
assert.ok(true, 'Impression 2 should be sent');

adClient.notifyAdCreativePlaying(ad.adCreatives[0], 0.01, ad.sequence);
await ad_1_creative_1_tracking_start.promise;
assert.ok(true, 'Creative 1 tracking start should be sent');
Expand All @@ -478,7 +481,7 @@ test('adTagUrl is vmap', async () => {

adClient.notifyAdCreativePlaying(ad.adCreatives[0], 5.0, ad.sequence);
await ad_1_creative_1_tracking_midpoint.promise;
assert.ok(true, 'Creative 1 tracking midpoint should be sent');
assert.ok(true, 'Creative 1 tracking midpoint should be sent');

adClient.notifyAdCreativePlaying(ad.adCreatives[0], 7.5, ad.sequence);
await ad_1_creative_1_tracking_thirdQuartile.promise;
Expand All @@ -505,7 +508,7 @@ test('adTagUrl is vmap', async () => {

await preroll_1_ad_1_error_1.promise;
assert.ok(true, 'Ad 2 Impression 2 should fail to be sent');

adClient.notifyAdCreativePlaying(ad.adCreatives[0], 0.1, ad.sequence);
await ad_2_creative_1_tracking_start.promise;
assert.ok(true, 'Ad 2 Creative 1 tracking start should be sent');
Expand Down Expand Up @@ -545,7 +548,7 @@ test('adTagUrl is vmap', async () => {
// midroll 1 - 1st ad
ad = ad_pod!.ads[0];
assert.is(ad.sequence, ad_pod_prepared!.ads[0].sequence, 'Ad should be the same as the one prefetched');

adClient.notifyAdStarted(ad);
await midroll_1_ad_1_impression_1.promise;
assert.ok(true, 'Midroll 1 Impression 1 should be sent');
Expand Down Expand Up @@ -589,7 +592,7 @@ test('adTagUrl is vmap', async () => {
// midroll 2 - 1st ad
ad = ad_pod!.ads[0];
assert.is(ad.sequence, ad_pod_prepared!.ads[0].sequence, 'Ad should be the same as the one prefetched');

adClient.notifyAdStarted(ad);
await midroll_2_ad_1_impression_1.promise;
assert.ok(true, 'Midroll 2 Ad 1 Impression 1 should be sent');
Expand Down Expand Up @@ -617,7 +620,7 @@ test('adTagUrl is vmap', async () => {
// midroll 2 - 2nd ad
ad = ad_pod!.ads[1];
assert.is(ad.sequence, ad_pod_prepared!.ads[1].sequence, 'Ad should be the same as the one prefetched');

adClient.notifyAdStarted(ad);
await midroll_2_ad_2_impression_1.promise;
assert.ok(true, 'Midroll 2 Ad 2 Impression 1 should be sent');
Expand Down Expand Up @@ -698,4 +701,4 @@ function wait(): Promise<void> {
return new Promise<void>((resolve) => setTimeout(resolve, 10));
}

test.run();
test.run();
6 changes: 6 additions & 0 deletions packages/iab-client/tests/setup/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DOMParser, XMLSerializer } from 'xmldom';

export function setup() {
globalThis.DOMParser = DOMParser;
globalThis.XMLSerializer = XMLSerializer;
}
3 changes: 0 additions & 3 deletions packages/utils/src/forceArray.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { default as eraseNaN } from "./eraseNaN";
export { default as filterNull } from "./filterNull";
export { default as forceArray } from "./forceArray";
export { default as mapArrayOrElem } from "./mapArrayOrElem";
export { default as Debug } from "./Debug";
5 changes: 2 additions & 3 deletions packages/utils/src/mapArrayOrElem.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import forceArray from "./forceArray";
import filterNull from "./filterNull";

export default function mapArrayOrElem<T, U>(
arr: T[] | T,
arr: T[],
fn: (item: T) => U | null,
): U[] {
return forceArray(arr).map(fn).filter(filterNull) as U[];
return arr.map(fn).filter(filterNull) as U[];
}
24 changes: 0 additions & 24 deletions packages/utils/tests/forceArray.test.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/utils/tests/mapArrayOrElem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ const test = suite('utils');
test('mapArrayOrElem', () => {
let actual: any;
let expected: any;

expected = ['aa'];
actual = mapArrayOrElem('a', (item) => item + item);
assert.equal(actual, expected);

expected = ['bb', 'cc'];
actual = mapArrayOrElem(['b', 'c'], (item) => item + item);
assert.equal(actual, expected);
});

test.run();
test.run();
7 changes: 3 additions & 4 deletions packages/vast-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
"build": "tsc -p tsconfig.json",
"test": "uvu -r ts-node/register tests"
},
"dependencies": {
"xml-js": "^1.6.11"
},
"devDependencies": {
"@types/xmldom": "^0.1.34",
"buffer": "^6.0.3",
"stream": "^0.0.2",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"uvu": "^0.5.6",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-merge": "^5.10.0"
"webpack-merge": "^5.10.0",
"xmldom": "^0.6.0"
},
"files": [
"dist"
Expand Down
Loading