Skip to content

Commit

Permalink
Fixes #4020
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Aug 7, 2023
1 parent 3185ca2 commit 04925bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/bunfig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,27 @@ pub const Bunfig = struct {
this.ctx.test_options.coverage.fractions.functions = expr.data.e_number.value;
this.ctx.test_options.coverage.fractions.lines = expr.data.e_number.value;
this.ctx.test_options.coverage.fractions.stmts = expr.data.e_number.value;
this.ctx.test_options.coverage.fail_on_low_coverage = true;
break :outer;
}

try this.expect(expr, .e_object);
if (expr.get("functions")) |functions| {
try this.expect(functions, .e_number);
this.ctx.test_options.coverage.fractions.functions = functions.data.e_number.value;
this.ctx.test_options.coverage.fail_on_low_coverage = true;
}

if (expr.get("lines")) |lines| {
try this.expect(lines, .e_number);
this.ctx.test_options.coverage.fractions.lines = lines.data.e_number.value;
this.ctx.test_options.coverage.fail_on_low_coverage = true;
}

if (expr.get("statements")) |stmts| {
try this.expect(stmts, .e_number);
this.ctx.test_options.coverage.fractions.stmts = stmts.data.e_number.value;
this.ctx.test_options.coverage.fail_on_low_coverage = true;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/cli/test_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ pub const TestCommand = struct {
fractions: bun.sourcemap.CoverageFraction = .{},
ignore_sourcemap: bool = false,
enabled: bool = false,
fail_on_low_coverage: bool = false,
};

pub fn exec(ctx: Command.Context) !void {
Expand Down Expand Up @@ -842,7 +843,7 @@ pub const TestCommand = struct {
}
}

if (reporter.summary.fail > 0 or (coverage.enabled and coverage.fractions.failing)) {
if (reporter.summary.fail > 0 or (coverage.enabled and coverage.fractions.failing and coverage.fail_on_low_coverage)) {
Global.exit(1);
}
}
Expand Down

0 comments on commit 04925bb

Please sign in to comment.