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

index.mjs causes jest to throw (regression in v1.0.4) #145

Closed
cexbrayat opened this issue Jan 22, 2022 · 7 comments
Closed

index.mjs causes jest to throw (regression in v1.0.4) #145

cexbrayat opened this issue Jan 22, 2022 · 7 comments

Comments

@cexbrayat
Copy link
Contributor

Reproduction

A CLI app using Jest and createRouterMock in a unit test will throw when upgrading to v1.0.4 with:

/Users/cedric/Code/ninjasquad/vue-ebook/book-tests/node_modules/vue-router-mock/dist/index.mjs:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import { createRouter, createMemoryHistory, START_LOCATION, routerKey, routeLocationKey, routerViewLocationKey, matchedRouteKey, RouterView, RouterLink } from 'vue-router';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import { flushPromises, mount } from '@vue/test-utils';
    > 2 | import { createRouterMock, injectRouterMock } from 'vue-router-mock';

This is because the main file switched to the mjs format, which is great for Vite but not ideal for Jest.

Expected behavior

Jest tests should still work

@posva
Copy link
Owner

posva commented Jan 22, 2022

It should be a matter of configuring unbuild to output cjs. Contribution welcome!

@cexbrayat
Copy link
Contributor Author

Don't you think this b7fd685#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R5 is the source of the regression?

@posva
Copy link
Owner

posva commented Jan 22, 2022

No, I did that because there is no cjs file generated at the moment

@pgarciaegido
Copy link

I am working on a PR to build both .mjs and .cjs files. 👍

@posva posva closed this as completed in 4ab0b34 Jan 23, 2022
@posva
Copy link
Owner

posva commented Jan 23, 2022

@pgarciaegido I actually just found the fix and pushed it 😅

@pgarciaegido
Copy link

Amazing @posva !

Just one little comment, do you think it makes sense to use the exports field to expose both files?

"exports": {
    "require": "./dist/index.cjs",
    "import": "./dist/index.mjs"
  },

Thanks a lot! 😄

@posva
Copy link
Owner

posva commented Jan 23, 2022

Totally! Published a new verison

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

No branches or pull requests

3 participants