Skip to content

Commit 898c78f

Browse files
juan-fernandeztlhunter
authored andcommitted
[ci-visibility] Do not modify how jest reports timeouts (#3399)
1 parent a4f5a39 commit 898c78f

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

integration-tests/ci-visibility.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,28 @@ testFrameworks.forEach(({
230230
}).catch(done)
231231
})
232232
})
233+
it('reports timeout error message', (done) => {
234+
childProcess = fork('ci-visibility/run-jest.js', {
235+
cwd,
236+
env: {
237+
...getCiVisAgentlessConfig(receiver.port),
238+
NODE_OPTIONS: '-r dd-trace/ci/init',
239+
RUN_IN_PARALLEL: true,
240+
TEST_REGEX: 'timeout-test/timeout-test.js'
241+
},
242+
stdio: 'pipe'
243+
})
244+
childProcess.stdout.on('data', (chunk) => {
245+
testOutput += chunk.toString()
246+
})
247+
childProcess.stderr.on('data', (chunk) => {
248+
testOutput += chunk.toString()
249+
})
250+
childProcess.on('message', () => {
251+
assert.include(testOutput, 'Exceeded timeout of 100 ms for a test while waiting for `done()` to be called.')
252+
done()
253+
})
254+
})
233255
}
234256

235257
it('can run tests and report spans', (done) => {

integration-tests/ci-visibility/run-jest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const options = {
44
projects: [__dirname],
55
testPathIgnorePatterns: ['/node_modules/'],
66
cache: false,
7-
testRegex: /test\/ci-visibility-test/,
7+
testRegex: process.env.TEST_REGEX ? new RegExp(process.env.TEST_REGEX) : /test\/ci-visibility-test/,
88
coverage: true,
99
runInBand: true
1010
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable */
2+
jest.setTimeout(100)
3+
describe('ci visibility', () => {
4+
it('will timeout', (done) => {
5+
setTimeout(() => {
6+
done()
7+
}, 200)
8+
})
9+
})

packages/datadog-instrumentations/src/jest.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
129129
suite: this.testSuite,
130130
runner: 'jest-circus',
131131
testParameters,
132-
frameworkVersion: jestVersion,
133-
testStartLine: getTestLineStart(event.test.asyncError, this.testSuite)
132+
frameworkVersion: jestVersion
134133
})
135134
originalTestFns.set(event.test, event.test.fn)
136135
event.test.fn = asyncResource.bind(event.test.fn)
@@ -145,7 +144,10 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
145144
const formattedError = formatJestError(event.test.errors[0])
146145
testErrCh.publish(formattedError)
147146
}
148-
testRunFinishCh.publish(status)
147+
testRunFinishCh.publish({
148+
status,
149+
testStartLine: getTestLineStart(event.test.asyncError, this.testSuite)
150+
})
149151
// restore in case it is retried
150152
event.test.fn = originalTestFns.get(event.test)
151153
})
@@ -471,7 +473,7 @@ function jasmineAsyncInstallWraper (jasmineAsyncInstallExport, jestVersion) {
471473
const formattedError = formatJestError(spec.result.failedExpectations[0].error)
472474
testErrCh.publish(formattedError)
473475
}
474-
testRunFinishCh.publish(specStatusToTestStatus[spec.result.status])
476+
testRunFinishCh.publish({ status: specStatusToTestStatus[spec.result.status] })
475477
onComplete.apply(this, arguments)
476478
})
477479
arguments[0] = callback

packages/datadog-plugin-jest/src/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ class JestPlugin extends CiPlugin {
166166
this.enter(span, store)
167167
})
168168

169-
this.addSub('ci:jest:test:finish', (status) => {
169+
this.addSub('ci:jest:test:finish', ({ status, testStartLine }) => {
170170
const span = storage.getStore().span
171171
span.setTag(TEST_STATUS, status)
172+
if (testStartLine) {
173+
span.setTag(TEST_SOURCE_START, testStartLine)
174+
}
172175
span.finish()
173176
finishAllTraceSpans(span)
174177
})
@@ -197,8 +200,10 @@ class JestPlugin extends CiPlugin {
197200
const extraTags = {
198201
[JEST_TEST_RUNNER]: runner,
199202
[TEST_PARAMETERS]: testParameters,
200-
[TEST_FRAMEWORK_VERSION]: frameworkVersion,
201-
[TEST_SOURCE_START]: testStartLine
203+
[TEST_FRAMEWORK_VERSION]: frameworkVersion
204+
}
205+
if (testStartLine) {
206+
extraTags[TEST_SOURCE_START] = testStartLine
202207
}
203208

204209
return super.startTestSpan(name, suite, this.testSuiteSpan, extraTags)

0 commit comments

Comments
 (0)