diff --git a/src/bunfig.zig b/src/bunfig.zig index e1f1ca4b07142f..050c603deff34e 100644 --- a/src/bunfig.zig +++ b/src/bunfig.zig @@ -253,6 +253,7 @@ 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; } @@ -260,16 +261,19 @@ pub const Bunfig = struct { 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; } } diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index c4d78f4d5df1a1..3a9411e089bc80 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -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 { @@ -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); } }