Skip to content

Commit

Permalink
Improve nextjs tests flakyness (#4411)
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien authored and juan-fernandez committed Jul 11, 2024
1 parent 11d6c2a commit 324d72b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/datadog-plugin-next/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ describe('Plugin', function () {
})

server.once('error', done)
server.stdout.once('data', () => {
// first log outputted isn't always the server started log
// https://github.com/vercel/next.js/blob/v10.2.0/packages/next/next-server/server/config-utils.ts#L39
// these are webpack related logs that run during execution time and not build

// additionally, next.js sets timeouts in 10.x when displaying extra logs
// https://github.com/vercel/next.js/blob/v10.2.0/packages/next/server/next.ts#L132-L133
setTimeout(done, 700) // relatively high timeout chosen to be safe
})

function waitUntilServerStarted (chunk) {
const chunkString = chunk.toString()
if (chunkString?.includes(port) || chunkString?.includes('Ready ')) {
server.stdout.off('data', waitUntilServerStarted)
done()
}
}
server.stdout.on('data', waitUntilServerStarted)

server.stderr.on('data', chunk => process.stderr.write(chunk))
server.stdout.on('data', chunk => process.stdout.write(chunk))
})
Expand Down

0 comments on commit 324d72b

Please sign in to comment.