File size: 2,598 Bytes
6778ee0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | import { initializePageDynamically } from './support/initialize-page-dynamically'
import { expectPlausibleInAction, switchByMode } from './support/test-utils'
import { expect, test } from '@playwright/test'
import { ScriptConfig } from './support/types'
import { LOCAL_SERVER_ADDR } from './support/server'
const DEFAULT_CONFIG: ScriptConfig = {
domain: 'example.com',
endpoint: `${LOCAL_SERVER_ADDR}/api/event`,
captureOnLocalhost: false
}
for (const mode of ['web', 'esm']) {
test.describe(`respects "logging" v2 config option (${mode})`, () => {
test('if logging is not explicitly set, it is treated as true and logs are emitted on ignored events', async ({
page
}, { testId }) => {
const config = { ...DEFAULT_CONFIG }
const consoleMessages: [string, string][] = []
page.on('console', (message) => {
consoleMessages.push([message.type(), message.text()])
})
const { url } = await initializePageDynamically(page, {
testId,
scriptConfig: switchByMode(
{
web: config,
esm: `<script type="module">import { init, track } from '/tracker/js/npm_package/plausible.js'; init(${JSON.stringify(
config
)})</script>`
},
mode
),
bodyContent: 'hello world'
})
await expectPlausibleInAction(page, {
action: () => page.goto(url),
expectedRequests: [],
refutedRequests: [{ n: 'pageview' }]
})
expect(consoleMessages).toEqual([
['warning', 'Ignoring Event: localhost']
])
})
test('if logging is explicitly set to false, logs are not emitted on ignored events', async ({
page
}, { testId }) => {
const config = { ...DEFAULT_CONFIG, logging: false }
const consoleMessages: [string, string][] = []
page.on('console', (message) => {
consoleMessages.push([message.type(), message.text()])
})
const { url } = await initializePageDynamically(page, {
testId,
scriptConfig: switchByMode(
{
web: config,
esm: `<script type="module">import { init, track } from '/tracker/js/npm_package/plausible.js'; init(${JSON.stringify(
config
)})</script>`
},
mode
),
bodyContent: 'hello world'
})
await expectPlausibleInAction(page, {
action: () => page.goto(url),
expectedRequests: [],
refutedRequests: [{ n: 'pageview' }]
})
expect(consoleMessages).toEqual([])
})
})
}
|