Skip to content

Commit

Permalink
add e2e rum event validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Oct 30, 2020
1 parent 6901090 commit d457cdf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
5 changes: 3 additions & 2 deletions test/e2e/lib/framework/createTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { deleteAllCookies, withBrowserLogs } from '../helpers/browser'
import { flushEvents } from '../helpers/sdk'
import { validateFormat } from '../helpers/validation'
import { EventRegistry } from './eventsRegistry'
import { getTestServers, Servers, waitForServersIdle } from './httpServers'
import { log } from './logger'
Expand All @@ -9,13 +10,12 @@ import { createIntakeServerApp } from './serverApps/intake'
import { createMockServerApp } from './serverApps/mock'

const DEFAULT_RUM_OPTIONS = {
applicationId: 'appId',
applicationId: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
clientToken: 'token',
enableExperimentalFeatures: ['v2_format'],
}

const DEFAULT_LOGS_OPTIONS = {
applicationId: 'appId',
clientToken: 'token',
}

Expand Down Expand Up @@ -144,6 +144,7 @@ async function setUpTest({ baseUrl }: TestContext) {
async function tearDownTest({ events }: TestContext) {
await flushEvents()
expect(events.internalMonitoring).toEqual([])
validateFormat(events.rum)
await withBrowserLogs((logs) => {
logs.forEach((browserLog) => {
log(`Browser ${browserLog.source}: ${browserLog.level} ${browserLog.message}`)
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/lib/helpers/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ajv from 'ajv'
import rumEventsFormatJson from '../../../../rum-events-format/rum-events-format.json'
import _commonSchemaJson from '../../../../rum-events-format/schemas/_common-schema.json'
import actionSchemaJson from '../../../../rum-events-format/schemas/action-schema.json'
import errorSchemaJson from '../../../../rum-events-format/schemas/error-schema.json'
import long_taskSchemaJson from '../../../../rum-events-format/schemas/long_task-schema.json'
import resourceSchemaJson from '../../../../rum-events-format/schemas/resource-schema.json'
import viewSchemaJson from '../../../../rum-events-format/schemas/view-schema.json'
import { ServerRumEvent } from '../types/serverEvents'

export function validateFormat(events: ServerRumEvent[]) {
events.forEach((event) => {
const instance = new ajv({
allErrors: true,
})
instance
.addSchema(_commonSchemaJson, 'schemas/_common-schema.json')
.addSchema(viewSchemaJson, 'schemas/view-schema.json')
.addSchema(actionSchemaJson, 'schemas/action-schema.json')
.addSchema(resourceSchemaJson, 'schemas/resource-schema.json')
.addSchema(long_taskSchemaJson, 'schemas/long_task-schema.json')
.addSchema(errorSchemaJson, 'schemas/error-schema.json')
.addSchema(rumEventsFormatJson, 'rum-events-format.json')
.validate('rum-events-format.json', event)

if (instance.errors) {
instance.errors.map((error) => fail(`${error.dataPath || 'event'} ${error.message}`))
}
})
}
2 changes: 1 addition & 1 deletion test/e2e/scenario/logs.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('logs', () => {
await flushEvents()
expect(events.logs.length).toBe(1)
expect(events.logs[0].view.id).toBeDefined()
expect(events.logs[0].application_id).toBe('appId')
expect(events.logs[0].application_id).toBe('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee')
})

createTest('track fetch error')
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"strict": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"target": "es5",
"plugins": [
{
"name": "typescript-tslint-plugin"
}
],
"types": ["node", "webdriverio", "jasmine"],
"types": ["node", "webdriverio", "jasmine", "ajv"],
"paths": {
"@datadog/browser-logs": ["../../packages/logs/src"],
"@datadog/browser-rum": ["../../packages/rum/src"],
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"no-implicit-dependencies": [
true,
"dev",
["@datadog/browser-logs", "@datadog/browser-rum", "@datadog/browser-core"]
["@datadog/browser-logs", "@datadog/browser-rum", "@datadog/browser-core", "ajv"]
],
"no-null-keyword": true,
"no-submodule-imports": [true],
Expand Down

0 comments on commit d457cdf

Please sign in to comment.