This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsonReporter): implement first iteration of json reports
- Loading branch information
Nick Schmidt
committed
Feb 11, 2019
1 parent
1d8ec88
commit 23f7f83
Showing
4 changed files
with
54 additions
and
0 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
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,36 @@ | ||
const report = { | ||
filesCoverage: [], | ||
coverage: 100, | ||
coverageSatisfied: true, | ||
flowPassed: true, | ||
config: { threshold: 90 }, | ||
} | ||
|
||
describe('jsonReporter', () => { | ||
beforeEach(() => { | ||
global.console = { log: () => {} } | ||
}) | ||
|
||
test('returns the right reporterName', () => { | ||
const reporter = require('../json') | ||
const response = reporter(report) | ||
|
||
expect(response.reporterName).toBe('json') | ||
}) | ||
|
||
test('returns valid stringified json', () => { | ||
const reporter = require('../json') | ||
const response = reporter(report) | ||
|
||
expect(() => JSON.parse(response.contents)).not.toThrow() | ||
expect(JSON.parse(response.contents).coverageSatisfied).toEqual(true) | ||
}) | ||
|
||
test('works with a pretty option', () => { | ||
const reporter = require('../json') | ||
const response = reporter({ ...report, config: { ...report.config, pretty: true } }) | ||
|
||
expect(() => JSON.parse(response.contents)).not.toThrow() | ||
expect(JSON.parse(response.contents).coverageSatisfied).toEqual(true) | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = function jsonReporter(report) { | ||
const contents = JSON.stringify(report, null, report.config.pretty ? 2 : 0) | ||
|
||
console.log(contents) | ||
|
||
return { | ||
reporterName: 'json', | ||
contents, | ||
} | ||
} |