2026-09-01 23:41:28 +02:00
|
|
|
const { test, expect } = require("@playwright/test");
|
|
|
|
|
const {
|
|
|
|
|
CREDENTIAL_KEY,
|
|
|
|
|
createFakeBackend,
|
|
|
|
|
injectGeneratedUserscript,
|
|
|
|
|
installGmEnvironment,
|
|
|
|
|
installHermeticRoutes,
|
|
|
|
|
openNavigationFixture,
|
2026-09-06 12:51:12 +02:00
|
|
|
readGmValue,
|
2026-09-01 23:41:28 +02:00
|
|
|
} = require("./harness");
|
2026-09-06 12:51:12 +02:00
|
|
|
const { USERSCRIPT_MATRIX_RUNTIME, installNavigationMatrixFixture } = require("./navigation-matrix");
|
2026-09-01 23:41:28 +02:00
|
|
|
const {
|
2026-09-06 12:51:12 +02:00
|
|
|
createNavigationRuntimeContractAdapter,
|
|
|
|
|
registerNavigationRuntimeContractScenarios,
|
|
|
|
|
runNavigationRuntimeContract,
|
|
|
|
|
} = require("../../e2e/navigation-runtime-contract");
|
2026-09-01 23:41:28 +02:00
|
|
|
|
|
|
|
|
const EXISTING_CREDENTIALS = {
|
|
|
|
|
registrationConfirmed: true,
|
2026-09-06 12:51:12 +02:00
|
|
|
userId: "ExistingUserscriptCredential00000001",
|
2026-09-01 23:41:28 +02:00
|
|
|
};
|
2026-09-06 12:51:12 +02:00
|
|
|
registerNavigationRuntimeContractScenarios({
|
|
|
|
|
runtimeName: "userscript",
|
|
|
|
|
register: ({ scenario, title }) => {
|
|
|
|
|
test(title, async ({ context, page }) => {
|
|
|
|
|
await page.setViewportSize(scenario.viewport);
|
|
|
|
|
const consoleErrors = [];
|
|
|
|
|
const pageErrors = [];
|
|
|
|
|
page.on("console", (message) => {
|
|
|
|
|
if (message.type() === "error") consoleErrors.push(message.text());
|
|
|
|
|
});
|
|
|
|
|
page.on("pageerror", (error) => pageErrors.push(error.message));
|
2026-09-01 23:41:28 +02:00
|
|
|
|
2026-09-06 12:51:12 +02:00
|
|
|
await context.addInitScript(() => {
|
|
|
|
|
globalThis.__unhandledRejections = [];
|
|
|
|
|
addEventListener("unhandledrejection", (event) => {
|
|
|
|
|
const reason = event.reason;
|
|
|
|
|
globalThis.__unhandledRejections.push(reason instanceof Error ? reason.message : String(reason));
|
|
|
|
|
});
|
|
|
|
|
});
|
2026-09-01 23:41:28 +02:00
|
|
|
|
2026-09-06 12:51:12 +02:00
|
|
|
const backend = createFakeBackend({
|
|
|
|
|
countsByVideo: {
|
|
|
|
|
[scenario.destination.videoId]: scenario.destination.counts,
|
|
|
|
|
[scenario.origin.videoId]: scenario.origin.counts,
|
|
|
|
|
},
|
2026-09-01 23:41:28 +02:00
|
|
|
});
|
2026-09-06 12:51:12 +02:00
|
|
|
await installGmEnvironment(context, { [CREDENTIAL_KEY]: EXISTING_CREDENTIALS });
|
|
|
|
|
await installNavigationMatrixFixture(context, scenario);
|
|
|
|
|
await installHermeticRoutes(context, backend);
|
|
|
|
|
await openNavigationFixture(page, {
|
|
|
|
|
pageKind: scenario.origin.kind,
|
|
|
|
|
videoId: scenario.origin.videoId,
|
|
|
|
|
});
|
|
|
|
|
await injectGeneratedUserscript(page);
|
2026-09-01 23:41:28 +02:00
|
|
|
|
2026-09-06 12:51:12 +02:00
|
|
|
const adapter = createNavigationRuntimeContractAdapter({
|
|
|
|
|
backend,
|
|
|
|
|
expectedCredentials: EXISTING_CREDENTIALS,
|
|
|
|
|
matrixRuntime: USERSCRIPT_MATRIX_RUNTIME,
|
|
|
|
|
page,
|
|
|
|
|
readCredentials: () => readGmValue(page, CREDENTIAL_KEY),
|
|
|
|
|
readInteractionRecords: () => backend.requests,
|
|
|
|
|
runtimeName: "userscript",
|
|
|
|
|
});
|
|
|
|
|
await runNavigationRuntimeContract({
|
|
|
|
|
adapter,
|
|
|
|
|
scenario,
|
|
|
|
|
});
|
2026-09-01 23:41:28 +02:00
|
|
|
|
2026-09-06 12:51:12 +02:00
|
|
|
expect(backend.blockedRequests).toEqual([]);
|
|
|
|
|
expect(consoleErrors).toEqual([]);
|
|
|
|
|
expect(pageErrors).toEqual([]);
|
|
|
|
|
expect(await page.evaluate(() => globalThis.__unhandledRejections)).toEqual([]);
|
2026-09-01 23:41:28 +02:00
|
|
|
});
|
2026-09-06 12:51:12 +02:00
|
|
|
},
|
|
|
|
|
});
|