-
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
19 changed files
with
292 additions
and
205 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
27 changes: 27 additions & 0 deletions
27
packages/integration-tests/src/server/middlewares/delay-middleware.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,27 @@ | ||
/** | ||
* | ||
* 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 { Request, Response, NextFunction } from 'express' | ||
|
||
export const delayMiddleware = async (req: Request, res: Response, next: NextFunction) => { | ||
if (typeof req.query.delay === 'string') { | ||
const timeout = parseInt(req.query.delay) | ||
await new Promise((resolve) => setTimeout(resolve, timeout)) | ||
} | ||
|
||
next() | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/integration-tests/src/server/middlewares/index.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,20 @@ | ||
/** | ||
* | ||
* 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. | ||
* | ||
*/ | ||
export * from './delay-middleware' | ||
export * from './server-timing-middleware' | ||
export * from './no-cache-middleware' |
31 changes: 31 additions & 0 deletions
31
packages/integration-tests/src/server/middlewares/no-cache-middleware.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,31 @@ | ||
/** | ||
* | ||
* 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 { Request, Response, NextFunction } from 'express' | ||
import onHeaders from 'on-headers' | ||
|
||
export const noCacheMiddleware = (req: Request, res: Response, next: NextFunction) => { | ||
if (typeof req.query.noCache === 'string') { | ||
onHeaders(res, () => { | ||
res.setHeader('Cache-Control', 'no-store, max-age=0') | ||
res.removeHeader('Etag') | ||
res.removeHeader('Last-Modified') | ||
}) | ||
} | ||
|
||
next() | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/integration-tests/src/server/middlewares/server-timing-middleware.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,29 @@ | ||
/** | ||
* | ||
* 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 { NextFunction, Request, Response } from 'express' | ||
import { setServerTimingHeader } from '../server-timing' | ||
|
||
export const serverTimingMiddleware = (req: Request, res: Response, next: NextFunction) => { | ||
if (typeof req.query.serverTiming === 'string') { | ||
res.setHeader('Server-Timing', req.query.serverTiming) | ||
} else { | ||
setServerTimingHeader(res) | ||
} | ||
|
||
next() | ||
} |
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
File renamed without changes.
File renamed without changes.
130 changes: 130 additions & 0 deletions
130
packages/integration-tests/src/tests/resource-observer/resource-observer.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,130 @@ | ||
/** | ||
* | ||
* 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' | ||
|
||
test.describe('resource observer', () => { | ||
test('should report resource loads happening after page load', async ({ recordPage }) => { | ||
await recordPage.goTo('/resource-observer/resources.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'guard-span').length === 1) | ||
const agentSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('splunk-otel-web.js'), | ||
) | ||
const imageSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('image.png?noCache'), | ||
) | ||
const imageBlackSpans = recordPage.receivedSpans.filter( | ||
(span) => | ||
typeof span.tags['http.url'] === 'string' && | ||
span.tags['http.url'].endsWith('splunk-black.svg?delay=100'), | ||
) | ||
const scriptSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('test.js'), | ||
) | ||
|
||
expect(agentSpans).toHaveLength(1) | ||
expect(imageSpans).toHaveLength(1) | ||
|
||
expect(imageBlackSpans).toHaveLength(1) | ||
expect(imageBlackSpans[0].annotations.length).toBe(8) | ||
expect(imageBlackSpans[0].tags['http.url']).toBe( | ||
'http://localhost:3000/resource-observer/assets/splunk-black.svg?delay=100', | ||
) | ||
|
||
expect(scriptSpans).toHaveLength(1) | ||
expect(scriptSpans[0].annotations.length).toBe(8) | ||
expect(scriptSpans[0].tags['http.url']).toBe('http://localhost:3000/resource-observer/assets/test.js') | ||
}) | ||
|
||
test('resources can be ignored', async ({ recordPage }) => { | ||
await recordPage.goTo('/resource-observer/resources-ignored.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'guard-span').length === 1) | ||
const imageBlackSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('splunk-black.svg'), | ||
) | ||
const scriptSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('test.js'), | ||
) | ||
|
||
expect(imageBlackSpans).toHaveLength(0) | ||
expect(scriptSpans).toHaveLength(0) | ||
}) | ||
|
||
test('should create one span for cached resource', async ({ recordPage }) => { | ||
await recordPage.goTo('/resource-observer/resources-twice.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'guard-span').length === 1) | ||
const imageBlackSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('splunk-black.svg'), | ||
) | ||
|
||
expect(imageBlackSpans).toHaveLength(1) | ||
expect(imageBlackSpans[0].tags['component']).toBe('document-load') | ||
}) | ||
|
||
test('should create two spans for non cached resource', async ({ recordPage, browserName }) => { | ||
if (['firefox', 'webkit'].includes(browserName)) { | ||
// TODO: Investigate why this test is failing on Firefox and Webkit | ||
test.skip() | ||
} | ||
|
||
await recordPage.goTo('/resource-observer/resources-twice-no-cache.ejs') | ||
|
||
await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'guard-span').length === 1) | ||
const imageSpans = recordPage.receivedSpans.filter( | ||
(span) => typeof span.tags['http.url'] === 'string' && span.tags['http.url'].endsWith('image.png?noCache'), | ||
) | ||
|
||
expect(imageSpans).toHaveLength(2) | ||
expect(imageSpans[0].tags['component']).toBe('document-load') | ||
expect(imageSpans[1].tags['component']).toBe('splunk-post-doc-load-resource') | ||
expect(imageSpans[0].traceId).not.toBe(imageSpans[1].traceId) | ||
}) | ||
|
||
// test.only('should propagate tracing context to created spans', async ({ recordPage, browserName }) => { | ||
// await recordPage.goTo('/resource-observer/resources-custom-context.ejs') | ||
// | ||
// await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'guard-span').length === 1) | ||
// | ||
// const imageRootSpans = recordPage.receivedSpans.filter( | ||
// (span) => | ||
// typeof span.tags['http.url'] === 'string' && | ||
// span.tags['http.url'].endsWith('splunk-black.svg') && | ||
// span.tags['component'] === 'splunk-post-doc-load-resource', | ||
// ) | ||
// const imageParentSpans = recordPage.receivedSpans.filter((span) => span.name === 'image-parent') | ||
// const imageChildSpans = recordPage.receivedSpans.filter( | ||
// (span) => | ||
// typeof span.tags['http.url'] === 'string' && | ||
// span.tags['http.url'].endsWith('splunk-black.svg') && | ||
// span.tags['component'] === 'splunk-post-doc-load-resource', | ||
// ) | ||
// | ||
// expect(imageRootSpans).toHaveLength(1) | ||
// expect(imageParentSpans).toHaveLength(1) | ||
// expect(imageChildSpans).toHaveLength(1) | ||
// | ||
// expect(imageRootSpans[0].traceId).not.toBe(imageParentSpans[0].traceId) | ||
// expect(imageRootSpans[0].parentId).toBeUndefined() | ||
// | ||
// console.log(imageChildSpans[0]) | ||
// expect(imageChildSpans[0].parentId).toBe(imageParentSpans[0].id) | ||
// }) | ||
}) |
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
Oops, something went wrong.