Skip to content

Commit

Permalink
Merge branch 'main' into sm/core7-jsforce-node
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale authored Apr 22, 2024
2 parents 9c0c6c0 + 95fb994 commit d8c2805
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/streaming/testResultStringifyStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export class TestResultStringifyStream extends Readable {
}
});

this.push('],');
this.push(']');
}

@elapsedTime()
buildCodeCoverage(): void {
if (this.testResult.codecoverage) {
this.push('"codecoverage":[');
this.push(',"codecoverage":[');
const numberOfCodeCoverage = this.testResult.codecoverage.length - 1;
this.testResult.codecoverage.forEach((coverage, index) => {
const { coveredLines, uncoveredLines, ...theRest } = coverage;
Expand Down
43 changes: 36 additions & 7 deletions test/streaming/testResultStringifyStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,58 @@ describe('TestResultStringifyStream', () => {
};
});

it('should transform TestResult into a JSON string with no tests and no coverage', (done) => {
it('should transform TestResult into a JSON string with empty tests and no coverage', (done) => {
let output = '';
const emptyTestsNoCoverage = structuredClone(testResult);
delete emptyTestsNoCoverage.codecoverage;
// Initialize the stream with the testResult
stream = new TestResultStringifyStream(testResult);
stream = new TestResultStringifyStream(emptyTestsNoCoverage);

stream.on('data', (chunk: string) => {
output += chunk;
});

stream.on('end', () => {
const expectedOutput = JSON.stringify(testResult);
expect(() => JSON.parse(output)).to.not.throw();
const expectedOutput = JSON.stringify(emptyTestsNoCoverage);
expect(output).to.equal(expectedOutput);
done();
});

stream._read();
});
it('should transform TestResult into a JSON string', (done) => {
it('should transform TestResult into a JSON string with tests and no coverage', (done) => {
let output = '';
tests[0].perClassCoverage = [perClassCoverageData[0]];
tests[1].perClassCoverage = perClassCoverageData;
const testsWithoutCoverage = structuredClone(tests);
const resultsWithTests = {
...testResult,
tests,
tests: testsWithoutCoverage
};
delete resultsWithTests.codecoverage;
// Initialize the stream with the testResult
stream = new TestResultStringifyStream(resultsWithTests);

stream.on('data', (chunk: string) => {
output += chunk;
});

stream.on('end', () => {
expect(() => JSON.parse(output)).to.not.throw();
const expectedOutput = JSON.stringify(resultsWithTests);
expect(output).to.equal(expectedOutput);
done();
});

stream._read();
});
it('should transform TestResult into a JSON string with tests and coverage both present', (done) => {
let output = '';
const testsWithCoverage = structuredClone(tests);
testsWithCoverage[0].perClassCoverage = [perClassCoverageData[0]];
testsWithCoverage[1].perClassCoverage = perClassCoverageData;
const resultsWithTests = {
...testResult,
tests: testsWithCoverage,
codecoverage: coverageData
};
// Initialize the stream with the testResult
Expand All @@ -170,6 +198,7 @@ describe('TestResultStringifyStream', () => {
});

stream.on('end', () => {
expect(() => JSON.parse(output)).to.not.throw();
const expectedOutput = JSON.stringify(resultsWithTests);
expect(output).to.equal(expectedOutput);
done();
Expand Down

0 comments on commit d8c2805

Please sign in to comment.