Skip to content

Commit 9ee48d2

Browse files
author
Loïc Mangeonjean
committed
fix: prevent too many errors during tests
1 parent 11858ba commit 9ee48d2

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

FixJSDOMEnvironment.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import { TestEnvironment } from 'jest-environment-jsdom'
22

33
class FixJSDOMEnvironment extends TestEnvironment {
44
constructor(...args) {
5-
super(...args);
5+
super(...args)
6+
7+
this.dom.virtualConsole.removeAllListeners('jsdomError')
8+
this.dom.virtualConsole.on('jsdomError', (error) => {
9+
if (error.message.startsWith('Could not parse CSS stylesheet')) {
10+
return
11+
}
12+
context.console.error(error)
13+
})
614

715
// FIXME https://github.com/jsdom/jsdom/issues/3363
8-
this.global.structuredClone = structuredClone;
16+
this.global.structuredClone = structuredClone
917
}
1018
}
1119

browserMock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ Object.defineProperty(window, 'Buffer', {
145145

146146
// Force override performance, for some reason the implementation is empty otherwise
147147
let _performance = performance
148+
// remove nodeTiming because otherwise VSCode refuse to detect the env as a browser env, and it also fails to detect a node env (no `process`) so it generates an error
149+
performance.nodeTiming = undefined
148150
Object.defineProperty(global, 'performance', {
149151
get () { return _performance },
150152
set (v) {

0 commit comments

Comments
 (0)