timkindberg / jest-when

Jest support for mock argument-matched return values.
MIT License
734 stars 38 forks source link

Run time error Node v14.17.0 #75

Closed muratakburak closed 3 years ago

muratakburak commented 3 years ago

I have used jest-when library to mock reading of a specific file like below when(mockedReadFileSync).calledWith(path.resolve(__dirname, "./../../assets/settings.json"), { encoding: "utf-8" }).mockReturnValue(JSON.stringify(settingsFileContent));

It has been almost a week since I used the library in my project but is started throwing errors today. I've searched about it but only found some records about gulp.

Here is my task in vscode. When I run it, it gives me error below. Never fails when I comment out the only line of code that I use jest-when. Seemed like a version issue after I read the discussions about gulp but I am not sure. Any help is appreciated.

{
    "type": "node",
    "request": "launch",
    "name": "Launch jest",
    "program": "${workspaceFolder}/node_modules/.bin/jest",
        "windows": {
                "program": "${workspaceFolder}/node_modules/jest/bin/jest",
         },
    "args": ["--detectOpenHandles", "--watch"],
    "outputCapture": "std",
    "autoAttachChildProcesses": true,
    "outFiles": ["${workspaceFolder}/out/**/*.js"],
        "preLaunchTask": "build"
}
 RUNS  src/__tests__/app.test.ts
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe[24464]: c:\ws\src\node_contextify.cc:1035: Assertion `args[0]->IsString()' failed.
 1: 00007FF7003C3E0F napi_wrap+108911
 2: 00007FF700367E16 v8::base::CPU::has_sse+61910
 3: 00007FF700368191 v8::base::CPU::has_sse+62801
 4: 00007FF70037297A node::OnFatalError+40330
 5: 00007FF700BEDDCF v8::internal::Builtins::builtin_handle+321711       
 6: 00007FF700BED364 v8::internal::Builtins::builtin_handle+319044       
 7: 00007FF700BED657 v8::internal::Builtins::builtin_handle+319799       
 8: 00007FF700BED4A3 v8::internal::Builtins::builtin_handle+319363       
 9: 00007FF700CC9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
10: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498 
11: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498 
12: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498 
13: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498 
14: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498 
15: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498 
16: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
17: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
18: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
19: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
20: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
21: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
22: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
23: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
24: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
25: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
26: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
27: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
28: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
29: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
30: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
31: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
32: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
33: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
34: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
35: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
36: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
37: 00007FF700C8F2C0 v8::internal::SetupIsolateDelegate::SetupHeap+225376
38: 00007FF700D0BE1E v8::internal::SetupIsolateDelegate::SetupHeap+736190
39: 00007FF700C8233D v8::internal::SetupIsolateDelegate::SetupHeap+172253
40: 00007FF700C5FC3C v8::internal::SetupIsolateDelegate::SetupHeap+31196
41: 00007FF700B2FB7F v8::internal::Execution::CallWasm+1839
42: 00007FF700B2FC8B v8::internal::Execution::CallWasm+2107
43: 00007FF700B306CA v8::internal::Execution::TryCall+378
44: 00007FF700B10CE5 v8::internal::MicrotaskQueue::RunMicrotasks+501
45: 00007FF700B10A40 v8::internal::MicrotaskQueue::PerformCheckpoint+32
46: 00007FF700BEDDCF v8::internal::Builtins::builtin_handle+321711
47: 00007FF700BED364 v8::internal::Builtins::builtin_handle+319044
48: 00007FF700BED657 v8::internal::Builtins::builtin_handle+319799
49: 00007FF700BED4A3 v8::internal::Builtins::builtin_handle+319363
50: 00007FF700CC9C8D v8::internal::SetupIsolateDelegate::SetupHeap+465453
51: 00007FF700C62092 v8::internal::SetupIsolateDelegate::SetupHeap+40498
52: 00007FF700C5FD4E v8::internal::SetupIsolateDelegate::SetupHeap+31470
53: 00007FF700C5F93C v8::internal::SetupIsolateDelegate::SetupHeap+30428
54: 00007FF700B2FAC1 v8::internal::Execution::CallWasm+1649
55: 00007FF700B2F32F v8::internal::Execution::Call+191
56: 00007FF700C1AEA7 v8::Function::Call+615
57: 00007FF7003F0C04 node::CallbackScope::~CallbackScope+868
58: 00007FF7003F0F7B node::CallbackScope::~CallbackScope+1755
59: 00007FF7003E8B74 v8::internal::compiler::Operator::EffectOutputCount+228
60: 00007FF700294F1F v8::internal::Isolate::isolate_root_bias+35119
61: 00007FF70040FFBE uv_process_kill+302
62: 00007FF700420CE9 uv_loop_init+1337
63: 00007FF700420E5A uv_run+202
64: 00007FF700322CD5 v8::internal::OrderedHashTable<v8::internal::OrderedHashSet,1>::NumberOfBucketsOffset+9365
65: 00007FF700396F37 node::Start+311
66: 00007FF7001F677C RC4_options+339580
67: 00007FF7011B874C v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+152316
68: 00007FFE61057034 BaseThreadInitThunk+20
69: 00007FFE611A2651 RtlUserThreadStart+33
timkindberg commented 3 years ago

Hmm I have no idea... that's not a very helpful stack unfortunately. I'm not sure where I'd start to help here. If you make a small repo recreating the bug I could spin it up, but I'm on a Mac and it looks like you are on Windows, so not sure if it will happen on my Mac. But I'd try.

In the meantime can you try a sanity test by adding this test to your suite (comment all other jest.when usages):

it('works with basic args and return', () => {
  const fn = jest.fn()
  when(fn).calledWith(1).mockReturnValue('success')
  expect(fn(1)).toEqual('success')
})
muratakburak commented 3 years ago

I couldn't reproduce with running only one test you provided which is the only place where jest-when is used. I can try to create a small repo that you can try to repro but maybe after a week.

muratakburak commented 3 years ago

Hi @timkindberg can you check this repo https://github.com/muratakburak/jest-when-crash It also happens with this one.

timkindberg commented 3 years ago

🤔 Hmm I ran it and it worked. I really am not sure what the issue might be here. The stack trace is nothing I've seen before. It seems related to the Node V8 Engine, which makes me think maybe it's related to Windows Node?? I really don't know.

image

muratakburak commented 3 years ago

Ok, thanks. Looks like I'll have to look for an alternative to get desired behaviour. Any suggestions? Or maybe I can post it somewhere else?

timkindberg commented 3 years ago

I'd recommend stack overflow.