Skip to content

Commit 22a2a4e

Browse files
committed
test: Run promises integration tests on all supported browsers
1 parent 46a0220 commit 22a2a4e

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

packages/browser/test/integration/common/utils.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ function supportsNativeFetch() {
4444
return result;
4545
}
4646

47-
function isChrome() {
48-
return (
49-
/Chrome/.test(navigator.userAgent) &&
50-
/Google Inc/.test(navigator.vendor) &&
51-
!/Android/.test(navigator.userAgent)
52-
);
47+
function supportsOnunhandledRejection() {
48+
return typeof PromiseRejectionEvent !== "undefined";
5349
}
5450

5551
function isBelowIE11() {

packages/browser/test/integration/suites/builtins.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ describe("wrapped built-ins", function() {
4646
describe("unhandledrejection", function() {
4747
it("should capture unhandledrejection with error", function() {
4848
return runInSandbox(sandbox, function() {
49-
if (isChrome()) {
49+
if (supportsOnunhandledRejection()) {
5050
Promise.reject(new Error("test2"));
5151
} else {
5252
window.resolveTest({ window: window });
5353
}
5454
}).then(function(summary) {
55-
if (summary.window.isChrome()) {
55+
if (summary.window.supportsOnunhandledRejection()) {
5656
assert.equal(summary.events[0].exception.values[0].value, "test2");
5757
assert.equal(summary.events[0].exception.values[0].type, "Error");
58-
assert.isAtLeast(
59-
summary.events[0].exception.values[0].stacktrace.frames.length,
60-
1
61-
);
58+
59+
// Of course Safari had to screw up here...
60+
if (!/Version\/\d.+Safari\/\d/.test(window.navigator.userAgent)) {
61+
assert.isAtLeast(
62+
summary.events[0].exception.values[0].stacktrace.frames.length,
63+
1
64+
);
65+
}
6266
assert.equal(
6367
summary.events[0].exception.values[0].mechanism.handled,
6468
false
@@ -73,13 +77,13 @@ describe("wrapped built-ins", function() {
7377

7478
it("should capture unhandledrejection with a string", function() {
7579
return runInSandbox(sandbox, function() {
76-
if (isChrome()) {
80+
if (supportsOnunhandledRejection()) {
7781
Promise.reject("test");
7882
} else {
7983
window.resolveTest({ window: window });
8084
}
8185
}).then(function(summary) {
82-
if (summary.window.isChrome()) {
86+
if (summary.window.supportsOnunhandledRejection()) {
8387
// non-error rejections doesnt provide stacktraces so we can skip the assertion
8488
assert.equal(
8589
summary.events[0].exception.values[0].value,
@@ -103,13 +107,13 @@ describe("wrapped built-ins", function() {
103107

104108
it("should capture unhandledrejection with a monster string", function() {
105109
return runInSandbox(sandbox, function() {
106-
if (isChrome()) {
110+
if (supportsOnunhandledRejection()) {
107111
Promise.reject("test".repeat(100));
108112
} else {
109113
window.resolveTest({ window: window });
110114
}
111115
}).then(function(summary) {
112-
if (summary.window.isChrome()) {
116+
if (summary.window.supportsOnunhandledRejection()) {
113117
// non-error rejections doesnt provide stacktraces so we can skip the assertion
114118
assert.equal(summary.events[0].exception.values[0].value.length, 253);
115119
assert.include(
@@ -134,13 +138,13 @@ describe("wrapped built-ins", function() {
134138

135139
it("should capture unhandledrejection with an object", function() {
136140
return runInSandbox(sandbox, function() {
137-
if (isChrome()) {
141+
if (supportsOnunhandledRejection()) {
138142
Promise.reject({ a: "b", b: "c", c: "d" });
139143
} else {
140144
window.resolveTest({ window: window });
141145
}
142146
}).then(function(summary) {
143-
if (summary.window.isChrome()) {
147+
if (summary.window.supportsOnunhandledRejection()) {
144148
// non-error rejections doesnt provide stacktraces so we can skip the assertion
145149
assert.equal(
146150
summary.events[0].exception.values[0].value,
@@ -164,7 +168,7 @@ describe("wrapped built-ins", function() {
164168

165169
it("should capture unhandledrejection with an monster object", function() {
166170
return runInSandbox(sandbox, function() {
167-
if (isChrome()) {
171+
if (supportsOnunhandledRejection()) {
168172
var a = {
169173
a: "1".repeat("100"),
170174
b: "2".repeat("100"),
@@ -177,7 +181,7 @@ describe("wrapped built-ins", function() {
177181
window.resolveTest({ window: window });
178182
}
179183
}).then(function(summary) {
180-
if (summary.window.isChrome()) {
184+
if (summary.window.supportsOnunhandledRejection()) {
181185
// non-error rejections doesnt provide stacktraces so we can skip the assertion
182186
assert.equal(
183187
summary.events[0].exception.values[0].value,
@@ -201,13 +205,13 @@ describe("wrapped built-ins", function() {
201205

202206
it("should capture unhandledrejection with a number", function() {
203207
return runInSandbox(sandbox, function() {
204-
if (isChrome()) {
208+
if (supportsOnunhandledRejection()) {
205209
Promise.reject(1337);
206210
} else {
207211
window.resolveTest({ window: window });
208212
}
209213
}).then(function(summary) {
210-
if (summary.window.isChrome()) {
214+
if (summary.window.supportsOnunhandledRejection()) {
211215
// non-error rejections doesnt provide stacktraces so we can skip the assertion
212216
assert.equal(
213217
summary.events[0].exception.values[0].value,
@@ -231,13 +235,13 @@ describe("wrapped built-ins", function() {
231235

232236
it("should capture unhandledrejection with null", function() {
233237
return runInSandbox(sandbox, function() {
234-
if (isChrome()) {
238+
if (supportsOnunhandledRejection()) {
235239
Promise.reject(null);
236240
} else {
237241
window.resolveTest({ window: window });
238242
}
239243
}).then(function(summary) {
240-
if (summary.window.isChrome()) {
244+
if (summary.window.supportsOnunhandledRejection()) {
241245
// non-error rejections doesnt provide stacktraces so we can skip the assertion
242246
assert.equal(
243247
summary.events[0].exception.values[0].value,
@@ -261,13 +265,13 @@ describe("wrapped built-ins", function() {
261265

262266
it("should capture unhandledrejection with an undefined", function() {
263267
return runInSandbox(sandbox, function() {
264-
if (isChrome()) {
268+
if (supportsOnunhandledRejection()) {
265269
Promise.reject(undefined);
266270
} else {
267271
window.resolveTest({ window: window });
268272
}
269273
}).then(function(summary) {
270-
if (summary.window.isChrome()) {
274+
if (summary.window.supportsOnunhandledRejection()) {
271275
// non-error rejections doesnt provide stacktraces so we can skip the assertion
272276
assert.equal(
273277
summary.events[0].exception.values[0].value,
@@ -291,7 +295,7 @@ describe("wrapped built-ins", function() {
291295

292296
it("should skip our own failed requests that somehow bubbled-up to unhandledrejection handler", function() {
293297
return runInSandbox(sandbox, function() {
294-
if (isChrome()) {
298+
if (supportsOnunhandledRejection()) {
295299
Promise.reject({
296300
__sentry_own_request__: true,
297301
});
@@ -303,7 +307,7 @@ describe("wrapped built-ins", function() {
303307
window.resolveTest({ window: window });
304308
}
305309
}).then(function(summary) {
306-
if (summary.window.isChrome()) {
310+
if (summary.window.supportsOnunhandledRejection()) {
307311
assert.equal(summary.events.length, 2);
308312
}
309313
});

0 commit comments

Comments
 (0)