Skip to content

Commit 848c2a5

Browse files
committed
ref: Add missing test for local Windows Tracekit scheme
1 parent 9a05738 commit 848c2a5

File tree

4 files changed

+47
-24
lines changed

4 files changed

+47
-24
lines changed

packages/browser/src/tracekit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ TraceKit._computeStackTrace = (function _computeStackTraceWrapper() {
477477
}
478478

479479
// Chromium based browsers: Chrome, Brave, new Opera, new Edge
480-
var chrome = /^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|[-a-z]+(?=:)|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,
480+
var chrome = /^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[-a-z]+:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,
481481
// gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
482482
// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
483483
// We need this specific case for now because we want no other regex to match.

packages/browser/test/unit/tracekit/custom.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@ import { expect } from 'chai';
33
import { _computeStackTrace } from '../../../src/tracekit';
44

55
describe('Tracekit - Custom Tests', () => {
6+
it('should parse errors with custom schemes', () => {
7+
const CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME = {
8+
message: 'message string',
9+
name: 'Error',
10+
stack: `Error: message string
11+
at examplescheme://examplehost/cd351f7250857e22ceaa.worker.js:70179:15`,
12+
};
13+
14+
const stacktrace = _computeStackTrace(CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME);
15+
16+
expect(stacktrace.stack).deep.equal([
17+
{
18+
args: [],
19+
column: 15,
20+
context: null,
21+
func: '?',
22+
line: 70179,
23+
url: 'examplescheme://examplehost/cd351f7250857e22ceaa.worker.js',
24+
},
25+
]);
26+
});
27+
628
describe('should parse exceptions with native code frames', () => {
729
it('in Chrome 73', () => {
830
const CHROME73_NATIVE_CODE_EXCEPTION = {
@@ -238,4 +260,28 @@ describe('Tracekit - Custom Tests', () => {
238260
]);
239261
});
240262
});
263+
264+
describe('should parse exceptions called within an iframe', () => {
265+
it('in Electron Renderer', () => {
266+
const CHROME_ELECTRON_RENDERER = {
267+
message: "Cannot read property 'error' of undefined",
268+
name: 'TypeError',
269+
stack: `TypeError: Cannot read property 'error' of undefined
270+
at TESTTESTTEST.someMethod (C:\\Users\\user\\path\\to\\file.js:295:108)`,
271+
};
272+
273+
const stacktrace = _computeStackTrace(CHROME_ELECTRON_RENDERER);
274+
275+
expect(stacktrace.stack).deep.equal([
276+
{
277+
args: [],
278+
column: 108,
279+
context: null,
280+
func: 'TESTTESTTEST.someMethod',
281+
line: 295,
282+
url: 'C:\\Users\\user\\path\\to\\file.js',
283+
},
284+
]);
285+
});
286+
});
241287
});

packages/browser/test/unit/tracekit/original.test.ts

-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
SAFARI_7,
3939
SAFARI_8,
4040
SAFARI_8_EVAL,
41-
CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME
4241
} from './originalfixtures';
4342

4443
describe('Tracekit - Original Tests', () => {
@@ -1245,18 +1244,4 @@ describe('Tracekit - Original Tests', () => {
12451244
context: null,
12461245
});
12471246
});
1248-
1249-
it('should parse Chromium Embedded Framework errors with custom schemes', () => {
1250-
const stackFrames = _computeStackTrace(CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME);
1251-
expect(stackFrames).to.be.ok;
1252-
expect(stackFrames.stack.length).to.equal(1);
1253-
expect(stackFrames.stack[0]).to.deep.equal({
1254-
url: 'examplescheme://examplehost/cd351f7250857e22ceaa.worker.js',
1255-
func: '?',
1256-
args: [],
1257-
line: 70179,
1258-
column: 15,
1259-
context: null,
1260-
});
1261-
})
12621247
});

packages/browser/test/unit/tracekit/originalfixtures.ts

-8
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,3 @@ export const ANDROID_REACT_NATIVE_PROD = {
482482
'value@index.android.bundle:29:927\n' +
483483
'[native code]',
484484
};
485-
486-
export const CHROMIUM_EMBEDDED_FRAMEWORK_CUSTOM_SCHEME = {
487-
message: 'message string',
488-
name: 'Error',
489-
stack:
490-
'Error: message string\n' +
491-
' at examplescheme://examplehost/cd351f7250857e22ceaa.worker.js:70179:15'
492-
};

0 commit comments

Comments
 (0)