From 7b5401f95e42ec66d6094e2a027767cccb57c7e7 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 6 Jun 2024 16:31:33 +0100 Subject: [PATCH] fix: import and throw DOMException correctly The `node-domexception` module polyfills the global environment with the DOMExecption constructor but it doesn't export anything, so use a bare import to perform the polyfill then use the global constructor. Adds a test to prevent regressions. --- polyfill/RTCPeerConnection.js | 8 ++------ test/jest-tests/polyfill.test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 test/jest-tests/polyfill.test.js diff --git a/polyfill/RTCPeerConnection.js b/polyfill/RTCPeerConnection.js index be9913b..763cdd4 100644 --- a/polyfill/RTCPeerConnection.js +++ b/polyfill/RTCPeerConnection.js @@ -4,11 +4,11 @@ import RTCDataChannel from './RTCDataChannel.js'; import RTCIceCandidate from './RTCIceCandidate.js'; import { RTCDataChannelEvent, RTCPeerConnectionIceEvent } from './Events.js'; import RTCSctpTransport from './RTCSctpTransport.js'; -import DOMException from 'node-domexception'; +import 'node-domexception'; export default class _RTCPeerConnection extends EventTarget { static async generateCertificate() { - throw new Error('Not implemented'); + throw new DOMException('Not implemented'); } #peerConnection; @@ -192,10 +192,6 @@ export default class _RTCPeerConnection extends EventTarget { return this.#peerConnection.signalingState(); } - static generateCertificate(keygenAlgorithm) { - throw new DOMException('Not implemented'); - } - async addIceCandidate(candidate) { if (candidate == null || candidate.candidate == null) { throw new DOMException('Candidate invalid'); diff --git a/test/jest-tests/polyfill.test.js b/test/jest-tests/polyfill.test.js new file mode 100644 index 0000000..5873a0a --- /dev/null +++ b/test/jest-tests/polyfill.test.js @@ -0,0 +1,10 @@ +import { expect } from '@jest/globals'; +import polyfill from '../../polyfill/index.js'; + +describe('polyfill', () => { + test('generateCertificate should throw', () => { + expect(async () => { + await polyfill.RTCPeerConnection.generateCertificate({}); + }).rejects.toEqual(new DOMException('Not implemented')); + }); +});