Compare commits

...

1 Commits

Author SHA1 Message Date
Don Isaac
a21e095d13 refactor(bun:test): remove undefined struct field defaults 2025-04-20 15:58:41 -04:00
4 changed files with 18 additions and 27 deletions

View File

@@ -1359,7 +1359,7 @@ pub const EventLoopTimer = struct {
}
if (comptime t.Type() == JSC.Jest.TestRunner) {
container.onTestTimeout(now, vm);
container.onTestTimeout(now);
return .disarm;
}

View File

@@ -67,9 +67,8 @@ pub const TestRunner = struct {
bail: u32 = 0,
allocator: std.mem.Allocator,
callback: *Callback = undefined,
callback: *Callback,
drainer: JSC.AnyTask = undefined,
queue: std.fifo.LinearFifo(*TestRunnerTask, .{ .Dynamic = {} }) = std.fifo.LinearFifo(*TestRunnerTask, .{ .Dynamic = {} }).init(default_allocator),
has_pending_tests: bool = false,
@@ -87,7 +86,7 @@ pub const TestRunner = struct {
.tag = .TestRunner,
},
active_test_for_timeout: ?TestRunner.Test.ID = null,
test_options: *const bun.CLI.Command.TestOptions = undefined,
test_options: *const bun.CLI.Command.TestOptions,
global_callbacks: struct {
beforeAll: std.ArrayListUnmanaged(JSValue) = .{},
@@ -102,10 +101,7 @@ pub const TestRunner = struct {
unhandled_errors_between_tests: u32 = 0,
pub const Drainer = JSC.AnyTask.New(TestRunner, drain);
pub fn onTestTimeout(this: *TestRunner, now: *const bun.timespec, vm: *VirtualMachine) void {
_ = vm; // autofix
pub fn onTestTimeout(this: *TestRunner, now: *const bun.timespec) void {
this.event_loop_timer.state = .FIRED;
if (this.pending_test) |pending_test| {
@@ -115,15 +111,11 @@ pub const TestRunner = struct {
}
}
pub fn setTimeout(
this: *TestRunner,
milliseconds: u32,
test_id: TestRunner.Test.ID,
) void {
pub fn setTimeout(this: *TestRunner, ms: u32, test_id: Test.ID) void {
this.active_test_for_timeout = test_id;
if (milliseconds > 0) {
this.scheduleTimeout(milliseconds);
if (ms > 0) {
this.scheduleTimeout(ms);
}
}
@@ -247,7 +239,7 @@ pub const TestRunner = struct {
pub const File = struct {
source: logger.Source = logger.Source.initEmptyFile(""),
log: logger.Log = logger.Log.initComptime(default_allocator),
module_scope: *DescribeScope = undefined,
module_scope: *DescribeScope,
pub const List = std.MultiArrayList(File);
pub const ID = u32;

View File

@@ -1059,6 +1059,7 @@ pub const TestCommand = struct {
.bail = ctx.test_options.bail,
.filter_regex = ctx.test_options.test_filter_regex,
.filter_buffer = bun.MutableString.init(ctx.allocator, 0) catch unreachable,
.test_options = &ctx.test_options,
.snapshots = Snapshots{
.allocator = ctx.allocator,
.update_snapshots = ctx.test_options.update_snapshots,
@@ -1068,17 +1069,15 @@ pub const TestCommand = struct {
.inline_snapshots_to_write = &inline_snapshots_to_write,
},
},
.callback = undefined,
.callback = TestRunner.Callback{
.onUpdateCount = CommandLineReporter.handleUpdateCount,
.onTestStart = CommandLineReporter.handleTestStart,
.onTestPass = CommandLineReporter.handleTestPass,
.onTestFail = CommandLineReporter.handleTestFail,
.onTestSkip = CommandLineReporter.handleTestSkip,
.onTestTodo = CommandLineReporter.handleTestTodo,
},
};
reporter.callback = TestRunner.Callback{
.onUpdateCount = CommandLineReporter.handleUpdateCount,
.onTestStart = CommandLineReporter.handleTestStart,
.onTestPass = CommandLineReporter.handleTestPass,
.onTestFail = CommandLineReporter.handleTestFail,
.onTestSkip = CommandLineReporter.handleTestSkip,
.onTestTodo = CommandLineReporter.handleTestTodo,
};
reporter.repeat_count = @max(ctx.test_options.repeat_count, 1);
reporter.jest.callback = &reporter.callback;
jest.Jest.runner = &reporter.jest;
reporter.jest.test_options = &ctx.test_options;

View File

@@ -29,7 +29,7 @@ const words: Record<string, { reason: string; limit?: number; regex?: boolean }>
"== alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
"!= alloc.ptr": { reason: "The std.mem.Allocator context pointer can be undefined, which makes this comparison undefined behavior" },
[String.raw`: [a-zA-Z0-9_\.\*\?\[\]\(\)]+ = undefined,`]: { reason: "Do not default a struct field to undefined", limit: 242, regex: true },
[String.raw`: [a-zA-Z0-9_\.\*\?\[\]\(\)]+ = undefined,`]: { reason: "Do not default a struct field to undefined", limit: 239, regex: true },
"usingnamespace": { reason: "Zig deprecates this, and will not support it in incremental compilation.", limit: 19 },
"std.fs.Dir": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 180 },