Skip to content

Commit

Permalink
Delete lib modules (#1697)
Browse files Browse the repository at this point in the history
* Inline google-ad-size module

* Delete noop.ts lib

* Delete support-utilities util

* Delete time-utils

* Delete cookies.js

* Delete config.js

* Fix tests
  • Loading branch information
arelra authored Dec 10, 2024
1 parent a446fff commit 5a6366b
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 382 deletions.
5 changes: 2 additions & 3 deletions src/core/messenger/scroll.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { noop } from '../../utils/noop';
import { _ as testExports } from './scroll';

const addScrollListener = testExports.addScrollListener;
Expand Down Expand Up @@ -91,8 +90,8 @@ describe.skip('Cross-frame messenger: scroll', () => {
constructor(callback: ObsCallback) {
onIntersect = callback;
return Object.freeze({
observe: noop,
unobserve: noop,
observe: () => {},
unobserve: () => {},
disconnect: () => {
onIntersect = null;
},
Expand Down
15 changes: 2 additions & 13 deletions src/define/define-slot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { SizeMapping } from '../core/ad-sizes';
import { adSizes, createAdSize } from '../core/ad-sizes';
import { toGoogleTagSize } from '../utils/googletag-ad-size';
import {
buildGoogletagSizeMapping,
collectSizes,
Expand Down Expand Up @@ -74,21 +73,11 @@ describe('buildGoogletagSizeMapping', () => {
expect(result).toEqual([
[
[980, 0],
[
toGoogleTagSize(adSizes.mpu),
'fluid',
toGoogleTagSize(adSizes.googleCard),
toGoogleTagSize(adSizes.halfPage),
],
[adSizes.mpu, 'fluid', adSizes.googleCard, adSizes.halfPage],
],
[
[0, 0],
[
toGoogleTagSize(adSizes.mpu),
'fluid',
toGoogleTagSize(adSizes.googleCard),
toGoogleTagSize(adSizes.halfPage),
],
[adSizes.mpu, 'fluid', adSizes.googleCard, adSizes.halfPage],
],
]);
});
Expand Down
8 changes: 6 additions & 2 deletions src/define/define-slot.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { breakpoints as sourceBreakpoints } from '@guardian/source/foundations';
import { once } from 'lodash-es';
import type { SizeMapping, SlotName } from '../core/ad-sizes';
import type { AdSize, SizeMapping, SlotName } from '../core/ad-sizes';
import { EventTimer } from '../core/index';
import { isEligibleForTeads } from '../core/targeting/teads-eligibility';
import { toGoogleTagSize } from '../utils/googletag-ad-size';
import { getUrlVars } from '../utils/url';
import { initSlotIas } from './init-slot-ias';

Expand All @@ -29,6 +28,11 @@ const isBreakpoint = (
): breakpoint is keyof typeof breakpointViewports =>
breakpoint in breakpointViewports;

const toGoogleTagSize = (size: AdSize): googletag.SingleSize => {
// not using width and height here as to maintain compatibility with plain arrays
return size[0] === 0 && size[1] === 0 ? 'fluid' : [size[0], size[1]];
};

/**
* Builds a googletag size mapping based on the breakpoints and ad sizes from
* the size mapping in commercial-core and the viewport sizes from source-foundations.
Expand Down
35 changes: 4 additions & 31 deletions src/init/consented/prepare-googletag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,11 @@ import { getConsentFor, loadScript, onConsent } from '@guardian/libs';
import type * as AdSizesType from '../../core/ad-sizes';
import { loadAdvert } from '../../display/load-advert';
import { commercialFeatures } from '../../lib/commercial-features';
import _config from '../../lib/config';
import { getCurrentBreakpoint as getCurrentBreakpoint_ } from '../../lib/detect/detect-breakpoint';
import { dfpEnv } from '../../lib/dfp/dfp-env';
import { init as prepareGoogletag } from './prepare-googletag';
import { fillStaticAdvertSlots } from './static-ad-slots';

const config = _config as {
get: (k: string) => string;
set: (
k: string,
v:
| boolean
| string
| Record<string, never>
| {
adUnit: string;
contentType: string;
edition: string;
isFront: boolean;
keywordIds: string;
pageId: string;
section: string;
seriesId: string;
sharedAdTargeting: {
ct: string;
edition: string;
k: string[];
se: string[];
};
},
) => void;
};

const getAdverts = (withEmpty: boolean) => {
return [...dfpEnv.adverts.values()].map((advert) => {
// Do not return empty slots unless explicitly requested
Expand Down Expand Up @@ -270,10 +242,11 @@ describe('DFP', () => {
} = {} as const;

beforeEach(() => {
config.set('page', {
// @ts-expect-error -- test
window.guardian.config.page = {
adUnit: '/123456/theguardian.com/front',
contentType: 'Article',
edition: 'us',
edition: 'US',
isFront: true,
keywordIds: 'world/korea,world/ukraine',
pageId: 'world/uk',
Expand All @@ -285,7 +258,7 @@ describe('DFP', () => {
k: ['korea', 'ukraine'],
se: ['happy-times'],
},
});
};

document.body.innerHTML = domSnippet;

Expand Down
2 changes: 0 additions & 2 deletions src/insert/spacefinder/article.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ jest.mock('insert/spacefinder/space-filler', () => ({
},
}));

jest.mock('lib/config', () => ({ page: {}, get: () => false }));

jest.mock('experiments/ab', () => ({
isUserInVariant: () => false,
}));
Expand Down
21 changes: 0 additions & 21 deletions src/lib/config.d.ts

This file was deleted.

86 changes: 0 additions & 86 deletions src/lib/config.js

This file was deleted.

65 changes: 0 additions & 65 deletions src/lib/cookies.js

This file was deleted.

6 changes: 4 additions & 2 deletions src/lib/header-bidding/a9/a9.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flatten } from 'lodash-es';
import type { Advert } from '../../../define/Advert';
import type { A9AdUnitInterface } from '../../../types/global';
import { noop } from '../../../utils/noop';
import { reportError } from '../../../utils/report-error';
import type { HeaderBiddingSlot, SlotFlatMap } from '../prebid-types';
import { getHeaderBiddingAdSlots } from '../slot-config';

Expand Down Expand Up @@ -82,7 +82,9 @@ const requestBids = async (
});
}),
)
.catch(noop);
.catch(() => {
reportError(new Error('a9 header bidding error'), 'commercial');
});

return requestQueue;
};
Expand Down
4 changes: 0 additions & 4 deletions src/lib/header-bidding/prebid/appnexus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ jest.mock('experiments/ab', () => ({
isUserInVariant: jest.fn(),
}));

jest.mock('lib/cookies', () => ({
getCookie: jest.fn(),
}));

const resetConfig = () => {
window.guardian.ophan = {
pageViewId: 'pvid',
Expand Down
Loading

0 comments on commit 5a6366b

Please sign in to comment.