dd-trace 4.0.0-pre-e22d438 → 4.0.0-pre-6961448

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "4.0.0-pre-e22d438",
3
+ "version": "4.0.0-pre-6961448",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -10,16 +10,13 @@ const {
10
10
  getTestSessionCommonTags,
11
11
  getTestModuleCommonTags,
12
12
  getTestSuiteCommonTags,
13
+ addIntelligentTestRunnerSpanTags,
13
14
  TEST_PARAMETERS,
14
15
  getCodeOwnersFileEntries,
15
16
  TEST_SESSION_ID,
16
17
  TEST_MODULE_ID,
17
18
  TEST_SUITE_ID,
18
19
  TEST_COMMAND,
19
- TEST_ITR_TESTS_SKIPPED,
20
- TEST_SESSION_CODE_COVERAGE_ENABLED,
21
- TEST_SESSION_ITR_SKIPPING_ENABLED,
22
- TEST_CODE_COVERAGE_LINES_TOTAL,
23
20
  TEST_BUNDLE
24
21
  } = require('../../dd-trace/src/plugins/util/test')
25
22
  const { COMPONENT } = require('../../dd-trace/src/constants')
@@ -83,14 +80,14 @@ class JestPlugin extends CiPlugin {
83
80
  testCodeCoverageLinesTotal
84
81
  }) => {
85
82
  this.testSessionSpan.setTag(TEST_STATUS, status)
86
- this.testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false')
87
- this.testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false')
88
- this.testSessionSpan.setTag(TEST_SESSION_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false')
89
-
90
- if (testCodeCoverageLinesTotal !== undefined) {
91
- this.testSessionSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal)
92
- }
93
83
  this.testModuleSpan.setTag(TEST_STATUS, status)
84
+
85
+ addIntelligentTestRunnerSpanTags(
86
+ this.testSessionSpan,
87
+ this.testModuleSpan,
88
+ { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled, testCodeCoverageLinesTotal }
89
+ )
90
+
94
91
  this.testModuleSpan.finish()
95
92
  this.testSessionSpan.finish()
96
93
  finishAllTraceSpans(this.testSessionSpan)
@@ -13,14 +13,12 @@ const {
13
13
  getTestSessionCommonTags,
14
14
  getTestModuleCommonTags,
15
15
  getTestSuiteCommonTags,
16
+ addIntelligentTestRunnerSpanTags,
16
17
  TEST_SUITE_ID,
17
18
  TEST_SESSION_ID,
18
19
  TEST_MODULE_ID,
19
20
  TEST_BUNDLE,
20
- TEST_COMMAND,
21
- TEST_ITR_TESTS_SKIPPED,
22
- TEST_SESSION_CODE_COVERAGE_ENABLED,
23
- TEST_SESSION_ITR_SKIPPING_ENABLED
21
+ TEST_COMMAND
24
22
  } = require('../../dd-trace/src/plugins/util/test')
25
23
  const { COMPONENT } = require('../../dd-trace/src/constants')
26
24
 
@@ -156,11 +154,14 @@ class MochaPlugin extends CiPlugin {
156
154
  if (this.testSessionSpan) {
157
155
  const { isSuitesSkippingEnabled, isCodeCoverageEnabled } = this.itrConfig || {}
158
156
  this.testSessionSpan.setTag(TEST_STATUS, status)
159
- this.testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false')
160
- this.testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false')
161
- this.testSessionSpan.setTag(TEST_SESSION_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false')
162
-
163
157
  this.testModuleSpan.setTag(TEST_STATUS, status)
158
+
159
+ addIntelligentTestRunnerSpanTags(
160
+ this.testSessionSpan,
161
+ this.testModuleSpan,
162
+ { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled }
163
+ )
164
+
164
165
  this.testModuleSpan.finish()
165
166
  this.testSessionSpan.finish()
166
167
  finishAllTraceSpans(this.testSessionSpan)
@@ -23,10 +23,18 @@ function withNoop (fn) {
23
23
  }
24
24
 
25
25
  function unsubscribeAll () {
26
- debugChannel.unsubscribe(onDebug)
27
- infoChannel.unsubscribe(onInfo)
28
- warnChannel.unsubscribe(onWarn)
29
- errorChannel.unsubscribe(onError)
26
+ if (debugChannel.hasSubscribers) {
27
+ debugChannel.unsubscribe(onDebug)
28
+ }
29
+ if (infoChannel.hasSubscribers) {
30
+ infoChannel.unsubscribe(onInfo)
31
+ }
32
+ if (warnChannel.hasSubscribers) {
33
+ warnChannel.unsubscribe(onWarn)
34
+ }
35
+ if (errorChannel.hasSubscribers) {
36
+ errorChannel.unsubscribe(onError)
37
+ }
30
38
  }
31
39
 
32
40
  function toggleSubscription (enable) {
@@ -50,6 +50,8 @@ const JEST_TEST_RUNNER = 'test.jest.test_runner'
50
50
  const TEST_ITR_TESTS_SKIPPED = '_dd.ci.itr.tests_skipped'
51
51
  const TEST_SESSION_ITR_SKIPPING_ENABLED = 'test_session.itr.tests_skipping.enabled'
52
52
  const TEST_SESSION_CODE_COVERAGE_ENABLED = 'test_session.code_coverage.enabled'
53
+ const TEST_MODULE_ITR_SKIPPING_ENABLED = 'test_module.itr.tests_skipping.enabled'
54
+ const TEST_MODULE_CODE_COVERAGE_ENABLED = 'test_module.code_coverage.enabled'
53
55
 
54
56
  const TEST_CODE_COVERAGE_LINES_TOTAL = 'test.codecov_lines_total'
55
57
 
@@ -84,9 +86,13 @@ module.exports = {
84
86
  TEST_MODULE_ID,
85
87
  TEST_SUITE_ID,
86
88
  TEST_ITR_TESTS_SKIPPED,
89
+ TEST_BUNDLE,
87
90
  TEST_SESSION_ITR_SKIPPING_ENABLED,
88
91
  TEST_SESSION_CODE_COVERAGE_ENABLED,
92
+ TEST_MODULE_ITR_SKIPPING_ENABLED,
93
+ TEST_MODULE_CODE_COVERAGE_ENABLED,
89
94
  TEST_CODE_COVERAGE_LINES_TOTAL,
95
+ addIntelligentTestRunnerSpanTags,
90
96
  getCoveredFilenamesFromCoverage,
91
97
  resetCoverage,
92
98
  mergeCoverage,
@@ -282,6 +288,26 @@ function getTestSuiteCommonTags (command, testFrameworkVersion, testSuite) {
282
288
  }
283
289
  }
284
290
 
291
+ function addIntelligentTestRunnerSpanTags (
292
+ testSessionSpan,
293
+ testModuleSpan,
294
+ { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled, testCodeCoverageLinesTotal }
295
+ ) {
296
+ testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false')
297
+ testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false')
298
+ testSessionSpan.setTag(TEST_SESSION_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false')
299
+
300
+ testModuleSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false')
301
+ testModuleSpan.setTag(TEST_MODULE_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false')
302
+ testModuleSpan.setTag(TEST_MODULE_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false')
303
+
304
+ // If suites have been skipped we don't want to report the total coverage, as it will be wrong
305
+ if (testCodeCoverageLinesTotal !== undefined && !isSuitesSkipped) {
306
+ testSessionSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal)
307
+ testModuleSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal)
308
+ }
309
+ }
310
+
285
311
  function getCoveredFilenamesFromCoverage (coverage) {
286
312
  const coverageMap = istanbul.createCoverageMap(coverage)
287
313