-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathbase.test.ts
More file actions
57 lines (47 loc) · 1.89 KB
/
base.test.ts
File metadata and controls
57 lines (47 loc) · 1.89 KB
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
import { launchBrowser, type LaunchContext, MOCK_HOST, MOCK_URL, MOCK_URL_2, sleep } from "../common/base"
import { readRecordsOfFirstPage } from "../common/record"
import { createWhitelist } from "../common/whitelist"
let context: LaunchContext
describe('Tracking', () => {
beforeEach(async () => context = await launchBrowser())
afterEach(() => context.close())
test('basic tracking', async () => {
const page = await context.newPageAndWaitCsInjected(MOCK_URL)
await sleep(2)
let records = await readRecordsOfFirstPage(context)
expect(records.length).toEqual(1)
const { visit: visitStr, time: timeStr } = records[0]
// 1 visit
expect(visitStr).toEqual("1")
// >= 2 s
const time = parseInt(timeStr.replace('s', '').trim())
expect(time >= 2)
// Another page
await page.bringToFront()
await page.goto(MOCK_URL_2)
records = await readRecordsOfFirstPage(context)
expect(records.length).toEqual(2)
const urls = records.map(r => r.url)
expect(urls.includes(MOCK_HOST))
}, 60000)
test('white list', async () => {
const page = await context.newPageAndWaitCsInjected(MOCK_URL)
await sleep(2)
let records = await readRecordsOfFirstPage(context)
expect(records.length).toEqual(1)
const { visit: visitStr, time: timeStr } = records[0]
// 1 visit
expect(visitStr).toEqual("1")
// >= 2 s
const time = parseInt(timeStr.replace('s', '').trim())
expect(time >= 2)
await createWhitelist(context, MOCK_HOST)
await page.bringToFront()
await page.reload()
await sleep(2)
records = await readRecordsOfFirstPage(context)
expect(records.length).toEqual(1)
expect(records[0].time).toEqual(timeStr)
expect(records[0].visit).toEqual("1")
}, 60000)
})