Skip to content
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

Bun test runner support #2524

Closed
rodhoward opened this issue Oct 8, 2024 · 3 comments
Closed

Bun test runner support #2524

rodhoward opened this issue Oct 8, 2024 · 3 comments

Comments

@rodhoward
Copy link

I've been using test-utils for years! Thanks for all the hard work.

Having added lots of unit tests test performance becomes more important. I've been looking at bun as well as happy dom as a replacement for our existing unit tests in jest and jsdom.

I've followed the bun guid to set up happy dom and that seems to be working but adding test utils into the mix isn't working. I'm getting the following error:

1354 | // same stub, so we're safe and do not need to pass these stubs
1355 | // for each mount operation
1356 | var stubs = new WeakMap();
1357 | function registerStub(_a) {
1358 |     var source = _a.source, stub = _a.stub;
1359 |     stubs.set(stub, source);
                 ^
TypeError: WeakMap keys must be objects or non-registered symbols
      at registerStub (/home/rod/test/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:1359:11)
      at createInstance (/home/rod/test/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8151:5)
      at mount (/home/rod/test/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:14)
      at /home/rod/test/src/components/___tests__/HelloWorld.spec.js:6:19
✗ dom test [2.00ms]

And my unit test looks like this:

import {test, expect} from 'bun:test';
import { mount } from '@vue/test-utils'
import Hello from "../HelloWorld.vue";

test('dom test', () => {
  const wrapper = mount(Hello, {msg: "bob's your uncle"});
  expect(wrapper.html()).toEqual("bob");

  // This is working fine:
  // document.body.innerHTML = `<button>My button</button>`;
  // const button = document.querySelector('button');
  // expect(button?.innerText).toEqual('My button');
});

I suspect this fix might need to come from bun.. but I'm hoping you might know better what exactly is the issue and can report it more accurately to them than I can. There might even be a feature request or bug in bun that relates to this issue that I could monitor?

Regards
Rod

@cexbrayat
Copy link
Member

I think you're running into oven-sh/bun#5052

But I don't know if that's an error in bun/JavascriptCore or if the stubs WeakMap internally used by VTU is using some keys that aren't supposed to be used (reading https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Key_not_weakly_held).

If you're willing to take a look, you can check the key that is throwing and we'll see if that's a valid key and a bun issue or if the WeakMap is not correctly used in VTU and we should fix it.

@rodhoward
Copy link
Author

mm I added some debugging and now I feel a little silly. I think the

import Hello from "../HelloWorld.vue";

Is just importing a file path or a string because bun doesn't have any plugin to tell it how to handle .vue files. This then causes the above error when trying to set the stubs:

stubs.set("src/components/HelloWorld.vue", "src/components/HelloWorld.vue");

#oven-sh/bun#5967

Thanks for the quick response.

@cexbrayat
Copy link
Member

👍 Let's close then, thanks for looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants