Skip to content

Commit 1f263ed

Browse files
Update dependency vitest to v4 [SECURITY] (#1959)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: lukasIO <mail@lukasseiler.de>
1 parent f014a58 commit 1f263ed

13 files changed

Lines changed: 169 additions & 242 deletions

eslint.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,14 @@ export default [
168168
'@typescript-eslint/prefer-nullish-coalescing': 'off',
169169
},
170170
},
171+
{
172+
// vitest v4 requires `function`/`class` (not arrow) implementations for
173+
// mocks invoked with `new` (e.g. WebSocketStream, RTCRtpScriptTransform)
174+
name: 'test/mock-constructors',
175+
files: ['**/*.test.ts'],
176+
rules: {
177+
'prefer-arrow-callback': 'off',
178+
'func-names': 'off',
179+
},
180+
},
171181
];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"typescript": "5.9.3",
124124
"typescript-eslint": "^8.47.0",
125125
"vite": "7.3.3",
126-
"vitest": "^3.0.0"
126+
"vitest": "^4.0.0"
127127
},
128128
"packageManager": "pnpm@10.33.0"
129129
}

pnpm-lock.yaml

Lines changed: 124 additions & 222 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ minimumReleaseAgeExclude:
33
- '@livekit/*'
44
# allow webrtc-adapter 9.0.5, see https://github.com/livekit/client-sdk-js/issues/1806
55
- webrtc-adapter@9.0.5
6+
# Renovate security update: vitest@4.1.0
7+
- vitest@4.1.0

src/api/SignalClient.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function mockWebSocketStream(options: MockWebSocketStreamOptions = {}) {
7777
onUrl,
7878
} = options;
7979

80-
return vi.mocked(WebSocketStream).mockImplementationOnce((url) => {
80+
return vi.mocked(WebSocketStream).mockImplementationOnce(function (url) {
8181
onUrl?.(url);
8282
return {
8383
url: 'wss://test.livekit.io',
@@ -283,7 +283,7 @@ describe('SignalClient.connect', () => {
283283
it('should reject when AbortSignal is triggered', async () => {
284284
const abortController = new AbortController();
285285

286-
vi.mocked(WebSocketStream).mockImplementation(() => {
286+
vi.mocked(WebSocketStream).mockImplementation(function () {
287287
// Simulate abort
288288
setTimeout(() => abortController.abort(new Error('User aborted connection')), 50);
289289

@@ -344,7 +344,7 @@ describe('SignalClient.connect', () => {
344344
extensions: '',
345345
};
346346

347-
vi.mocked(WebSocketStream).mockImplementation(() => {
347+
vi.mocked(WebSocketStream).mockImplementation(function () {
348348
return {
349349
url: 'wss://test.livekit.io',
350350
opened: Promise.resolve(mockConnection),
@@ -526,7 +526,7 @@ describe('SignalClient.connect', () => {
526526
closedResolve = resolve;
527527
});
528528

529-
vi.mocked(WebSocketStream).mockImplementation(() => {
529+
vi.mocked(WebSocketStream).mockImplementation(function () {
530530
// Simulate close during connection
531531
queueMicrotask(() => {
532532
closedResolve({ closeCode: 1006, reason: 'Connection lost' });

src/api/WebSocketStream.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,24 @@ describe('WebSocketStream', () => {
129129
vi.clearAllMocks();
130130

131131
// Store original WebSocket
132-
originalWebSocket = global.WebSocket;
132+
originalWebSocket = globalThis.WebSocket;
133133

134134
// Mock WebSocket globally
135-
global.WebSocket = vi.fn((url: string, protocols?: string | string[]) => {
135+
globalThis.WebSocket = vi.fn(function (url: string, protocols?: string | string[]) {
136136
mockWebSocket = new MockWebSocket(url, protocols);
137137
return mockWebSocket as any;
138138
}) as any;
139139

140140
// Add constants to the mocked WebSocket
141-
(global.WebSocket as any).CONNECTING = MockWebSocket.CONNECTING;
142-
(global.WebSocket as any).OPEN = MockWebSocket.OPEN;
143-
(global.WebSocket as any).CLOSING = MockWebSocket.CLOSING;
144-
(global.WebSocket as any).CLOSED = MockWebSocket.CLOSED;
141+
(globalThis.WebSocket as any).CONNECTING = MockWebSocket.CONNECTING;
142+
(globalThis.WebSocket as any).OPEN = MockWebSocket.OPEN;
143+
(globalThis.WebSocket as any).CLOSING = MockWebSocket.CLOSING;
144+
(globalThis.WebSocket as any).CLOSED = MockWebSocket.CLOSED;
145145
});
146146

147147
afterEach(() => {
148148
// Restore original WebSocket
149-
global.WebSocket = originalWebSocket;
149+
globalThis.WebSocket = originalWebSocket;
150150
});
151151

152152
describe('Constructor and Initialization', () => {

src/e2ee/worker/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"ES2018.Promise",
99
"WebWorker",
1010
"ES2021.WeakRef",
11-
"DOM.AsyncIterable"
11+
"DOM.AsyncIterable",
12+
"ES2020.BigInt",
13+
"ES2018.AsyncIterable",
14+
"ES2018.AsyncGenerator"
1215
]
1316
}
1417
}

src/packetTrailer/PacketTrailerManager.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ describe('PacketTrailerManager', () => {
103103
it('uses RTCRtpScriptTransform for packet trailer extraction when supported', () => {
104104
useSafariUserAgent();
105105
const transform = {};
106-
const RTCRtpScriptTransform = vi.fn(() => transform);
106+
const RTCRtpScriptTransform = vi.fn(function () {
107+
return transform;
108+
});
107109
setScriptTransform(RTCRtpScriptTransform);
108110

109111
const worker = {} as Worker;

src/packetTrailer/worker/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
"ES2018.Promise",
99
"WebWorker",
1010
"ES2021.WeakRef",
11-
"DOM.AsyncIterable"
11+
"DOM.AsyncIterable",
12+
"ES2020.BigInt",
13+
"ES2018.AsyncIterable",
14+
"ES2018.AsyncGenerator"
1215
]
1316
}
1417
}

src/room/RTCEngine.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ describe('RTCEngine', () => {
185185
stubScriptTransformSupport();
186186

187187
const transform = {};
188-
const RTCRtpScriptTransform = vi.fn(() => transform);
188+
const RTCRtpScriptTransform = vi.fn(function () {
189+
return transform;
190+
});
189191
Object.defineProperty(window, 'RTCRtpScriptTransform', {
190192
configurable: true,
191193
value: RTCRtpScriptTransform,

0 commit comments

Comments
 (0)