File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { program } from './program.js'
55import { read } from './file-reader.js'
66import { print as pretty } from './reporters/pretty.js'
77import { print as tap } from './reporters/tap.js'
8+ import { print as json } from './reporters/json.js'
89import { help } from './help.js'
910
1011async function cli ( cli_args : string [ ] ) {
@@ -30,8 +31,7 @@ async function cli(cli_args: string[]) {
3031 return tap ( report , params )
3132 }
3233 if ( params . reporter === 'json' ) {
33- let log = JSON . stringify ( report )
34- return report . report . ok ? console . log ( log ) : console . error ( log )
34+ return json ( report , params )
3535 }
3636 return pretty ( report , params )
3737}
Original file line number Diff line number Diff line change 1+ import type { CliArguments } from '../arguments.js'
2+ import type { Report } from '../program.js'
3+
4+ function prepare ( { report, context } : Report , params : CliArguments ) {
5+ context . coverage . coverage_per_stylesheet = context . coverage . coverage_per_stylesheet . filter ( ( sheet ) => {
6+ // Include if the user wanted min-file-coverage and this file coverage is too low
7+ if (
8+ params [ 'show-uncovered' ] === 'violations' &&
9+ report . min_file_line_coverage . expected !== undefined &&
10+ sheet . line_coverage_ratio < report . min_file_line_coverage . expected
11+ ) {
12+ return true
13+ }
14+
15+ // Include if show=all and coverage isn't 100%
16+ if ( params [ 'show-uncovered' ] === 'all' && sheet . line_coverage_ratio < 1 ) {
17+ return true
18+ }
19+
20+ // Skip the sheet if show=none or coverage is higher than requested
21+ return false
22+ } )
23+
24+ return {
25+ report,
26+ context,
27+ }
28+ }
29+
30+ export function print ( { report, context } : Report , params : CliArguments ) : void {
31+ let logger = report . ok ? console . log : console . error
32+ let data = prepare ( { context, report } , params )
33+ logger ( JSON . stringify ( data ) )
34+ }
You can’t perform that action at this time.
0 commit comments