Skip to content

Commit 160ded8

Browse files
[test optimization] More robust cypress test (#6463)
1 parent 7338335 commit 160ded8

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

integration-tests/cypress/cypress.spec.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ moduleTypes.forEach(({
120120
}
121121

122122
this.retries(2)
123-
this.timeout(70000)
123+
this.timeout(80000)
124124
let sandbox, cwd, receiver, childProcess, webAppPort, secondWebAppServer
125125

126126
if (type === 'commonJS') {
@@ -195,21 +195,20 @@ moduleTypes.forEach(({
195195
})
196196
}
197197

198-
it('does not crash if badly init', (done) => {
198+
it('does not crash if badly init', async () => {
199199
const {
200200
NODE_OPTIONS, // NODE_OPTIONS dd-trace config does not work with cypress
201201
DD_CIVISIBILITY_AGENTLESS_URL,
202202
...restEnvVars
203203
} = getCiVisAgentlessConfig(receiver.port)
204204

205-
receiver.assertPayloadReceived(() => {
206-
const error = new Error('it should not report test events')
207-
// eslint-disable-next-line no-console
208-
console.log('it should never be executed')
209-
done(error)
205+
let hasReceivedEvents = false
206+
207+
const eventsPromise = receiver.assertPayloadReceived(() => {
208+
hasReceivedEvents = true
210209
}, ({ url }) => url.endsWith('/api/v2/citestcycle')).catch(() => {})
211210

212-
let testOutput
211+
let testOutput = ''
213212

214213
childProcess = exec(
215214
testCommand,
@@ -231,22 +230,27 @@ moduleTypes.forEach(({
231230
testOutput += chunk.toString()
232231
})
233232

234-
childProcess.on('exit', () => {
233+
await Promise.all([
234+
once(childProcess.stdout, 'end'),
235+
once(childProcess.stderr, 'end'),
236+
once(childProcess, 'exit'),
237+
eventsPromise
238+
])
239+
240+
assert.strictEqual(hasReceivedEvents, false)
241+
// TODO: remove try/catch once we find the source of flakiness
242+
try {
235243
assert.notInclude(testOutput, 'TypeError')
236-
// TODO: remove try/catch once we find the source of flakiness
237-
try {
238-
assert.include(testOutput, '1 of 1 failed')
239-
done()
240-
} catch (e) {
241-
// eslint-disable-next-line no-console
242-
console.log('---- Actual test output -----')
243-
// eslint-disable-next-line no-console
244-
console.log(testOutput)
245-
// eslint-disable-next-line no-console
246-
console.log('---- finish actual test output -----')
247-
done(e)
248-
}
249-
})
244+
assert.include(testOutput, '1 of 1 failed')
245+
} catch (e) {
246+
// eslint-disable-next-line no-console
247+
console.log('---- Actual test output -----')
248+
// eslint-disable-next-line no-console
249+
console.log(testOutput)
250+
// eslint-disable-next-line no-console
251+
console.log('---- finish actual test output -----')
252+
throw e
253+
}
250254
})
251255

252256
it('catches errors in hooks', (done) => {

0 commit comments

Comments
 (0)