Skip to content

Commit

Permalink
fix(instrumenter): 🐛 fix break of Karma process on error thrown in te…
Browse files Browse the repository at this point in the history
…st/src

fix #226
  • Loading branch information
kopach committed Sep 21, 2020
1 parent 9894629 commit cfc48c3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/instrumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ function getListOfFilesToCover(coverageReporterConfig: PublicAPI): string[] {

function addFileListToCoverageData(
filesToCover: string[],
coverage: CoverageData
coverage?: CoverageData
): void {
filesToCover.forEach((filePath: string): void => {
if (!coverage) return;

const fullFilePath: string = path.resolve(process.cwd(), filePath);

if (!coverage[fullFilePath]) {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/typescript/test/test-error.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* tslint:disable */

describe('Foo', () => {
it('should throw error', () => {
throw new Error('Unexpected error in test');
});
});
42 changes: 42 additions & 0 deletions test/reporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,48 @@ describe('karma-sabarivka-reporter:', () => {
});
});

it('should not break Karma process on thrown exception in tests', done => {
// given
const config= {
coverageReporter: {
include: 'test/**/ignored-file.ts',
},
};
const coverageReportDir = join(
OUTPUT_PATH,
`coverage${generate()}`
);
const server = createServer(
{
reporters: ['sabarivka', coverageReporter],
coverageIstanbulReporter: {
reports: ['json-summary'],
dir: coverageReportDir,
},
coverageReporter: {
...config.coverageReporter,
type: 'json-summary',
dir: coverageReportDir,
subdir: '.',
},
files: [
'fixtures/typescript/test/test-error.spec.ts',
],
preprocessors: {
'fixtures/typescript/test/test-error.spec.ts': ['webpack', 'sourcemap'],
},
},
undefined,
true
);

// when
const karmaStart = (server.start() as unknown) as Promise<void>;

// then
checkKarmaSuccessOutput(server, karmaStart, done);
});

describe('Correct config:', () => {
[
{
Expand Down

0 comments on commit cfc48c3

Please sign in to comment.