Compare commits

...

3 Commits

Author SHA1 Message Date
Dylan Conway
0f94115678 Merge branch 'main' into dylan/missing-snapshot-in-ci 2025-05-12 10:57:01 -07:00
Dylan Conway
5f74474097 Merge branch 'main' into dylan/missing-snapshot-in-ci 2025-03-28 00:08:54 -07:00
Dylan Conway
69a78ed172 check for ci 2025-03-28 00:07:23 -07:00
3 changed files with 21 additions and 21 deletions

View File

@@ -2957,11 +2957,16 @@ pub const Expect = struct {
var formatter = JSC.ConsoleObject.Formatter{ .globalThis = globalThis };
defer formatter.deinit();
const test_file_path = Jest.runner.?.files.get(this.testScope().?.describe.file_id).source.path.text;
Jest.runner.?.snapshots.failed += 1;
return switch (err) {
error.FailedToOpenSnapshotFile => globalThis.throw("Failed to open snapshot file for test file: {s}", .{test_file_path}),
error.FailedToMakeSnapshotDirectory => globalThis.throw("Failed to make snapshot directory for test file: {s}", .{test_file_path}),
error.FailedToWriteSnapshotFile => globalThis.throw("Failed write to snapshot file: {s}", .{test_file_path}),
error.SyntaxError, error.ParseError => globalThis.throw("Failed to parse snapshot file for: {s}", .{test_file_path}),
error.OutOfMemory => globalThis.throwOutOfMemory(),
error.NewSnapshotInCI => {
return globalThis.throw("Missing snapshot in CI", .{});
},
else => globalThis.throw("Failed to snapshot value: {any}", .{value.toFmt(&formatter)}),
};
};

View File

@@ -14,6 +14,8 @@ const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const VirtualMachine = JSC.VirtualMachine;
const Expect = @import("./expect.zig").Expect;
const OOM = bun.OOM;
const detectCI = bun.detectCI;
pub const Snapshots = struct {
const file_header = "// Bun Snapshot v1, https://goo.gl/fbAQLP\n";
@@ -97,6 +99,10 @@ pub const Snapshots = struct {
return expected;
}
if (bun.detectCI() != null) {
return error.NewSnapshotInCI;
}
// doesn't exist. append to file bytes and add to hashmap.
const estimated_length = "\nexports[`".len + name_with_counter.len + "`] = `".len + target_value.len + "`;\n".len;
try this.file_buf.ensureUnusedCapacity(estimated_length + 10);
@@ -210,7 +216,7 @@ pub const Snapshots = struct {
}
}
pub fn addInlineSnapshotToWrite(self: *Snapshots, file_id: TestRunner.File.ID, value: InlineSnapshotToWrite) !void {
pub fn addInlineSnapshotToWrite(self: *Snapshots, file_id: TestRunner.File.ID, value: InlineSnapshotToWrite) OOM!void {
const gpres = try self.inline_snapshots_to_write.getOrPut(file_id);
if (!gpres.found_existing) {
gpres.value_ptr.* = std.ArrayList(InlineSnapshotToWrite).init(self.allocator);

View File

@@ -9,15 +9,8 @@ const std = @import("std");
const bun = @import("bun");
const strings = bun.strings;
var ci_name: ?[]const u8 = null;
pub fn detectCI() ?[]const u8 {
const ci = ci_name orelse ci_name: {
CI.once.call();
break :ci_name ci_name.?;
};
return if (ci.len == 0) null else ci;
return CI.once.call(.{});
}
const CI = enum {
@@ -72,22 +65,18 @@ const CI = enum {
@"xcode-cloud",
@"xcode-server",
pub var once = std.once(struct {
pub fn once() void {
var name: []const u8 = "";
defer ci_name = name;
pub var once = bun.once(struct {
pub fn once() ?[]const u8 {
if (bun.getenvZ("CI")) |ci| {
if (strings.eqlComptime(ci, "false")) {
return;
return null;
}
}
// Special case Heroku
if (bun.getenvZ("NODE")) |node| {
if (strings.containsComptime(node, "/app/.heroku/node/bin/node")) {
name = "heroku";
return;
return "heroku";
}
}
@@ -101,8 +90,7 @@ const CI = enum {
if (value.len == 0 or bun.strings.eqlLong(env, value, true)) {
if (!any) continue :pairs;
name = @tagName(Array.Indexer.keyForIndex(i));
return;
return @tagName(Array.Indexer.keyForIndex(i));
}
}
@@ -110,10 +98,11 @@ const CI = enum {
}
if (!any) {
name = @tagName(Array.Indexer.keyForIndex(i));
return;
return @tagName(Array.Indexer.keyForIndex(i));
}
}
return null;
}
}.once);