mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 05:12:29 +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:
@@ -292,9 +292,7 @@ export function generateHashTable(nameToUse, symbolName, typeName, obj, props =
|
||||
// { "CLOSED"_s, JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::ConstantInteger, NoIntrinsic, { HashTableValue::ConstantType, 3 } },
|
||||
// };
|
||||
return `
|
||||
static const HashTableValue ${nameToUse}TableValues[] = {
|
||||
${rows.join(" ,\n")}
|
||||
};
|
||||
static const HashTableValue ${nameToUse}TableValues[] = {${rows.length > 0 ? "\n" + rows.join(" ,\n") + "\n" : ""}};
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -348,7 +346,11 @@ ${renderFieldsImpl(protoSymbolName, typeName, obj, protoFields, obj.values || []
|
||||
void ${proto}::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject)
|
||||
{
|
||||
Base::finishCreation(vm);
|
||||
reifyStaticProperties(vm, ${className(typeName)}::info(), ${proto}TableValues, *this);${specialSymbols}
|
||||
${
|
||||
Object.keys(protoFields).length > 0
|
||||
? `reifyStaticProperties(vm, ${className(typeName)}::info(), ${proto}TableValues, *this);`
|
||||
: ""
|
||||
}${specialSymbols}
|
||||
JSC_TO_STRING_TAG_WITHOUT_TRANSITION();
|
||||
}
|
||||
|
||||
@@ -1144,9 +1146,9 @@ function generateImpl(typeName, obj) {
|
||||
return [
|
||||
generatePrototypeHeader(typeName),
|
||||
!obj.noConstructor ? generateConstructorHeader(typeName).trim() + "\n" : null,
|
||||
Object.keys(proto).length > 0 && generatePrototype(typeName, obj).trim(),
|
||||
generatePrototype(typeName, obj).trim(),
|
||||
!obj.noConstructor ? generateConstructorImpl(typeName, obj).trim() : null,
|
||||
Object.keys(proto).length > 0 && generateClassImpl(typeName, obj).trim(),
|
||||
generateClassImpl(typeName, obj).trim(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
|
||||
Reference in New Issue
Block a user