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

Is there any solution to use vite-jest for an application which using Vite + Vue2 + Composition API? #35

Open
tomlla opened this issue Dec 28, 2021 · 6 comments

Comments

@tomlla
Copy link

tomlla commented Dec 28, 2021

If Vite + Vue2 is not vite-jest support target, I'll close this issue.

I got this error when I run vite-jest

$ ./node_modules/.bin/vite-jest
(node:16061) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Determining test suites to run...Pre-bundling dependencies:
  @vue/composition-api
  ....
  (...and 56 more)
(this will be run only when your dependencies or config have changed)
 > node_modules/@vue/composition-api/dist/vue-composition-api.esm.js:1:16: error: Could not read from file: /home/me/vite-vu2-app/vue/dist/vue.esm-bundler.js
    1 │ import Vue from 'vue';
      ╵                 ~~~~~

Error: Build failed with 1 error:
node_modules/@vue/composition-api/dist/vue-composition-api.esm.js:1:16: error: Could not read from file: /home/me/vite-vu2-app/vue/dist/vue.esm-bundler.js
    at failureErrorWithLog (/home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:1493:15)
    at /home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:1151:28
    at runOnEndCallbacks (/home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:941:63)
    at buildResponseToResult (/home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:1149:7)
    at /home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:1258:14
    at /home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:726:9)
    at Socket.readFromStdout (/home/me/vite-vu2-app/node_modules/esbuild/lib/main.js:596:7)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:199:23)

My environment

$ node --version
v16.13.0
$ jq .version node_modules/vite/package.json
"2.7.7"
$ jq .version node_modules/vue/package.json
"2.6.14"
$ jq .version node_modules/@vue/composition-api/package.json
"1.0.4"
$ grep preset jest.config.js
  preset: "vite-jest",
@haoqunjiang
Copy link
Owner

The errors here are because that I added some default options to the vite server but didn't realize they are Vue-3 only.

But there are some other issues that prevent vite-jest from supporting the vue2 plugin🤔 I'll take a look.

@haug1
Copy link

haug1 commented Mar 22, 2022

Would be cool to see this fixed 👀

@nagisaando
Copy link

Hi, is there any update on this?

@tomdevelops
Copy link

Hey @haug1 and @nagisaando, had the same problem, discovered vitest. With a little rewrite, works like a charm with vue2 + vite 🥳

@nagisaando
Copy link

@tomdevelops I am interested in using Vitest but it's just not production ready yet, and that bothers me a bit.😅 Hopefully they will be ready soon tho.

@elambro
Copy link

elambro commented Nov 25, 2022

@tomdevelops How did you get it working? I use Laravel 9 / Vue2 / Vite. My tests w/ vitest all throw (e.g.) "captialize is not a function" for simple function import/exports. However import/export works fine with objects & constants.

export function capitalize(str) {
    return str ? str.charAt(0).toUpperCase() + str.slice(1) : str
}
import {capitalize}    from "@utils";

I also tried with jest, but I get Cannot use import.meta outside a module.

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

6 participants