-
Hi following https://vitest.dev/guide/snapshot.html#custom-serializer I have: // custom-serializer.ts
import type { SnapshotSerializer } from 'vitest'
export default {
serialize(_val, config, indentation, depth, refs, printer) {
return printer('simple string', config, indentation, depth, refs) // notice simple value
},
test() {
return true
},
} satisfies SnapshotSerializer // vitest.config.mjs
export default defineConfig({
test: {
plugins: [swc.vite({ module: { type: 'es6' } }), tsconfigPaths()],
snapshotSerializers: ['./custom-serializer.ts'],
...
}
} Now any running test will trigger an out of memory error: expect(res)toMatchSnapshot() <--- Last few GCs --->
[1828836:0x7fbe24000f00] 4079 ms: Scavenge 149.7 (171.1) -> 139.3 (172.1) MB, 1.71 / 0.00 ms (average mu = 0.995, current mu = 0.997) allocation failure;
[1828836:0x7fbe24000f00] 4436 ms: Scavenge 154.9 (175.2) -> 145.0 (178.7) MB, 1.95 / 0.01 ms (average mu = 0.995, current mu = 0.997) allocation failure;
[1828836:0x7fbe24000f00] 4514 ms: Scavenge 158.8 (179.5) -> 147.8 (182.7) MB, 1.43 / 0.01 ms (average mu = 0.995, current mu = 0.997) task;
<--- JS stacktrace --->
FATAL ERROR: RegExpCompiler Allocation failed - process out of memory
----- Native stack trace -----
1: 0xb84bd6 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node (vitest)]
2: 0xefec30 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node (vitest)]
3: 0xefef17 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node (vitest)]
4: 0x14fc958 [node (vitest)]
5: 0x14eaaf0 v8::internal::RegExpAlternative::ToNode(v8::internal::RegExpCompiler*, v8::internal::RegExpNode*) [node (vitest)]
6: 0x14e8ef9 v8::internal::RegExpCapture::ToNode(v8::internal::RegExpTree*, int, v8::internal::RegExpCompiler*, v8::internal::RegExpNode*) [node (vitest)]
7: 0x14fe6bd v8::internal::RegExpCompiler::PreprocessRegExp(v8::internal::RegExpCompileData*, v8::base::Flags<v8::internal::RegExpFlag, int>, bool) [node (vitest)]
8: 0x15226cf v8::internal::RegExpImpl::Compile(v8::internal::Isolate*, v8::internal::Zone*, v8::internal::RegExpCompileData*, v8::base::Flags<v8::internal::RegExpFlag, int>, v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::String>, bool, unsigned int&) [node (vitest)]
9: 0x1522fd6 v8::internal::RegExpImpl::CompileIrregexp(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>, bool) [node (vitest)]
10: 0x1523b97 v8::internal::RegExpImpl::IrregexpPrepare(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>) [node (vitest)]
11: 0x1523cd0 v8::internal::RegExpImpl::IrregexpExec(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSRegExp>, v8::internal::Handle<v8::internal::String>, int, v8::internal::Handle<v8::internal::RegExpMatchInfo>, v8::internal::RegExp::ExecQuirks) [node (vitest)]
12: 0x154c835 v8::internal::Runtime_StringReplaceNonGlobalRegExpWithFunction(int, unsigned long*, v8::internal::Isolate*) [node (vitest)]
13: 0x1971ef6 [node (vitest)]
Aborted (core dumped) When directly returning a value from The same also happens when directly adding the serializer in the test: expect.addSnapshotSerializer({
serialize(val, config, indentation, depth, refs, printer) {
return printer('simple string', config, indentation, depth, refs) // notice simple value
},
test(val) {
return !!val
},
})
expect(res).toMatchSnapshot() // same error Am I missing something? Thanks for your answers. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
If I remember, I assume your example is just for the sake of crash and wouldn't be useful anyway. Can you show what you were trying to do in the first place (which probably lead you to discover something odd like this)? I think I got this loop myself in the past when making custom snapshot, so maybe it's worth adding some notes in the doc, but I think it's somewhat "obvious" that'll happen, so I'm not sure what's the better way to explain it. |
Beta Was this translation helpful? Give feedback.
For this need, introducing a simple wrapper might help, something like this:
https://stackblitz.com/edit/vitest-dev-vitest-w9sfer?file=test%2Frepro.test.ts