Skip to content

Commit 2193405

Browse files
committed
try importing TextEncoder
1 parent f11cc8e commit 2193405

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/* eslint-disable no-console */
2+
Error.stackTraceLimit = Infinity;
3+
4+
console.log('TextEncoder is defined:', typeof TextEncoder !== 'undefined');
5+
26
const fs = require('fs');
37
const path = require('path');
8+
const { TextEncoder } = require('util');
9+
const { Script } = require('vm');
410

511
const webpack = require('webpack');
612
const { JSDOM } = require('jsdom');
713

8-
Error.stackTraceLimit = Infinity;
914

1015
webpack(
1116
{
@@ -43,10 +48,8 @@ webpack(
4348

4449
function runTests() {
4550
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;
5053

5154
window.onerror = function () {
5255
console.error('ERROR thrown in manual test:');
@@ -62,13 +65,14 @@ function runTests() {
6265
process.exit(1);
6366
}
6467

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

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

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)