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

[BUG] - @testdeck/vitest is relying on commonjs module #322

Closed
3 tasks done
Lukinoh opened this issue Nov 3, 2022 · 6 comments · Fixed by #330
Closed
3 tasks done

[BUG] - @testdeck/vitest is relying on commonjs module #322

Lukinoh opened this issue Nov 3, 2022 · 6 comments · Fixed by #330
Assignees
Labels

Comments

@Lukinoh
Copy link
Contributor

Lukinoh commented Nov 3, 2022

Testdeck Version

0.3.0

Testdeck Package

  • @testdeck/vite

NodeJS Version

  • 18

Mocha / Jasmine / Jest / Vitest Version

  • Vitest: 0.24.5

Operating System

  • Other: WSL2

Actual Behaviour

I tried to use @testdeck/vitest on a small project, but it does not work because the build provided by testdeck is using commonjs, and vitest is not compatible with commonjs.

You can reproduce the issue easily on your repository by using the build output in your tests :

cd packages/vitest
sed -i 's/\.\/index/\.\/dist\/index.js/g' test.ts
npm run test

If you modify the tsconfig.json by

  • Removing "module": "commonjs"
  • Adding "moduleResolution": "node"

It will work, in your tests.

Expected Behaviour

It should not rely on commonjs, otherwise, it won't work natively with vitest.

@Lukinoh Lukinoh added the bug label Nov 3, 2022
@silkentrance silkentrance self-assigned this Nov 4, 2022
@silkentrance
Copy link
Member

@Lukinoh Thank you very much for the quick feedback.

I have to look into this as testdeck is meant for being used in both the browser and node.

@silkentrance
Copy link
Member

silkentrance commented Nov 4, 2022

@Lukinoh Which version of vitest are you using? Looking at vitest-dev/vitest#325 it seems as if this was already fixed.

@Lukinoh
Copy link
Contributor Author

Lukinoh commented Nov 4, 2022

I made a typo in my ticket.
0.24.5 was the version of vitest not vite. I will change that.

You can find my small project with the bug here: https://stackblitz.com/edit/vitejs-vite-rqocxq?file=package.json

But concretely what seems to happen is that "@testdeck/vitest" loads the file index.cjs of vite which is empty.

@silkentrance
Copy link
Member

I have looked into this.

Importing from ESM into CJS modules is quite tricky and requires a top level await, i.e.

const { expect } = await import("vitest");

While this works after the fact, i.e. the dist/index.js file is patched, it will not work when transpiling with tsc, as it requires esnext as its target and esnext for the module type. In addition it requires moduleResolution set to node.

@silkentrance
Copy link
Member

silkentrance commented Nov 4, 2022

Importing from CJS into ESM seems to be working, though.

So maybe just making @testdeck/vitest an ESM would do the trick while we figure out on how to deal with the other packages and their ESM support. (mocha >= 9, jasmine ?, jest ?, di-typedi ?)

@Lukinoh
Copy link
Contributor Author

Lukinoh commented Nov 4, 2022

As vitest is thought to be ESM first, it would make sense to me.

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

Successfully merging a pull request may close this issue.

2 participants