1
1
/* eslint-disable no-console */
2
2
const fs = require ( 'fs' ) ;
3
3
const path = require ( 'path' ) ;
4
+ const { Script } = require ( 'vm' ) ;
4
5
5
6
const webpack = require ( 'webpack' ) ;
6
7
const { JSDOM } = require ( 'jsdom' ) ;
@@ -43,10 +44,8 @@ webpack(
43
44
44
45
function runTests ( ) {
45
46
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 ;
47
+ const dom = new JSDOM ( '' , { runScripts : 'outside-only' } ) ;
48
+ const { window } = dom ;
50
49
51
50
window . onerror = function ( ) {
52
51
console . error ( 'ERROR thrown in manual test:' ) ;
@@ -62,13 +61,14 @@ function runTests() {
62
61
process . exit ( 1 ) ;
63
62
}
64
63
65
- const scriptEl = window . document . createElement ( 'script' ) ;
66
- scriptEl . textContent = myLibrary ;
67
- window . document . body . appendChild ( scriptEl ) ;
64
+ const vmContext = dom . getInternalVMContext ( ) ;
65
+ // This is a workaround for https://github.com/jsdom/jsdom/issues/2524
66
+ vmContext . TextEncoder = TextEncoder ;
67
+
68
+ const script1 = new Script ( myLibrary ) ;
69
+ const script2 = new Script ( myLibrary ) ;
70
+
71
+ script1 . runInContext ( vmContext ) ;
72
+ script2 . runInContext ( vmContext ) ;
68
73
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
74
}
0 commit comments