Skip to content

Commit

Permalink
add tests for createQueryHistoryRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseykulikov committed Oct 14, 2023
1 parent f426d90 commit e6f2b9a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// usage: yarn ava test/index.js
// usage: CRUX_KEY='...' yarn ava test/index.js

import test from 'ava'
import fetch from 'node-fetch'
import { createQueryRecord, normalizeUrl } from '../src/index.js'
import { createQueryRecord, createQueryHistoryRecord, normalizeUrl } from '../src/index.js'

const key = process.env.CRUX_KEY || 'no-key'

Expand All @@ -18,6 +18,17 @@ test('createQueryRecord', async (t) => {
t.is(json2?.record.key.effectiveConnectionType, '3G')
})

test('createQueryHistoryRecord', async (t) => {
const queryHistory = createQueryHistoryRecord({ key, fetch })
const json1 = await queryHistory({ url: 'https://github.com/', formFactor: 'DESKTOP' })

t.is(json1?.record.key.url, 'https://github.com/')
t.is(json1?.record.key.formFactor, 'DESKTOP')
t.is(json1?.record.collectionPeriods.length, 25)
t.is(json1?.record.metrics.cumulative_layout_shift?.histogramTimeseries.length, 3)
t.is(json1?.record.metrics.cumulative_layout_shift?.histogramTimeseries[0]?.densities.length, 25)
})

test('normalizeUrl', async (t) => {
const queryRecord = createQueryRecord({ key, fetch })
const urls = [
Expand Down

0 comments on commit e6f2b9a

Please sign in to comment.