-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5021cc
commit b89eaac
Showing
8 changed files
with
156 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
packages/dd-trace/src/ci-visibility/exporters/jest-worker/index.js
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict' | ||
|
||
const Writer = require('./writer') | ||
const { | ||
JEST_WORKER_COVERAGE_PAYLOAD_CODE, | ||
JEST_WORKER_TRACE_PAYLOAD_CODE, | ||
CUCUMBER_WORKER_TRACE_PAYLOAD_CODE | ||
} = require('../../../plugins/util/test') | ||
|
||
function getInterprocessTraceCode () { | ||
if (process.env.JEST_WORKER_ID) { | ||
return JEST_WORKER_TRACE_PAYLOAD_CODE | ||
} | ||
if (process.env.CUCUMBER_WORKER_ID) { | ||
return CUCUMBER_WORKER_TRACE_PAYLOAD_CODE | ||
} | ||
return null | ||
} | ||
|
||
// TODO: make it available with cucumber | ||
function getInterprocessCoverageCode () { | ||
if (process.env.JEST_WORKER_ID) { | ||
return JEST_WORKER_COVERAGE_PAYLOAD_CODE | ||
} | ||
return null | ||
} | ||
|
||
/** | ||
* Lightweight exporter whose writers only do simple JSON serialization | ||
* of trace and coverage payloads, which they send to the test framework's main process. | ||
* Currently used by Jest and Cucumber workers. | ||
*/ | ||
class TestWorkerCiVisibilityExporter { | ||
constructor () { | ||
const interprocessTraceCode = getInterprocessTraceCode() | ||
const interprocessCoverageCode = getInterprocessCoverageCode() | ||
|
||
this._writer = new Writer(interprocessTraceCode) | ||
this._coverageWriter = new Writer(interprocessCoverageCode) | ||
} | ||
|
||
export (payload) { | ||
this._writer.append(payload) | ||
} | ||
|
||
exportCoverage (formattedCoverage) { | ||
this._coverageWriter.append(formattedCoverage) | ||
} | ||
|
||
flush () { | ||
this._writer.flush() | ||
this._coverageWriter.flush() | ||
} | ||
} | ||
|
||
module.exports = TestWorkerCiVisibilityExporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
packages/dd-trace/test/ci-visibility/exporters/jest-worker/exporter.spec.js
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
packages/dd-trace/test/ci-visibility/exporters/test-worker/exporter.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict' | ||
|
||
require('../../../../../dd-trace/test/setup/tap') | ||
|
||
const TestWorkerCiVisibilityExporter = require('../../../../src/ci-visibility/exporters/test-worker') | ||
const { | ||
JEST_WORKER_TRACE_PAYLOAD_CODE, | ||
JEST_WORKER_COVERAGE_PAYLOAD_CODE, | ||
CUCUMBER_WORKER_TRACE_PAYLOAD_CODE | ||
} = require('../../../../src/plugins/util/test') | ||
|
||
describe('CI Visibility Test Worker Exporter', () => { | ||
let send, originalSend | ||
beforeEach(() => { | ||
send = sinon.spy() | ||
originalSend = process.send | ||
process.send = send | ||
}) | ||
afterEach(() => { | ||
process.send = originalSend | ||
}) | ||
context('when the process is a jest worker', () => { | ||
beforeEach(() => { | ||
process.env.JEST_WORKER_ID = '1' | ||
}) | ||
afterEach(() => { | ||
delete process.env.JEST_WORKER_ID | ||
}) | ||
it('can export traces', () => { | ||
const trace = [{ type: 'test' }] | ||
const traceSecond = [{ type: 'test', name: 'other' }] | ||
const jestWorkerExporter = new TestWorkerCiVisibilityExporter() | ||
jestWorkerExporter.export(trace) | ||
jestWorkerExporter.export(traceSecond) | ||
jestWorkerExporter.flush() | ||
expect(send).to.have.been.calledWith([JEST_WORKER_TRACE_PAYLOAD_CODE, JSON.stringify([trace, traceSecond])]) | ||
}) | ||
it('can export coverages', () => { | ||
const coverage = { sessionId: '1', suiteId: '1', files: ['test.js'] } | ||
const coverageSecond = { sessionId: '2', suiteId: '2', files: ['test2.js'] } | ||
const jestWorkerExporter = new TestWorkerCiVisibilityExporter() | ||
jestWorkerExporter.exportCoverage(coverage) | ||
jestWorkerExporter.exportCoverage(coverageSecond) | ||
jestWorkerExporter.flush() | ||
expect(send).to.have.been.calledWith( | ||
[JEST_WORKER_COVERAGE_PAYLOAD_CODE, JSON.stringify([coverage, coverageSecond])] | ||
) | ||
}) | ||
it('does not break if process.send is undefined', () => { | ||
delete process.send | ||
const trace = [{ type: 'test' }] | ||
const jestWorkerExporter = new TestWorkerCiVisibilityExporter() | ||
jestWorkerExporter.export(trace) | ||
jestWorkerExporter.flush() | ||
expect(send).not.to.have.been.called | ||
}) | ||
}) | ||
context('when the process is a cucumber worker', () => { | ||
beforeEach(() => { | ||
process.env.CUCUMBER_WORKER_ID = '1' | ||
}) | ||
afterEach(() => { | ||
delete process.env.CUCUMBER_WORKER_ID | ||
}) | ||
it('can export traces', () => { | ||
debugger | ||
const trace = [{ type: 'test' }] | ||
const traceSecond = [{ type: 'test', name: 'other' }] | ||
const cucumberWorkerExporter = new TestWorkerCiVisibilityExporter() | ||
cucumberWorkerExporter.export(trace) | ||
cucumberWorkerExporter.export(traceSecond) | ||
cucumberWorkerExporter.flush() | ||
expect(send).to.have.been.calledWith([CUCUMBER_WORKER_TRACE_PAYLOAD_CODE, JSON.stringify([trace, traceSecond])]) | ||
}) | ||
it('does not break if process.send is undefined', () => { | ||
delete process.send | ||
const trace = [{ type: 'test' }] | ||
const cucumberWorkerExporter = new TestWorkerCiVisibilityExporter() | ||
cucumberWorkerExporter.export(trace) | ||
cucumberWorkerExporter.flush() | ||
expect(send).not.to.have.been.called | ||
}) | ||
}) | ||
}) |