mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Implement toMatchSnapshot() (#2294)
* buggy snapshot * error output for failed snapshot * missing first * hints * open dir once, better cleanup * update flag * truncate on update * object and class snapshot formatting * array formatting * no function name, single item is empty array * string objects, maps, sets, promise * avoid using invalid memory * handle number objects * handle extending `Number` * boolean objects * snapshot tests and test updates * snapshot format for buffers * safer snapshot parsing * property matchers setup * strings and tests * generate classes with empty prototype * optional `propertyMatchers` parameter * new test folder structure * strings.eqlLong * globalObject.throwPretty() and expect.any tests * add updateSnapshot flag to help * move snapshot format out of `printErrorlikeObject` * empty object snapshot format * separate typed array, remove trailing comma * use `isCell`, object trailing commas * handle unicode * todo for primitive constructors * switch to `JSC.Node.Syscall.open` and `JSC.Maybe` * use js parser for snapshot files * deinit ast, log parse error * copy/paste most of `exports.ZigConsoleClient` * remove snapshot option * remove ordered properties option * remove snapshot format option from `exports.zig` * remove extra newlines * change mode * update test runner output * escape backticks faster * `bunx jest` in temp dir * remove buffered writer * add `toMatchSnapshot` to types * cleanup, switch to `pread` * cli `--update` flag * `--update-snapshots` * remove string object format
This commit is contained in:
16
src/cli.zig
16
src/cli.zig
@@ -214,8 +214,14 @@ pub const Arguments = struct {
|
||||
clap.parseParam("--outdir <STR> Default to \"dist\" if multiple files") catch unreachable,
|
||||
};
|
||||
|
||||
// TODO: update test completions
|
||||
const test_only_params = [_]ParamType{
|
||||
clap.parseParam("--update-snapshots Update snapshot files") catch unreachable,
|
||||
};
|
||||
|
||||
const build_params_public = public_params ++ build_only_params;
|
||||
pub const build_params = build_params_public ++ debug_params;
|
||||
pub const test_params = params ++ test_only_params;
|
||||
|
||||
fn printVersionAndExit() noreturn {
|
||||
@setCold(true);
|
||||
@@ -368,6 +374,10 @@ pub const Arguments = struct {
|
||||
cwd = try std.process.getCwdAlloc(allocator);
|
||||
}
|
||||
|
||||
if (cmd == .TestCommand) {
|
||||
ctx.test_options.update_snapshots = args.flag("--update-snapshots");
|
||||
}
|
||||
|
||||
ctx.args.absolute_working_dir = cwd;
|
||||
ctx.positionals = args.positionals();
|
||||
|
||||
@@ -859,6 +869,10 @@ pub const Command = struct {
|
||||
test_directory: []const u8 = "",
|
||||
};
|
||||
|
||||
pub const TestOptions = struct {
|
||||
update_snapshots: bool = false,
|
||||
};
|
||||
|
||||
pub const Context = struct {
|
||||
start_time: i128,
|
||||
args: Api.TransformOptions,
|
||||
@@ -869,6 +883,7 @@ pub const Command = struct {
|
||||
install: ?*Api.BunInstall = null,
|
||||
|
||||
debug: DebugOptions = DebugOptions{},
|
||||
test_options: TestOptions = TestOptions{},
|
||||
|
||||
preloads: []const string = &[_]string{},
|
||||
has_loaded_global_config: bool = false,
|
||||
@@ -1418,6 +1433,7 @@ pub const Command = struct {
|
||||
pub fn params(comptime cmd: Tag) []const Arguments.ParamType {
|
||||
return &comptime switch (cmd) {
|
||||
Command.Tag.BuildCommand => Arguments.build_params,
|
||||
Command.Tag.TestCommand => Arguments.test_params,
|
||||
else => Arguments.params,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user