Skip to content

Commit d690438

Browse files
committed
Load the decoupled prebid shim in the APS renderer browser spec
The APS adapter spec loads the external Prebid bundle and assumed it carries the tsjs shim (and the trustedServer adapter) inside it. Once the shim is decoupled (PR #967) the external bundle is pure Prebid.js, no adapter ever registers, and the in-page auction times out. Detect the decoupled world through the window.__tsjs_prebid_bundle manifest stamp and load dist/tsjs-prebid.js after the external bundle, matching the script order the server actually serves. On a coupled bundle the stamp is absent and the spec behaves exactly as before.
1 parent eecb646 commit d690438

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

crates/trusted-server-integration-tests/browser/tests/shared/aps-renderer.spec.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFileSync } from "node:fs";
22
import { resolve } from "node:path";
3-
import { expect, test } from "@playwright/test";
3+
import { expect, test, type Page } from "@playwright/test";
44
import { runtimeUrl } from "../../helpers/state.js";
55

66
const RUNNER_URL = "https://client.aps.amazon-adsystem.com/prebid-creative.js";
@@ -18,9 +18,34 @@ function clientAuctionBundlePaths() {
1818
return {
1919
gpt: resolve(TSJS_CRATE, "dist/tsjs-gpt.js"),
2020
prebid: resolve(TSJS_CRATE, "dist/prebid", manifest.filename),
21+
shim: resolve(TSJS_CRATE, "dist/tsjs-prebid.js"),
2122
};
2223
}
2324

25+
/**
26+
* Load the client auction scripts in the order the server serves them.
27+
*
28+
* A coupled external bundle ships Prebid.js with the tsjs shim (and the
29+
* trustedServer adapter) already installed. A decoupled external bundle is
30+
* pure Prebid.js and stamps its manifest on `window.__tsjs_prebid_bundle`;
31+
* the shim then arrives as the separately served deferred tsjs module, so
32+
* this helper loads it whenever the stamp is present.
33+
*/
34+
async function loadClientAuctionBundles(page: Page): Promise<void> {
35+
const bundles = clientAuctionBundlePaths();
36+
await page.addScriptTag({ path: bundles.gpt });
37+
await page.addScriptTag({ path: bundles.prebid });
38+
const decoupledBundle = await page.evaluate(() =>
39+
Boolean(
40+
(window as unknown as { __tsjs_prebid_bundle?: unknown })
41+
.__tsjs_prebid_bundle,
42+
),
43+
);
44+
if (decoupledBundle) {
45+
await page.addScriptTag({ path: bundles.shim });
46+
}
47+
}
48+
2449
function descriptor(
2550
tagType: "iframe" | "script",
2651
creativeUrl = tagType === "iframe"
@@ -210,9 +235,7 @@ test.describe("APS opaque renderer", () => {
210235
});
211236

212237
await page.goto(runtimeUrl("/aps-prebid-adapter-test"));
213-
const bundles = clientAuctionBundlePaths();
214-
await page.addScriptTag({ path: bundles.gpt });
215-
await page.addScriptTag({ path: bundles.prebid });
238+
await loadClientAuctionBundles(page);
216239

217240
const result = await page.evaluate(async () => {
218241
type PrebidBid = {

0 commit comments

Comments
 (0)