1
1
/* eslint-disable no-console */
2
+ Error . stackTraceLimit = Infinity ;
3
+
4
+ console . log ( 'TextEncoder is defined:' , typeof TextEncoder !== 'undefined' ) ;
5
+
2
6
const fs = require ( 'fs' ) ;
3
7
const path = require ( 'path' ) ;
8
+ const { TextEncoder } = require ( 'util' ) ;
9
+ const { Script } = require ( 'vm' ) ;
4
10
5
11
const webpack = require ( 'webpack' ) ;
6
12
const { JSDOM } = require ( 'jsdom' ) ;
7
13
8
- Error . stackTraceLimit = Infinity ;
9
14
10
15
webpack (
11
16
{
@@ -43,10 +48,8 @@ webpack(
43
48
44
49
function runTests ( ) {
45
50
const bundlePath = path . join ( __dirname , 'tmp.js' ) ;
46
- const { window } = new JSDOM ( '' , { runScripts : 'dangerously' } ) ;
47
-
48
- // This is a workaround for https://github.com/jsdom/jsdom/issues/2524
49
- window . TextEncoder = TextEncoder ;
51
+ const dom = new JSDOM ( '' , { runScripts : 'outside-only' } ) ;
52
+ const { window } = dom ;
50
53
51
54
window . onerror = function ( ) {
52
55
console . error ( 'ERROR thrown in manual test:' ) ;
@@ -62,13 +65,14 @@ function runTests() {
62
65
process . exit ( 1 ) ;
63
66
}
64
67
65
- const scriptEl = window . document . createElement ( 'script' ) ;
66
- scriptEl . textContent = myLibrary ;
67
- window . document . body . appendChild ( scriptEl ) ;
68
+ const vmContext = dom . getInternalVMContext ( ) ;
69
+ // This is a workaround for https://github.com/jsdom/jsdom/issues/2524
70
+ vmContext . TextEncoder = TextEncoder ;
71
+
72
+ const script1 = new Script ( myLibrary ) ;
73
+ const script2 = new Script ( myLibrary ) ;
74
+
75
+ script1 . runInContext ( vmContext ) ;
76
+ script2 . runInContext ( vmContext ) ;
68
77
69
- // Testing https://github.com/getsentry/sentry-javascript/issues/2043
70
- const scriptEl2 = window . document . createElement ( 'script' ) ;
71
- scriptEl2 . textContent = myLibrary ;
72
- window . document . body . appendChild ( scriptEl2 ) ;
73
- // ------------------------------------------------------------------
74
78
}
0 commit comments