Skip to content

Commit 0a3d39b

Browse files
committed
test: fix unit test config passing
1 parent 363da49 commit 0a3d39b

File tree

6 files changed

+34
-40
lines changed

6 files changed

+34
-40
lines changed

injected/entry-points/chrome.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @module Chrome integration
33
*/
4-
import { isTrackerOrigin } from '../src/trackers';
54
import { computeLimitedSiteObject } from '../src/utils';
65

76
/**
@@ -39,8 +38,6 @@ function randomString() {
3938
}
4039

4140
function init() {
42-
const trackerLookup = import.meta.trackerLookup;
43-
const documentOriginIsTracker = isTrackerOrigin(trackerLookup);
4441
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
4542
const bundledConfig = $BUNDLED_CONFIG$;
4643
const randomMethodName = '_d' + randomString();

injected/src/config-feature.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ export default class ConfigFeature {
1313

1414
/**
1515
* @param {any} name
16+
* @param {import('./content-scope-features.js').LoadArgs} args
1617
*/
17-
constructor(name) {
18+
constructor(name, args) {
1819
this.name = name;
20+
const { bundledConfig, site, platform } = args;
21+
this.#bundledConfig = bundledConfig;
22+
this.#args = args;
23+
// If we have a bundled config, treat it as a regular config
24+
// This will be overriden by the remote config if it is available
25+
if (this.#bundledConfig && this.#args) {
26+
const enabledFeatures = computeEnabledFeatures(bundledConfig, site.domain, platform.version);
27+
this.#args.featureSettings = parseFeatureSettings(bundledConfig, enabledFeatures);
28+
}
1929
}
2030

2131
get args() {
@@ -30,21 +40,6 @@ export default class ConfigFeature {
3040
return this.#args?.featureSettings;
3141
}
3242

33-
/**
34-
* @param {import('./content-scope-features.js').LoadArgs} loadArgs
35-
*/
36-
initLoadArgs(loadArgs) {
37-
const { bundledConfig, site, platform } = loadArgs;
38-
this.#bundledConfig = bundledConfig;
39-
this.#args = loadArgs;
40-
// If we have a bundled config, treat it as a regular config
41-
// This will be overriden by the remote config if it is available
42-
if (this.#bundledConfig && this.#args) {
43-
const enabledFeatures = computeEnabledFeatures(bundledConfig, site.domain, platform.version);
44-
this.#args.featureSettings = parseFeatureSettings(bundledConfig, enabledFeatures);
45-
}
46-
}
47-
4843
/**
4944
* Given a config key, interpret the value as a list of domain overrides, and return the elements that match the current page
5045
* Consider using patchSettings instead as per `getFeatureSetting`.
@@ -161,4 +156,4 @@ export default class ConfigFeature {
161156
get bundledConfig() {
162157
return this.#bundledConfig;
163158
}
164-
}
159+
}

injected/src/content-feature.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ export default class ContentFeature extends ConfigFeature {
3333
/** @type {ImportMeta} */
3434
#importConfig;
3535

36-
constructor(featureName, importConfig) {
37-
super(featureName);
38-
this.args = null;
36+
constructor(featureName, importConfig, args) {
37+
super(featureName, args);
3938
this.monitor = new PerformanceMonitor();
4039
this.#importConfig = importConfig;
4140
}
@@ -141,8 +140,6 @@ export default class ContentFeature extends ConfigFeature {
141140

142141
callInit(args) {
143142
const mark = this.monitor.mark(this.name + 'CallInit');
144-
this.args = args;
145-
this.platform = args.platform;
146143
this.init(args);
147144
mark.end();
148145
this.measure();
@@ -189,15 +186,15 @@ export default class ContentFeature extends ConfigFeature {
189186
return this.messaging.subscribe(name, cb);
190187
}
191188

192-
/**
193-
* @param {import('./content-scope-features.js').LoadArgs} args
194-
*/
195-
callLoad(args) {
196-
const mark = this.monitor.mark(this.name + 'CallLoad');
189+
setArgs(args) {
197190
this.args = args;
198191
this.platform = args.platform;
199-
this.initLoadArgs(args);
200-
this.load(args);
192+
}
193+
194+
callLoad() {
195+
const mark = this.monitor.mark(this.name + 'CallLoad');
196+
this.setArgs(this.args);
197+
this.load(this.args);
201198
mark.end();
202199
}
203200

injected/src/content-scope-features.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export function load(args) {
4545

4646
for (const featureName of featureNames) {
4747
const ContentFeature = platformFeatures['ddg_feature_' + featureName];
48-
const featureInstance = new ContentFeature(featureName, importConfig);
49-
featureInstance.callLoad(args);
48+
const featureInstance = new ContentFeature(featureName, importConfig, args);
49+
featureInstance.callLoad();
5050
features.push({ featureName, featureInstance });
5151
}
5252
mark.end();

injected/src/globals.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ declare module '*.riv' {
4444
}
4545

4646
declare module 'ddg:platformFeatures' {
47-
const output: Record<string, new (featureName: string, importConfig: ImportConfig) => import('./content-feature').default>;
47+
const output: Record<
48+
string,
49+
new (featureName: string, importConfig: ImportConfig, args: LoadArgs) => import('./content-feature').default
50+
>;
4851
export default output;
4952
}

injected/unit-test/content-feature.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ describe('ContentFeature class', () => {
1212
didRun = true;
1313
}
1414
}
15-
const me = new MyTestFeature('test');
16-
me.callInit({
15+
16+
const args = {
1717
site: {
1818
domain: 'beep.example.com',
1919
},
@@ -42,7 +42,9 @@ describe('ContentFeature class', () => {
4242
],
4343
},
4444
},
45-
});
45+
};
46+
const me = new MyTestFeature('test', {}, args);
47+
me.callInit(args);
4648
expect(didRun).withContext('Should run').toBeTrue();
4749
});
4850

@@ -56,7 +58,7 @@ describe('ContentFeature class', () => {
5658
}
5759
let feature;
5860
beforeEach(() => {
59-
feature = new MyTestFeature('someFeatureName');
61+
feature = new MyTestFeature('someFeatureName', {}, {});
6062
});
6163

6264
it('should not send duplicate flags', () => {
@@ -85,7 +87,7 @@ describe('ContentFeature class', () => {
8587
}
8688
let feature;
8789
beforeEach(() => {
88-
feature = new MyTestFeature('someFeatureName');
90+
feature = new MyTestFeature('someFeatureName', {}, {});
8991
});
9092

9193
it('should add debug flag to value descriptors', () => {

0 commit comments

Comments
 (0)