Skip to content

Commit af84d8a

Browse files
committed
try using vmContext
1 parent f11cc8e commit af84d8a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

packages/browser/test/package/npm-build.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-console */
22
const fs = require('fs');
33
const path = require('path');
4+
const { Script } = require('vm');
45

56
const webpack = require('webpack');
67
const { JSDOM } = require('jsdom');
@@ -43,10 +44,8 @@ webpack(
4344

4445
function runTests() {
4546
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;
5049

5150
window.onerror = function () {
5251
console.error('ERROR thrown in manual test:');
@@ -62,13 +61,14 @@ function runTests() {
6261
process.exit(1);
6362
}
6463

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);
6873

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-
// ------------------------------------------------------------------
7474
}

packages/browser/test/package/test-code.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
const Sentry = require('../../build/npm/cjs/index.js');
33
const Integrations = require('../../../integrations/build/npm/cjs/dedupe.js');
44

5+
console.log('about to init the SDK');
6+
57
// Init
68
Sentry.init({
79
dsn: 'https://completelyrandom@dsn.asdf/42',
810
integrations: [new Integrations.Dedupe()],
911
beforeSend(_event) {
10-
console.log('Got an event');
12+
// console.log('Got an event');
1113
return null;
1214
},
1315
beforeBreadcrumb(crumb) {
14-
console.log(`Got a breadcrumb: ${crumb.category}`);
16+
// console.log(`Got a breadcrumb: ${crumb.category}`);
1517
return crumb;
1618
},
1719
});

0 commit comments

Comments
 (0)