import { test, expect } from '@playwright/test' import { detect } from '../support/installation-support-playwright-wrappers' import { initializePageDynamically } from '../support/initialize-page-dynamically' test.describe('detector.js (tech recognition)', () => { test('skips v1 snippet detection by default', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, response: /* HTML */ ` ` }) const result = await detect(page, { url: url, detectV1: false, timeoutMs: 1000 }) expect(result.data.v1Detected).toBe(null) }) test('detects WP plugin, WP and GTM', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, response: /* HTML */ ` ` }) const result = await detect(page, { url: url, detectV1: false, timeoutMs: 1000 }) expect(result.data.wordpressPlugin).toBe(true) expect(result.data.wordpressLikely).toBe(true) expect(result.data.gtmLikely).toBe(true) }) test('No WP plugin, WP or GTM', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, response: /* HTML */ ` ` }) const result = await detect(page, { url: url, detectV1: false, timeoutMs: 1000 }) expect(result.data.wordpressPlugin).toBe(false) expect(result.data.wordpressLikely).toBe(false) expect(result.data.gtmLikely).toBe(false) expect(result.data.npm).toBe(false) }) test('npm is reported correctly', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, scriptConfig: /* HTML */ `` }) const result = await detect(page, { url: url, detectV1: false }) expect(result.data.wordpressPlugin).toBe(false) expect(result.data.wordpressLikely).toBe(false) expect(result.data.gtmLikely).toBe(false) expect(result.data.npm).toBe(true) }) }) test.describe('detector.js (v1 detection)', () => { test('v1Detected is true when v1 plausible exists + detects WP plugin, WP and GTM', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, response: /* HTML */ ` ` }) const result = await detect(page, { url: url, detectV1: true, timeoutMs: 1000 }) expect(result.data.v1Detected).toBe(true) expect(result.data.wordpressPlugin).toBe(true) expect(result.data.wordpressLikely).toBe(true) expect(result.data.gtmLikely).toBe(true) expect(result.data.npm).toBe(false) }) test('v1Detected is false when plausible function does not exist', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, response: /* HTML */ ` ` }) const result = await detect(page, { url: url, detectV1: true, timeoutMs: 1000 }) expect(result.data.v1Detected).toBe(false) expect(result.data.wordpressPlugin).toBe(false) expect(result.data.wordpressLikely).toBe(false) expect(result.data.gtmLikely).toBe(false) expect(result.data.npm).toBe(false) }) test('v1Detected is false when v2 plausible installed', async ({ page }, { testId }) => { const { url } = await initializePageDynamically(page, { testId, scriptConfig: { domain: 'abc.de', captureOnLocalhost: false } }) const result = await detect(page, { url: url, detectV1: true, timeoutMs: 1000 }) expect(result.data.v1Detected).toBe(false) }) })