Skip to content

Commit 87bcc0c

Browse files
committed
Fixing tests so they can run in both NodeJS and browsers
1 parent 131efda commit 87bcc0c

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

test/basic.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ import common from './common.js'
22
import Peer from '../index.js'
33
import { test, expect } from 'vitest'
44

5-
// Handle uncaught exceptions in both Node.js and browser
6-
if (typeof process !== 'undefined' && process.on) {
7-
process.on('uncaughtException', console.error) // User-Initiated Abort, reason=Close called
8-
} else if (typeof window !== 'undefined') {
9-
window.addEventListener('error', (event) => console.error(event.error))
10-
}
11-
125
test('detect WebRTC support', function () {
136
expect(Peer.WEBRTC_SUPPORT).toBe(true)
147
})

test/stream.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ import Peer from '../index.js'
22
import str from 'string-to-stream'
33
import { test, expect } from 'vitest'
44

5-
// Handle uncaught exceptions in both Node.js and browser
6-
if (typeof process !== 'undefined' && process.on) {
7-
process.on('uncaughtException', console.error) // User-Initiated Abort, reason=Close called
8-
} else if (typeof window !== 'undefined') {
9-
window.addEventListener('error', (event) => console.error(event.error))
10-
}
11-
125
test('duplex stream: send data one-way', { timeout: 20000 }, function () {
136
return new Promise<void>((resolve) => {
147
const peer1 = new Peer({ initiator: true })
@@ -17,6 +10,8 @@ test('duplex stream: send data one-way', { timeout: 20000 }, function () {
1710
peer2.on('signal', function (data) { peer1.signal(data) })
1811
peer1.on('connect', tryTest)
1912
peer2.on('connect', tryTest)
13+
peer1.on('error', function (err) { console.error(err) })
14+
peer2.on('error', function (err) { console.error(err) })
2015

2116
function tryTest () {
2217
if (!peer1.connected || !peer2.connected) return

vitest.browser.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export default defineConfig({
3131
instances: [
3232
// Default to chromium, but can be overridden with --browser.name flag
3333
// Supported browsers: chromium, firefox, webkit
34-
{ browser: 'chromium', provider: playwright() }
34+
{ browser: 'chromium', provider: playwright() },
35+
{ browser: 'firefox', provider: playwright() },
36+
{ browser: 'webkit', provider: playwright() },
3537
],
3638
headless: true
3739
}

0 commit comments

Comments
 (0)