-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace karma with playwright
- Loading branch information
Showing
15 changed files
with
214 additions
and
217 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...b/utils/devServer/assets/css-font-img.css → ...src/tests/docload/assets/css-font-img.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
body { | ||
background-image: 'splunk-black.png'; | ||
font-family: splunkerz; | ||
} | ||
|
||
@font-face { | ||
font-family: splunkerz; | ||
src: url(splunk.woff); | ||
src: url('splunk.woff'); | ||
} |
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
137 changes: 137 additions & 0 deletions
137
packages/integration-tests/src/tests/docload/docload.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** | ||
* | ||
* Copyright 2024 Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { expect } from '@playwright/test' | ||
import { test } from '../../utils/test' | ||
import { timesMakeSense } from '../../utils/time-make-sense' | ||
|
||
test.describe('docload', () => { | ||
test('resources before load event are correctly captured', async ({ recordPage }) => { | ||
await recordPage.goTo('/docload/docload-all.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'documentLoad').length === 1) | ||
const docLoadSpans = recordPage.receivedSpans.filter((span) => span.name === 'documentLoad') | ||
|
||
expect(docLoadSpans).toHaveLength(1) | ||
|
||
const resources = ['css-font-img.css', 'splunk-black.png?delay=300', 'iframe.ejs', 'splunk.woff'] | ||
for (const urlEnd of resources) { | ||
const resourceSpans = recordPage.receivedSpans.filter( | ||
(span) => span.tags['http.url'] && (span.tags['http.url'] as string).endsWith(urlEnd), | ||
) | ||
|
||
expect(docLoadSpans[0].traceId, `${urlEnd} has correct traceId`).toBe(resourceSpans[0].traceId) | ||
} | ||
|
||
const ignoredResources = ['/some-data', '/some-data?delay=1', '/api/v2/spans'] | ||
for (const urlEnd of ignoredResources) { | ||
const resourceSpans = recordPage.receivedSpans.filter( | ||
(span) => | ||
span.tags['component'] === 'document-load' && | ||
typeof span.tags['http.url'] === 'string' && | ||
span.tags['http.url'].endsWith(urlEnd), | ||
) | ||
|
||
expect(resourceSpans, `${urlEnd} is not captured`).toHaveLength(0) | ||
} | ||
}) | ||
|
||
test('documentFetch, resourceFetch, and documentLoad spans', async ({ recordPage }) => { | ||
await recordPage.goTo('/docload/docload.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'documentLoad').length === 1) | ||
const docLoadSpans = recordPage.receivedSpans.filter((span) => span.name === 'documentLoad') | ||
const docFetchSpans = recordPage.receivedSpans.filter((span) => span.name === 'documentFetch') | ||
const scriptFetchSpans = recordPage.receivedSpans.filter( | ||
(span) => | ||
span.name === 'resourceFetch' && | ||
typeof span.tags['http.url'] === 'string' && | ||
span.tags['http.url'].includes('splunk-otel-web.js'), | ||
) | ||
const brokenImageFetchSpans = recordPage.receivedSpans.filter( | ||
(span) => | ||
span.name === 'resourceFetch' && | ||
typeof span.tags['http.url'] === 'string' && | ||
span.tags['http.url'].includes('/nosuchimage.jpg'), | ||
) | ||
|
||
expect(docFetchSpans).toHaveLength(1) | ||
expect(docLoadSpans).toHaveLength(1) | ||
expect(docLoadSpans[0].traceId.match(/[a-f0-9]+/), 'Checking sanity of traceId').toBeTruthy() | ||
expect(docLoadSpans[0].id.match(/[a-f0-9]+/), 'Checking sanity of id').toBeTruthy() | ||
expect(docFetchSpans[0].traceId).toBe(docLoadSpans[0].traceId) | ||
expect(docFetchSpans[0].parentId).toBe(docLoadSpans[0].id) | ||
|
||
expect(scriptFetchSpans).toHaveLength(1) | ||
expect(scriptFetchSpans[0].traceId).toBe(docLoadSpans[0].traceId) | ||
expect(scriptFetchSpans[0].parentId).toBe(docLoadSpans[0].id) | ||
expect(scriptFetchSpans[0].tags['component']).toBe('document-load') | ||
|
||
expect(brokenImageFetchSpans.length).toBeGreaterThanOrEqual(1) | ||
expect(brokenImageFetchSpans[0].traceId).toBe(docLoadSpans[0].traceId) | ||
expect(brokenImageFetchSpans[0].parentId).toBe(docLoadSpans[0].id) | ||
|
||
expect(docFetchSpans[0].tags['component']).toBe('document-load') | ||
expect(docLoadSpans[0].tags['location.href']).toBe('http://localhost:3000/docload/docload.ejs') | ||
|
||
timesMakeSense(docFetchSpans[0].annotations, 'domainLookupStart', 'domainLookupEnd') | ||
timesMakeSense(docFetchSpans[0].annotations, 'connectStart', 'connectEnd') | ||
timesMakeSense(docFetchSpans[0].annotations, 'requestStart', 'responseStart') | ||
timesMakeSense(docFetchSpans[0].annotations, 'responseStart', 'responseEnd') | ||
timesMakeSense(docFetchSpans[0].annotations, 'fetchStart', 'responseEnd') | ||
|
||
expect(docFetchSpans[0].tags['link.traceId']).toBeDefined() | ||
expect(docFetchSpans[0].tags['link.spanId']).toBeDefined() | ||
expect(parseInt(scriptFetchSpans[0].tags['http.response_content_length'] as string)).toBeGreaterThan(0) | ||
|
||
expect(docLoadSpans[0].tags['component']).toBe('document-load') | ||
expect(docLoadSpans[0].tags['location.href']).toBe('http://localhost:3000/docload/docload.ejs') | ||
expect( | ||
(docLoadSpans[0].tags['screen.xy'] as string).match(/[0-9]+x[0-9]+/), | ||
'Checking sanity of screen.xy', | ||
).toBeTruthy() | ||
|
||
timesMakeSense(docLoadSpans[0].annotations, 'domContentLoadedEventStart', 'domContentLoadedEventEnd') | ||
timesMakeSense(docLoadSpans[0].annotations, 'loadEventStart', 'loadEventEnd') | ||
timesMakeSense(docLoadSpans[0].annotations, 'fetchStart', 'domInteractive') | ||
timesMakeSense(docLoadSpans[0].annotations, 'fetchStart', 'domComplete') | ||
|
||
expect(recordPage.receivedErrorSpans).toHaveLength(0) | ||
}) | ||
|
||
test('ignoring resource URLs', async ({ recordPage }) => { | ||
await recordPage.goTo('/docload/docload-ignored.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'documentFetch').length === 1) | ||
const ignoredResourceFetchSpans = recordPage.receivedSpans.filter( | ||
(span) => span.tags['http.url'] === 'http://localhost:3000/non-impactful-resource.jpg', | ||
) | ||
|
||
expect(ignoredResourceFetchSpans).toHaveLength(0) | ||
}) | ||
|
||
test('module can be disabled', async ({ recordPage }) => { | ||
await recordPage.goTo('/docload/docload.ejs?disableInstrumentation=document') | ||
|
||
await recordPage.waitForTimeoutAndFlushData(1000) | ||
const SPAN_TYPES = ['documentFetch', 'documentLoad', 'resourceFetch'] | ||
const documentSpans = recordPage.receivedSpans.filter((span) => SPAN_TYPES.includes(span.name)) | ||
|
||
expect(documentSpans).toHaveLength(0) | ||
expect(recordPage.receivedErrorSpans).toHaveLength(0) | ||
}) | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* | ||
* Copyright 2024 Splunk Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { expect } from '@playwright/test' | ||
|
||
export const timesMakeSense = ( | ||
annotations: Array<{ timestamp: number; value: string }>, | ||
startName: string, | ||
endName: string, | ||
) => { | ||
const annotationsObject: Record<string, number> = {} | ||
annotations.forEach((event) => { | ||
annotationsObject[event.value] = event.timestamp | ||
}) | ||
|
||
expect(annotationsObject[startName]).toBeTruthy() | ||
expect(annotationsObject[endName]).toBeTruthy() | ||
|
||
expect(annotationsObject[startName]).toBeLessThanOrEqual(annotationsObject[endName]) | ||
|
||
const diff = annotationsObject[endName] - annotationsObject[startName] | ||
const fiveMinutes = 5 * 60 * 1000 * 1000 | ||
|
||
// Sanity check for time difference | ||
expect(diff).toBeLessThanOrEqual(fiveMinutes) | ||
|
||
// Also looking for rough synchronization with reality (at least from our CI systems/laptops...) | ||
const nowMicros = new Date().getTime() * 1000 | ||
let clockSkew = annotationsObject[startName] - nowMicros | ||
if (clockSkew < 0) { | ||
clockSkew = -clockSkew | ||
} | ||
|
||
// Sanity check for clock skew | ||
expect(clockSkew).toBeLessThanOrEqual(fiveMinutes) | ||
} |
Oops, something went wrong.