From d457cdf229ff6e459d4439882b8f9b46db496bf6 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Fri, 30 Oct 2020 16:45:39 +0100 Subject: [PATCH] add e2e rum event validation --- test/e2e/lib/framework/createTest.ts | 5 +++-- test/e2e/lib/helpers/validation.ts | 30 ++++++++++++++++++++++++++++ test/e2e/scenario/logs.scenario.ts | 2 +- test/e2e/tsconfig.json | 3 ++- tslint.json | 2 +- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 test/e2e/lib/helpers/validation.ts diff --git a/test/e2e/lib/framework/createTest.ts b/test/e2e/lib/framework/createTest.ts index 10b0271f3e..8cb49a7ef8 100644 --- a/test/e2e/lib/framework/createTest.ts +++ b/test/e2e/lib/framework/createTest.ts @@ -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' @@ -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', } @@ -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}`) diff --git a/test/e2e/lib/helpers/validation.ts b/test/e2e/lib/helpers/validation.ts new file mode 100644 index 0000000000..86008984ca --- /dev/null +++ b/test/e2e/lib/helpers/validation.ts @@ -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}`)) + } + }) +} diff --git a/test/e2e/scenario/logs.scenario.ts b/test/e2e/scenario/logs.scenario.ts index d48825a1d9..90f4ec977b 100644 --- a/test/e2e/scenario/logs.scenario.ts +++ b/test/e2e/scenario/logs.scenario.ts @@ -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') diff --git a/test/e2e/tsconfig.json b/test/e2e/tsconfig.json index 9ce3bec904..4ad22fba6d 100644 --- a/test/e2e/tsconfig.json +++ b/test/e2e/tsconfig.json @@ -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"], diff --git a/tslint.json b/tslint.json index 0d66adc05e..a3cbabe40e 100644 --- a/tslint.json +++ b/tslint.json @@ -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],