Fix regression with bun test not recursively scanning the directory tree

This commit is contained in:
Jarred Sumner
2023-05-09 14:56:39 -07:00
parent ffd48dc7a7
commit ff1edca9ee
6 changed files with 36 additions and 10 deletions

View File

@@ -729,6 +729,7 @@ pub const VirtualMachine = struct {
existing_bundle: ?*NodeModuleBundle,
_log: ?*logger.Log,
env_loader: ?*DotEnv.Loader,
store_fd: bool,
) !*VirtualMachine {
var log: *logger.Log = undefined;
if (_log) |__log| {
@@ -748,7 +749,6 @@ pub const VirtualMachine = struct {
existing_bundle,
env_loader,
);
var vm = VMHolder.vm.?;
vm.* = VirtualMachine{
@@ -781,6 +781,7 @@ pub const VirtualMachine = struct {
vm.event_loop = &vm.regular_event_loop;
vm.bundler.macro_context = null;
vm.bundler.resolver.store_fd = store_fd;
vm.bundler.resolver.onWakePackageManager = .{
.context = &vm.modules,

View File

@@ -58,7 +58,14 @@ pub const Run = struct {
}
run = .{
.vm = try VirtualMachine.init(arena.allocator(), ctx.args, null, ctx.log, null),
.vm = try VirtualMachine.init(
arena.allocator(),
ctx.args,
null,
ctx.log,
null,
ctx.debug.hot_reload != .none,
),
.file = file,
.arena = arena,
.ctx = ctx,
@@ -93,8 +100,6 @@ pub const Run = struct {
b.options.macro_remap = macros;
}
b.resolver.store_fd = ctx.debug.hot_reload != .none;
b.configureRouter(false) catch {
if (Output.enable_ansi_colors_stderr) {
vm.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), true) catch {};

View File

@@ -252,6 +252,7 @@ const Scanner = struct {
if (@as(FileSystem.RealFS.EntriesOption.Tag, root.*) == .entries) {
var iter = root.entries.data.iterator();
const fd = root.entries.fd;
std.debug.assert(fd != 0);
while (iter.next()) |entry| {
this.next(entry.value_ptr.*, fd);
}
@@ -260,6 +261,8 @@ const Scanner = struct {
while (this.dirs_to_scan.readItem()) |entry| {
var dir = std.fs.Dir{ .fd = entry.relative_dir };
std.debug.assert(dir.fd != 0);
var parts2 = &[_]string{ entry.dir_path, entry.name.slice() };
var path2 = this.fs.absBuf(parts2, &this.open_dir_buf);
this.open_dir_buf[path2.len] = 0;
@@ -400,10 +403,21 @@ pub const TestCommand = struct {
js_ast.Expr.Data.Store.create(default_allocator);
js_ast.Stmt.Data.Store.create(default_allocator);
var vm = try JSC.VirtualMachine.init(ctx.allocator, ctx.args, null, ctx.log, env_loader);
var vm = try JSC.VirtualMachine.init(
ctx.allocator,
ctx.args,
null,
ctx.log,
env_loader,
// we must store file descriptors because we reuse them for
// iterating through the directory tree recursively
//
// in the future we should investigate if refactoring this to not
// rely on the dir fd yields a performance improvement
true,
);
vm.argv = ctx.passthrough;
vm.preload = ctx.preloads;
vm.bundler.resolver.store_fd = true;
try vm.bundler.configureDefines();
vm.bundler.options.rewrite_jest_for_tests = true;

View File

@@ -1470,6 +1470,7 @@ pub const RequestContext = struct {
null,
handler.log,
handler.env_loader,
true,
) catch |err| {
handler.handleJSError(.create_vm, err) catch {};
javascript_disabled = true;

View File

@@ -9519,7 +9519,14 @@ pub const Macro = struct {
resolver.opts.transform_options.node_modules_bundle_path = null;
resolver.opts.transform_options.node_modules_bundle_path_server = null;
defer resolver.opts.transform_options = old_transform_options;
var _vm = try JavaScript.VirtualMachine.init(default_allocator, resolver.opts.transform_options, null, log, env);
var _vm = try JavaScript.VirtualMachine.init(
default_allocator,
resolver.opts.transform_options,
null,
log,
env,
false,
);
_vm.enableMacroMode();
_vm.eventLoop().ensureWaker();

View File

@@ -2612,9 +2612,7 @@ pub const Resolver = struct {
if (in_place) |existing| {
existing.data.clearAndFree(allocator);
}
if (!r.store_fd) {
new_entry.fd = 0;
}
new_entry.fd = if (r.store_fd) open_dir.dir.fd else 0;
var dir_entries_ptr = in_place orelse allocator.create(Fs.FileSystem.DirEntry) catch unreachable;
dir_entries_ptr.* = new_entry;
dir_entries_option = try rfs.entries.put(&cached_dir_entry_result, .{