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

Support Jest 28 with @vue/cli-plugin-unit-jest #7129

Open
sceee opened this issue May 11, 2022 · 19 comments
Open

Support Jest 28 with @vue/cli-plugin-unit-jest #7129

sceee opened this issue May 11, 2022 · 19 comments

Comments

@sceee
Copy link

sceee commented May 11, 2022

What problem does this feature solve?

Since Jest 18 was released ( https://jestjs.io/blog/2022/04/25/jest-28 ), it would be preferable if @vue/cli-plugin-unit-jest also supports it.

There is also already a version 28 for ts-jest available that is compatible with Jest 28.

What does the proposed API look like?

n/a

@WIStudent
Copy link

Support Jest 18 with @vue/cli-plugin-unit-jest

I think you mean jest 28 instead of 18 😉

@realityfilter
Copy link

And @vue/vue3-jest is now at 28.0.0 too.

@sceee sceee changed the title Support Jest 18 with @vue/cli-plugin-unit-jest Support Jest 28 with @vue/cli-plugin-unit-jest May 24, 2022
@msmosavar
Copy link

It'd be nice if you add support for jest v28. Waiting for it :)

@trent-abc
Copy link

This is breaking my build, any suggestions (tried deleting package-lock & node_modules) or I have to just wait for the upgrade?

npm install
...
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/ts-jest
npm ERR!   dev ts-jest@"28.0.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional ts-jest@"^27.0.4" from @vue/[email protected]
npm ERR! node_modules/@vue/cli-plugin-unit-jest
npm ERR!   dev @vue/cli-plugin-unit-jest@"^5.0.6" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

@WIStudent
Copy link

@trent-abc You need to use ts-jest 27.

npm install -D ts-jest@27

@Tofandel
Copy link

Tofandel commented Jul 11, 2022

Yes but the way this is made currently feels like a pain, 1 package that updates, then one vue package that follows up, then the vue-cli-plugin package that needs to follow up. A big chain of update..

Either version range should be more lax in the vue-cli-plugin or there should be autoupgrades with renovate, otherwise updates takes months before they make it to the vue-cli plugin

It's the same issue with eslint

@xwnwho
Copy link

xwnwho commented Aug 10, 2022

any good news?

@markhalliwell
Copy link

This is holding up our upgrades to Jest 28.

@Vahelnir
Copy link

Vahelnir commented Sep 15, 2022

vue-jest added support for the <script setup> syntax in the v29.1.0 which is for jest 29 (vuejs/vue-jest#489).

<script setup> without testing support is kind of useless :)

If using npm 8.3.0 (I think ?) we can use the `overrides` property in the package.json to override `jest`, `ts-jest` and `@vue/vue2-jest` in `@vue/cli-plugin-unit-jest`.

edit: for some reason I can't use markdown code blocks

@iamface
Copy link

iamface commented Sep 27, 2022

This is holding up our upgrades to Jest 28.

This is blocking me as well. My test coverage is failing #7040 and the source maps were only fixed for v28 vuejs/vue-jest#486 so I'm unable to upgrade and resolve being stuck at 27.

npm ERR! While resolving: @vue/[email protected]
npm ERR! Found: @vue/[email protected]
npm ERR! node_modules/@vue/vue2-jest
npm ERR!   dev @vue/vue2-jest@"^28" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @vue/vue2-jest@"^27.0.0-alpha.3" from @vue/[email protected]
npm ERR! node_modules/@vue/cli-plugin-unit-jest
npm ERR!   dev @vue/cli-plugin-unit-jest@"~5.0.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @vue/[email protected]
npm ERR! node_modules/@vue/vue2-jest
npm ERR!   peerOptional @vue/vue2-jest@"^27.0.0-alpha.3" from @vue/[email protected]
npm ERR!   node_modules/@vue/cli-plugin-unit-jest
npm ERR!     dev @vue/cli-plugin-unit-jest@"~5.0.0" from the root project

@schirrel
Copy link

Any update on it?

@nfantone
Copy link

nfantone commented Oct 19, 2022

Same over here trying to install @vue/[email protected] along with latest @vue/vue2-jest.

❯ npm i --save-dev @vue/cli-plugin-unit-jest
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @vue/[email protected]
npm ERR! Found: @vue/[email protected]
npm ERR! node_modules/@vue/vue2-jest
npm ERR!   dev @vue/vue2-jest@"^29.1.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @vue/vue2-jest@"^27.0.0-alpha.3" from @vue/[email protected]
npm ERR! node_modules/@vue/cli-plugin-unit-jest
npm ERR!   dev @vue/cli-plugin-unit-jest@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @vue/[email protected]
npm ERR! node_modules/@vue/vue2-jest
npm ERR!   peerOptional @vue/vue2-jest@"^27.0.0-alpha.3" from @vue/[email protected]
npm ERR!   node_modules/@vue/cli-plugin-unit-jest
npm ERR!     dev @vue/cli-plugin-unit-jest@"*" from the root project

@markhalliwell
Copy link

Not to sound insensitive (I know how dev work goes), but can we please get a release that supports jest 29? We cannot upgrade anything related to jest because of this package.

@darrinmn9
Copy link
Contributor

I was able to successfully upgrade to jest 28/29, but it does require the use of resolutions (yarn) / overrides (npm).

"devDependencies": {
    "@vue/cli-plugin-unit-jest": "^5.0.8",
    "@vue/vue2-jest": "^29.0.0",
    "jest-environment-jsdom": "^29.0.0"
},
"resolutions": {
    "jest": "^29.0.0",
    "babel-jest": "^29.0.0"
},

Ofcourse you'll have to address any jest breaking changes in your codebase. (My project is in JS, TypeScript might require more changes)

upgrade guides:
https://jestjs.io/docs/28.x/upgrading-to-jest28
https://jestjs.io/docs/upgrading-to-jest29

@ErikBjare
Copy link

ErikBjare commented May 11, 2023

After updating all my jest-related deps to ^29, and much frustration trying the resolutions/overrides trick by @darrinmn9 above, I ended up with:

  "overrides": {
      "@vue/cli-plugin-unit-jest": {
          "ts-jest": "$ts-jest",
          "@vue/vue2-jest": "$@vue/vue2-jest"
      }
  }

It resolved, and I then got the following error when running with npm test:

 TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')
   at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:63:28)

