Skip to content

Commit 4a9aea2

Browse files
authored
test(rum-core): fix some flaky tests (#1561)
1 parent f239235 commit 4a9aea2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/rum-core/test/common/xhr-patch.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ describe('xhrPatch', function () {
190190
const req = new window.XMLHttpRequest()
191191
const getEvents = registerEventListener(req)
192192
req.open('GET', 'https://elastic.co/guide', true)
193+
req.timeout = 1
193194
req.addEventListener('loadend', () => {
194195
expect(getEvents(done).map(e => e.event)).toEqual(['schedule', 'invoke'])
195196
})

packages/rum-core/test/performance-monitoring/performance-monitoring.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,13 @@ describe('PerformanceMonitoring', function () {
198198

199199
it('should notify when a transaction has been filtered out', function () {
200200
spyOn(configService, 'dispatchEvent')
201-
var tr = new Transaction('transaction-no-duration', 'transaction-type')
202-
tr.end()
201+
// NOTE: tests in SauceLabs fail because the duration becomes 1. Setting the start & end
202+
// times will ensure `duration` is 0.
203+
var now = Date.now()
204+
var tr = new Transaction('transaction-no-duration', 'transaction-type', {
205+
startTime: now
206+
})
207+
tr.end(now)
203208

204209
var payload = performanceMonitoring.createTransactionPayload(tr)
205210
expect(payload).toBeUndefined()

0 commit comments

Comments
 (0)