Skip to content

Commit

Permalink
chore: replace karma with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
Joozty committed Dec 11, 2024
1 parent ee68f4b commit 3ac6e5a
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 100 deletions.
48 changes: 19 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"server": "run-p server:*",
"server:same-origin": "PORT=3000 tsx src/server/server.ts",
"server:cross-origin": "PORT=3001 tsx src/server/server.ts",
"server:socketio": "PORT=3002 tsx src/server/server-socketio.ts",
"test": "npx playwright test",
"compile": "exit 0;"
},
Expand All @@ -30,6 +31,7 @@
"@fastify/websocket": "^11.0.1",
"npm-run-all": "^4.1.5",
"pino-pretty": "^13.0.0",
"socket.io": "^4.8.1",
"tsx": "^4.19.2"
}
}
37 changes: 37 additions & 0 deletions packages/integration-tests/src/server/server-socketio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
*
* 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 { createServer } from 'http'
import { Server } from 'socket.io'

const httpServer = createServer()
const io = new Server(httpServer, {
cors: {
origin: true,
},
})

io.on('connection', (socket) => {
socket.on('hello', () => {})
socket.on('ping', (...args) => {
socket.emit('pong', ...args)
})
})

const PORT = Number.parseInt(process.env.PORT || '3002')

httpServer.listen(PORT)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>Socket.io</title>

<script src="/socket.io/socket.io.js"></script>
<script src="https://www.unpkg.com/socket.io[email protected]/dist/socket.io.min.js"></script>
<%- renderAgent({instrumentations: {socketio: true}}) %>
</head>
<body>
Expand All @@ -13,9 +13,9 @@
<button id="sendHello" type="button">Send</button>
<button id="sendPing" type="button">Ping</button>
<script>
var socket;
let socket;
connectSocket.addEventListener('click', function () {
socket = io();
socket = io("ws://localhost:3002/");
socket.on('pong', function () {
window.testing = false;
console.log('Pong!');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<button id="connectSocket" type="button">Connect to a socket.io server</button>
<button id="sendHello" type="button">Send</button>
<button id="sendPing" type="button">Ping</button>
<script src="/socket.io/socket.io.js"></script>
<script src="https://www.unpkg.com/socket.io[email protected]/dist/socket.io.min.js"></script>
<script>
var socket;
let socket;
connectSocket.addEventListener('click', function () {
socket = io();
socket = io("ws://localhost:3002/");
socket.on('pong', function () {
window.testing = false;
console.log('Pong!');
Expand Down
51 changes: 51 additions & 0 deletions packages/integration-tests/src/tests/socketio/socketio.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
*
* 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 { test } from '../../utils/test'
import { expect } from '@playwright/test'

test.describe('socketio', () => {
test('produces correct connect span', async ({ recordPage }) => {
await recordPage.goTo('/socketio/socketio.ejs')
await recordPage.locator('#connectSocket').click()
await recordPage.locator('#sendHello').click()
await recordPage.locator('#sendPing').click()

await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'pong receive').length > 0)
const socketioSpans = recordPage.receivedSpans.filter((span) => span.tags['messaging.system'] === 'socket.io')

expect(socketioSpans).toHaveLength(3)
expect(socketioSpans[0].name).toBe('hello send')
expect(socketioSpans[1].name).toBe('ping send')
expect(socketioSpans[2].name).toBe('pong receive')
})

test.only('produces correct connect span (socket.io already on page)', async ({ recordPage }) => {
await recordPage.goTo('/socketio/socketio.before.ejs')
await recordPage.locator('#connectSocket').click()
await recordPage.locator('#sendHello').click()
await recordPage.locator('#sendPing').click()

await recordPage.waitForSpans((spans) => spans.filter((span) => span.name === 'pong receive').length > 0)
const socketioSpans = recordPage.receivedSpans.filter((span) => span.tags['messaging.system'] === 'socket.io')

expect(socketioSpans).toHaveLength(3)
expect(socketioSpans[0].name).toBe('hello send')
expect(socketioSpans[1].name).toBe('ping send')
expect(socketioSpans[2].name).toBe('pong receive')
})
})
65 changes: 0 additions & 65 deletions packages/web/integration-tests/tests/socketio/socketio.spec.js

This file was deleted.

0 comments on commit 3ac6e5a

Please sign in to comment.