-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for React-testing-library #198
Comments
re: JSDOM, the next step here is to implement a The Another option is to submit a PR to JSDOM that leverages ShadowRealm instead of the |
We'll be tracking support for the |
@Electroid Can we keep this open to confirm that react-testing-library works once the vm module work is completed? |
Tested this with bun 0.5.8 and looks like the blocker isn't
I think bun just needs a way to load some kind of DOM library like Trying to import
Trying to import
|
- skipped tests requiring dom: oven-sh/bun#198
I'll be testing this out tmrw unless @EvHaus beats me to it. |
It uses kind of an insane hack where the context object's prototype becomes a special global object proxy (like window in browsers) Lmk if that breaks stuff |
oh interesitng |
@gkiely Can you share your code? I'm having a hard time figuring out how to get JSDom to be loaded in bun before any tests run. |
@EvHaus can you try |
I'm using a variation on this, will update shortly: https://twitter.com/jarredsumner/status/1659391501871513607/photo/1 JSDom is not working for me, using happy-dom. |
Ok posted an update with a working version. Preload fixed the above error.
|
I'll have a fix for the issue with node-fetch shortly. TLDR Is we polyfill node-fetch since in Bun it should just use the globalThis.fetch implementation, but our polyfill was only exporting fetch and not all the other things node-fetch exports. |
@EvHaus I tried to get your commit running and there is definitely a bug with In the meantime, if you make helpers/happydom.ts look more like this: import { GlobalRegistrator } from "@happy-dom/global-registrator";
GlobalRegistrator.register(); and add a [test]
preload = ["./helpers/happydom.ts"] It gets a lot closer to working. There are 218 test failures, but 20 pass and it console.log's a LOT of text |
Nice! The main thing that was missing is a way for For now I manually added that to each test file and that got me a lot closer. All tests pass when run individually, but running them all causes bun to crash mid-way through with...
...before all the tests have finshed. You can try with latest commit in EvHaus/test-runner-benchmarks@3d13051 |
- skipped tests requiring dom: oven-sh/bun#198
* Feat(core)!: refactor and upgrade - remove non typescript-first dependencies - upgrade all deps to latest versions - refactor components to react.fc - migrate to bun.sh * Feat(tests)!: migrate tests to bun:test - skipped tests requiring dom: oven-sh/bun#198 * Fix(MR): remove Navigator typings * Chore(ts): update tsconfig
We will add support for registering hooks via bun:test in preload |
I can repro the crash. Call stack: WTFCrashWithInfo(int, char const*, char const*, int) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/wtf/Assertions.h:758)
JSC::LocalAllocator::allocateSlowCase(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode) (@JSC::LocalAllocator::allocateSlowCase(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode):67)
JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode)::'lambda'()::operator()() const (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/LocalAllocatorInlines.h:41)
JSC::HeapCell* JSC::FreeList::allocateWithCellSize<JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode)::'lambda'()>(JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode)::'lambda'() const&, unsigned long) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/FreeListInlines.h:44)
JSC::LocalAllocator::allocate(JSC::Heap&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/LocalAllocatorInlines.h:38)
JSC::GCClient::IsoSubspace::allocate(JSC::VM&, unsigned long, JSC::GCDeferralContext*, JSC::AllocationFailureMode) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/IsoSubspaceInlines.h:34)
void* JSC::tryAllocateCellHelper<JSC::JSString, (JSC::AllocationFailureMode)0>(JSC::VM&, unsigned long, JSC::GCDeferralContext*) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/JSCellInlines.h:190)
void* JSC::allocateCell<JSC::JSString>(JSC::VM&, unsigned long) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/JSCellInlines.h:206)
JSC::JSString::create(JSC::VM&, WTF::Ref<WTF::StringImpl, WTF::RawPtrTraits<WTF::StringImpl>>&&) (/Users/jarred/Code/bun/node_modules/bun-webkit-macos-arm64/include/JavaScriptCore/JSString.h:187)
JSC::JSFunction::originalName(JSC::JSGlobalObject*) (@JSC::JSFunction::originalName(JSC::JSGlobalObject*):253)
JSC::JSBoundFunction::nameSlow(JSC::VM&) (@JSC::JSBoundFunction::nameSlow(JSC::VM&):47)
JSC::JSFunction::name(JSC::VM&) (@JSC::JSFunction::name(JSC::VM&):58)
JSC::getCalculatedDisplayName(JSC::VM&, JSC::JSObject*) (@JSC::getCalculatedDisplayName(JSC::VM&, JSC::JSObject*):65)
JSC::StackFrame::functionName(JSC::VM&) const (@JSC::StackFrame::functionName(JSC::VM&) const:43)
JSC::StackFrame::toString(JSC::VM&) const (@JSC::StackFrame::toString(JSC::VM&) const:13)
JSC::Interpreter::stackTraceAsString(JSC::VM&, WTF::Vector<JSC::StackFrame, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&) (@JSC::Interpreter::stackTraceAsString(JSC::VM&, WTF::Vector<JSC::StackFrame, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> const&):35)
JSC::ErrorInstance::computeErrorInfo(JSC::VM&) (@JSC::ErrorInstance::computeErrorInfo(JSC::VM&):23)
JSC::Heap::finalizeUnconditionalFinalizers() (@JSC::Heap::finalizeUnconditionalFinalizers():306)
JSC::Heap::runEndPhase(JSC::GCConductor) (@JSC::Heap::runEndPhase(JSC::GCConductor):355)
JSC::Heap::runCurrentPhase(JSC::GCConductor, JSC::CurrentThreadState*) (@JSC::Heap::runCurrentPhase(JSC::GCConductor, JSC::CurrentThreadState*):97)
WTF::ScopedLambdaFunctor<void (JSC::CurrentThreadState&), JSC::Heap::collectInMutatorThread()::$_25>::implFunction(void*, JSC::CurrentThreadState&) (@WTF::ScopedLambdaFunctor<void (JSC::CurrentThreadState&), JSC::Heap::collectInMutatorThread()::$_25>::implFunction(void*, JSC::CurrentThreadState&):12)
JSC::callWithCurrentThreadState(WTF::ScopedLambda<void (JSC::CurrentThreadState&)> const&) (@JSC::callWithCurrentThreadState(WTF::ScopedLambda<void (JSC::CurrentThreadState&)> const&):45)
JSC::Heap::collectInMutatorThread() (@JSC::Heap::collectInMutatorThread():27)
JSC::Heap::waitForCollection(unsigned long long) (@JSC::Heap::waitForCollection(unsigned long long):42)
JSC::Heap::collectSync(JSC::GCRequest) (@JSC::Heap::collectSync(JSC::GCRequest):30)
::JSC__VM__runGC(JSC__VM *, bool) (/Users/jarred/Code/bun/src/bun.js/bindings/bindings.cpp:3453)
src.bun.js.bindings.shimmer.Shimmer("JSC","VM",src.bun.js.bindings.bindings.VM).cppFn (/Users/jarred/Code/bun/src/bun.js/bindings/shimmer.zig:186)
src.bun.js.bindings.bindings.VM.runGC (/Users/jarred/Code/bun/src/bun.js/bindings/bindings.zig:4683)
src.cli.test_command.TestCommand.run (/Users/jarred/Code/bun/src/cli/test_command.zig:720)
src.string_types.PathString.slice (/Users/jarred/Code/bun/src/string_types.zig:43)
src.cli.test_command.TestCommand.runAllTests.Context.begin (/Users/jarred/Code/bun/src/cli/test_command.zig:618)
src.bun.js.javascript.OpaqueWrap__anon_144322__struct_253123.callback (/Users/jarred/Code/bun/src/bun.js/javascript.zig:121)
::JSC__VM__holdAPILock(JSC__VM *, void *, void (*)(void *)) (/Users/jarred/Code/bun/src/bun.js/bindings/bindings.cpp:3492)
src.bun.js.bindings.shimmer.Shimmer("JSC","VM",src.bun.js.bindings.bindings.VM).cppFn (/Users/jarred/Code/bun/src/bun.js/bindings/shimmer.zig:186)
src.bun.js.bindings.bindings.VM.holdAPILock (/Users/jarred/Code/bun/src/bun.js/bindings/bindings.zig:4627)
src.bun.js.javascript.VirtualMachine.runWithAPILock (/Users/jarred/Code/bun/src/bun.js/javascript.zig:1710)
src.cli.test_command.TestCommand.runAllTests (/Users/jarred/Code/bun/src/cli/test_command.zig:632)
src.cli.test_command.TestCommand.exec (/Users/jarred/Code/bun/src/cli/test_command.zig:462)
src.cli.Command.start (/Users/jarred/Code/bun/src/cli.zig:1213) We manually run the garbage collector after each file finishes executing and that seems to cause a crash due to a memory allocation failure happening inside the finalizer when getting function names from Error objects being finalized. I'm not sure yet if this is a bug in bun or in JSC (probably Bun) |
…l`, `afterEach` hooks Towards #198
Current status:
react-testing-library should work now, minus the above issue with the test simulation. |
Confirmed. Working well for me in bun 0.6.3. 👍 I was able to add it to my test runner benchmarks. If you're curious, here are the results:
Looks like |
The very marginal improvement there over vitest, I think, is because of the timers. If you remove the |
ah there's only one usage of |
If I remove the 1 usage of
|
the main remaining TODOs here are:
|
Confirmed. Latest canary is a bit better (results). Bun is now a clear winner 🎉 |
@EvHaus the |
@Jarred-Sumner Feel free to close this. |
I try to switch from Jest+Testing Library to Bun+Testing Library and stumbled over this issue. It looks like I have to run When I do it globally in a preload function like this:
then I got |
@donaldpipowitch, I had the same issue, I opened an issue on react testing library repo |
@donaldpipowitch @hmidmrii You need to set up happy-dom before calling cleanup. |
@gkiely If you check the issue I opened on react testing library repo in my previous commit, you will find that I did that in the preload file, I even proposed two workarounds, |
I opened an issue on their repo because I did some logs on both preload cleanup (placing the cleanup code in the preload file) and local cleanup (placing the cleanup code in each test file) and saw that both act the same, so I expected it the issue to be from |
Allow running tests with @testing-library/react.
Example repo: https://github.com/gkiely/bun-rtl
Steps:
Error without environment:
Error after enabling jsdom:
The text was updated successfully, but these errors were encountered: