Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions integration-tests/ci-visibility.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,28 @@ testFrameworks.forEach(({
}).catch(done)
})
})
it('reports timeout error message', (done) => {
childProcess = fork('ci-visibility/run-jest.js', {
cwd,
env: {
...getCiVisAgentlessConfig(receiver.port),
NODE_OPTIONS: '-r dd-trace/ci/init',
RUN_IN_PARALLEL: true,
TEST_REGEX: 'timeout-test/timeout-test.js'
},
stdio: 'pipe'
})
childProcess.stdout.on('data', (chunk) => {
testOutput += chunk.toString()
})
childProcess.stderr.on('data', (chunk) => {
testOutput += chunk.toString()
})
childProcess.on('message', () => {
assert.include(testOutput, 'Exceeded timeout of 100 ms for a test while waiting for `done()` to be called.')
done()
})
})
}

it('can run tests and report spans', (done) => {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/ci-visibility/run-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const options = {
projects: [__dirname],
testPathIgnorePatterns: ['/node_modules/'],
cache: false,
testRegex: /test\/ci-visibility-test/,
testRegex: process.env.TEST_REGEX ? new RegExp(process.env.TEST_REGEX) : /test\/ci-visibility-test/,
coverage: true,
runInBand: true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable */
jest.setTimeout(100)
describe('ci visibility', () => {
it('will timeout', (done) => {
setTimeout(() => {
done()
}, 200)
})
})
10 changes: 6 additions & 4 deletions packages/datadog-instrumentations/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
suite: this.testSuite,
runner: 'jest-circus',
testParameters,
frameworkVersion: jestVersion,
testStartLine: getTestLineStart(event.test.asyncError, this.testSuite)
frameworkVersion: jestVersion
})
originalTestFns.set(event.test, event.test.fn)
event.test.fn = asyncResource.bind(event.test.fn)
Expand All @@ -145,7 +144,10 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
const formattedError = formatJestError(event.test.errors[0])
testErrCh.publish(formattedError)
}
testRunFinishCh.publish(status)
testRunFinishCh.publish({
status,
testStartLine: getTestLineStart(event.test.asyncError, this.testSuite)
})
// restore in case it is retried
event.test.fn = originalTestFns.get(event.test)
})
Expand Down Expand Up @@ -471,7 +473,7 @@ function jasmineAsyncInstallWraper (jasmineAsyncInstallExport, jestVersion) {
const formattedError = formatJestError(spec.result.failedExpectations[0].error)
testErrCh.publish(formattedError)
}
testRunFinishCh.publish(specStatusToTestStatus[spec.result.status])
testRunFinishCh.publish({ status: specStatusToTestStatus[spec.result.status] })
onComplete.apply(this, arguments)
})
arguments[0] = callback
Expand Down
11 changes: 8 additions & 3 deletions packages/datadog-plugin-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ class JestPlugin extends CiPlugin {
this.enter(span, store)
})

this.addSub('ci:jest:test:finish', (status) => {
this.addSub('ci:jest:test:finish', ({ status, testStartLine }) => {
const span = storage.getStore().span
span.setTag(TEST_STATUS, status)
if (testStartLine) {
span.setTag(TEST_SOURCE_START, testStartLine)
}
span.finish()
finishAllTraceSpans(span)
})
Expand Down Expand Up @@ -197,8 +200,10 @@ class JestPlugin extends CiPlugin {
const extraTags = {
[JEST_TEST_RUNNER]: runner,
[TEST_PARAMETERS]: testParameters,
[TEST_FRAMEWORK_VERSION]: frameworkVersion,
[TEST_SOURCE_START]: testStartLine
[TEST_FRAMEWORK_VERSION]: frameworkVersion
}
if (testStartLine) {
extraTags[TEST_SOURCE_START] = testStartLine
}

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