Same error happens for jest-environment-node/NodeEnvironment. I added some print statements and figured the config wasn't being loaded by vue-cli-service unit:test correctly.

I figured calling jest directly would work around this, so I changed my package.json script "test" to call jest directly:

  "scripts": {
    "test": "jest",
    ...
  }

Which works! I still have the @vue/cli-plugin-unit-jest dependency for the preset: '@vue/cli-plugin-unit-jest' config option in jest.config.js.

ErikBjare added a commit to ActivityWatch/aw-webui that referenced this issue May 11, 2023
ErikBjare added a commit to ActivityWatch/aw-webui that referenced this issue May 11, 2023
@kepi0809
Copy link

After updating all my jest-related deps to ^29, and much frustration trying the resolutions/overrides trick by @darrinmn9 above, I ended up with:

  "overrides": {
      "@vue/cli-plugin-unit-jest": {
          "ts-jest": "$ts-jest",
          "@vue/vue2-jest": "$@vue/vue2-jest"
      }
  }

It resolved, and I then got the following error when running with npm test:

 TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')
   at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:63:28)

Same error happens for jest-environment-node/NodeEnvironment. I added some print statements and figured the config wasn't being loaded by vue-cli-service unit:test correctly.

I figured calling jest directly would work around this, so I changed my package.json script "test" to call jest directly:

  "scripts": {
    "test": "jest",
    ...
  }

Which works! I still have the @vue/cli-plugin-unit-jest dependency for the preset: '@vue/cli-plugin-unit-jest' config option in jest.config.js.

I can confirm, this solution works. Thanks for sharing @ErikBjare

@artikhurana
Copy link

overrides

Where we need to add this overrides? Could you please help me. I'm also facing same issue

@kepi0809
Copy link

kepi0809 commented Jun 7, 2023

overrides

Where we need to add this overrides? Could you please help me. I'm also facing same issue

It goes into your package.json, if you use yarn then the syntax could be different though. (resolutions I think but I didn't test with yarn)

manuelleduc pushed a commit to xwiki/xwiki-platform that referenced this issue Oct 25, 2023
Requires to force @vue/cli-plugin-unit-jest to use a more recent version of @vue/vue2-jest
See vuejs/vue-cli#7129
surli pushed a commit to xwiki/xwiki-platform that referenced this issue Nov 6, 2023
Requires to force @vue/cli-plugin-unit-jest to use a more recent version of @vue/vue2-jest
See vuejs/vue-cli#7129
@lokeswari9
Copy link

will this also add support for @vue/vue3-jest to v28 and v29 because its the same issue I am migrating my vue 2 project to vue 3 and i am stuck figuring out the versions for updating my test cases

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