Skip to content

Commit 57aaf99

Browse files
authored
fix: Integration tests (#1840)
* fix: Add extended loggin * fix: Add assert * fix: Remove promise tests * Revert "fix: Remove promise tests" This reverts commit 37412b7. * Revert "fix: Add assert" This reverts commit 1d1119e. * fix: Integration tests * fix: Remove console.log from test * fix: Integration tests om < ie11 * test: Fix stuck integration test * test: Unify setTimeouts calls * I hate javascript * fix: Saucelabs
1 parent c3ccebb commit 57aaf99

File tree

4 files changed

+49
-39
lines changed

4 files changed

+49
-39
lines changed

packages/browser/test/integration/init.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,7 @@ function captureSameConsecutiveMessages(message) {
129129
}
130130

131131
function isChrome() {
132-
return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
132+
return (
133+
/Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor) && !/Android/.test(navigator.userAgent)
134+
);
133135
}

packages/browser/test/integration/test.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ for (var idx in frames) {
399399
var sentryData = sentryData[0];
400400
// ¯\_(ツ)_/¯
401401
if (isBelowIE11()) {
402-
assert.equal(sentryData.exception.values[0].type, undefined);
402+
assert.equal(sentryData.exception.values[0].type, 'Error');
403403
} else {
404404
assert.match(sentryData.exception.values[0].type, /SyntaxError/);
405405
}
@@ -507,7 +507,7 @@ for (var idx in frames) {
507507
var sentryData = iframe.contentWindow.sentryData[0];
508508
// ¯\_(ツ)_/¯
509509
if (isBelowIE11()) {
510-
assert.equal(sentryData.exception.values[0].type, undefined);
510+
assert.equal(sentryData.exception.values[0].type, 'Error');
511511
} else {
512512
assert.match(sentryData.exception.values[0].type, /^Error/);
513513
}
@@ -625,9 +625,7 @@ for (var idx in frames) {
625625
done,
626626
function() {
627627
if (isChrome()) {
628-
setTimeout(function() {
629-
return Promise.reject(new Error('test2'));
630-
});
628+
Promise.reject(new Error('test2'));
631629
} else {
632630
done();
633631
}
@@ -641,7 +639,7 @@ for (var idx in frames) {
641639
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
642640
done();
643641
} else {
644-
console.log('Skipping this test in non chrome');
642+
// This test will be skipped if it's not Chrome Desktop
645643
done();
646644
}
647645
}
@@ -656,9 +654,7 @@ for (var idx in frames) {
656654
done,
657655
function() {
658656
if (isChrome()) {
659-
setTimeout(function() {
660-
return Promise.reject('test');
661-
});
657+
Promise.reject('test');
662658
} else {
663659
done();
664660
}
@@ -672,7 +668,7 @@ for (var idx in frames) {
672668
assert.equal(sentryData[0].exception.mechanism.type, 'onunhandledrejection');
673669
done();
674670
} else {
675-
console.log('Skipping this test in non chrome');
671+
// This test will be skipped if it's not Chrome Desktop
676672
done();
677673
}
678674
}
@@ -757,6 +753,7 @@ for (var idx in frames) {
757753

758754
xhr.open('GET', 'example.json');
759755
xhr.onreadystatechange = function() {
756+
setTimeout(done, 1000);
760757
// replace onreadystatechange with no-op so exception doesn't
761758
// fire more than once as XHR changes loading state
762759
xhr.onreadystatechange = function() {};
@@ -996,10 +993,10 @@ for (var idx in frames) {
996993
iframe,
997994
done,
998995
function() {
996+
setTimeout(done, 1000);
999997
var xhr = new XMLHttpRequest();
1000998
xhr.open('GET', 'https://example.com/api/1/store/');
1001999
xhr.send('{"message":"someMessage","level":"warning"}');
1002-
setTimeout(done);
10031000
},
10041001
function() {
10051002
if (IS_ASYNC_LOADER) {
@@ -1159,6 +1156,10 @@ for (var idx in frames) {
11591156
iframe,
11601157
done,
11611158
function() {
1159+
setTimeout(function() {
1160+
Sentry.captureMessage('test');
1161+
}, 1000);
1162+
11621163
// add an event listener to the input. we want to make sure that
11631164
// our breadcrumbs still work even if the page has an event listener
11641165
// on an element that cancels event bubbling
@@ -1171,9 +1172,6 @@ for (var idx in frames) {
11711172
// click <input/>
11721173
var click = new MouseEvent('click');
11731174
input.dispatchEvent(click);
1174-
setTimeout(function() {
1175-
Sentry.captureMessage('test');
1176-
});
11771175
},
11781176
function(sentryData) {
11791177
if (IS_ASYNC_LOADER) {
@@ -1199,13 +1197,14 @@ for (var idx in frames) {
11991197
iframe,
12001198
done,
12011199
function() {
1200+
setTimeout(function() {
1201+
Sentry.captureMessage('test');
1202+
}, 1000);
1203+
12021204
// click <input/>
12031205
var click = new MouseEvent('click');
12041206
var input = document.getElementsByTagName('input')[0];
12051207
input.dispatchEvent(click);
1206-
setTimeout(function() {
1207-
Sentry.captureMessage('test');
1208-
});
12091208
},
12101209
function(sentryData) {
12111210
if (IS_ASYNC_LOADER) {
@@ -1231,9 +1230,11 @@ for (var idx in frames) {
12311230
iframe,
12321231
done,
12331232
function() {
1234-
var clickHandler = function(evt) {
1235-
//evt.stopPropagation();
1236-
};
1233+
setTimeout(function() {
1234+
Sentry.captureMessage('test');
1235+
}, 1000);
1236+
1237+
var clickHandler = function() {};
12371238

12381239
// mousemove event shouldnt clobber subsequent "breadcrumbed" events (see #724)
12391240
document.querySelector('.a').addEventListener('mousemove', clickHandler);
@@ -1246,9 +1247,6 @@ for (var idx in frames) {
12461247
var click = new MouseEvent('click');
12471248
var input = document.querySelector('.a'); // leaf node
12481249
input.dispatchEvent(click);
1249-
setTimeout(function() {
1250-
Sentry.captureMessage('test');
1251-
});
12521250
},
12531251
function(sentryData) {
12541252
if (IS_ASYNC_LOADER) {
@@ -1275,6 +1273,10 @@ for (var idx in frames) {
12751273
iframe,
12761274
done,
12771275
function() {
1276+
setTimeout(function() {
1277+
Sentry.captureMessage('test');
1278+
}, 1000);
1279+
12781280
// click <input/>
12791281
var click = new MouseEvent('click');
12801282
function kaboom() {
@@ -1285,9 +1287,6 @@ for (var idx in frames) {
12851287

12861288
var input = document.querySelector('.a'); // leaf node
12871289
input.dispatchEvent(click);
1288-
setTimeout(function() {
1289-
Sentry.captureMessage('test');
1290-
});
12911290
},
12921291
function(sentryData) {
12931292
if (IS_ASYNC_LOADER) {
@@ -1311,16 +1310,17 @@ for (var idx in frames) {
13111310
iframe,
13121311
done,
13131312
function() {
1313+
setTimeout(function() {
1314+
Sentry.captureMessage('test');
1315+
}, 1000);
1316+
13141317
// keypress <input/> twice
13151318
var keypress1 = new KeyboardEvent('keypress');
13161319
var keypress2 = new KeyboardEvent('keypress');
13171320

13181321
var input = document.getElementsByTagName('input')[0];
13191322
input.dispatchEvent(keypress1);
13201323
input.dispatchEvent(keypress2);
1321-
setTimeout(function() {
1322-
Sentry.captureMessage('test');
1323-
});
13241324
},
13251325
function(sentryData) {
13261326
if (IS_ASYNC_LOADER) {
@@ -1378,6 +1378,10 @@ for (var idx in frames) {
13781378
iframe,
13791379
done,
13801380
function() {
1381+
setTimeout(function() {
1382+
Sentry.captureMessage('test');
1383+
}, 1000);
1384+
13811385
// 1st keypress <input/>
13821386
var keypress1 = new KeyboardEvent('keypress');
13831387
// click <input/>
@@ -1389,9 +1393,6 @@ for (var idx in frames) {
13891393
input.dispatchEvent(keypress1);
13901394
input.dispatchEvent(click);
13911395
input.dispatchEvent(keypress2);
1392-
setTimeout(function() {
1393-
Sentry.captureMessage('test');
1394-
});
13951396
},
13961397
function(sentryData) {
13971398
if (IS_ASYNC_LOADER) {
@@ -1423,17 +1424,18 @@ for (var idx in frames) {
14231424
iframe,
14241425
done,
14251426
function() {
1427+
setTimeout(function() {
1428+
setTimeout(done, 1000);
1429+
Sentry.captureMessage('test');
1430+
}, 1000);
1431+
14261432
// keypress <input/> twice
14271433
var keypress1 = new KeyboardEvent('keypress');
14281434
var keypress2 = new KeyboardEvent('keypress');
14291435

14301436
var div = document.querySelector('[contenteditable]');
14311437
div.dispatchEvent(keypress1);
14321438
div.dispatchEvent(keypress2);
1433-
setTimeout(function() {
1434-
Sentry.captureMessage('test');
1435-
setTimeout(done, 1000);
1436-
});
14371439
},
14381440
function(sentryData) {
14391441
if (IS_ASYNC_LOADER) {
@@ -1459,16 +1461,16 @@ for (var idx in frames) {
14591461
iframe,
14601462
done,
14611463
function() {
1464+
setTimeout(done, 1000);
1465+
14621466
history.pushState({}, '', '/foo');
14631467
history.pushState({}, '', '/bar?a=1#fragment');
14641468
history.pushState({}, '', {}); // pushState calls toString on non-string args
14651469
history.pushState({}, '', null); // does nothing / no-op
1466-
14671470
// can't call history.back() because it will change url of parent document
14681471
// (e.g. document running mocha) ... instead just "emulate" a back button
14691472
// press by calling replaceState
14701473
history.replaceState({}, '', '/bar?a=1#fragment');
1471-
setTimeout(done);
14721474
},
14731475
function(sentryData) {
14741476
if (IS_ASYNC_LOADER) {

packages/browser/test/karma/karma.saucelabs.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ module.exports = function(config) {
103103
recordVideo: false,
104104
testName: '@sentry/browser' + (process.env.TRAVIS_JOB_NUMBER ? ' #' + process.env.TRAVIS_JOB_NUMBER : ''),
105105
public: 'public',
106+
extendedDebugging: true,
106107
},
107108
});
108109
};

packages/utils/src/object.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ function normalizeValue(value: any, key?: any): any {
280280
return objectifyError(value);
281281
}
282282

283+
// tslint:disable-next-line:strict-type-predicates
284+
if (typeof Event !== 'undefined' && value instanceof Event) {
285+
return Object.getPrototypeOf(value) ? value.constructor.name : 'Event';
286+
}
287+
283288
if (isNaN(value)) {
284289
return '[NaN]';
285290
}

0 commit comments

Comments
 (0)