question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Will this play nicely with jest?

See original GitHub issue

First of all–thank you SO much. I’ve been hoping one of the core Vue members would backport script setup to Vue 2.

The only adoption concern I have left after reading the readme is whether this will break my jest tests. I guess it wouldn’t be too hard for me to write a basic jest transform using the JavaScript API. But I wasn’t sure whether that would play nicely with vue-jest. Any thoughts on this.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Neophencommented, Aug 24, 2021

Ok so for those running into this issue here’s the solution:

create a file vue-setup-transformer.js:

const { transform } = require('vue2-script-setup-transform');
const vueJest = require('vue-jest');

module.exports = {
  process(source, filename, ...args) {
    const transformed = transform(source, filename);
    return vueJest.process(transformed.code, filename, ...args);
  },
};

and then in your jest.config.js replace vue-jest with this custom transformer:

'.*\\.(vue)$': '<rootDir>/vue-setup-transformer.js',

I don’t know where i could submit this PR or how to do it, but if you let me know i could most likely do a pr here or for vue-jest?

Edit: This still seems to have trouble when transforming with external dependencies. it fails at the const transformed = transform(source, filename); and never goes into the vue-jest.process

Trying to figure out why

3reactions
lmiller1990commented, Aug 24, 2021

First off, I am amazed this has been ported to Vue 2. Well done! I haven’t looked at how it’s implemented exactly, but assuming there is no technical blocker, we could support this in vue-jest.

Considering Vue 2 will not have many more big updates, maintenance should not be too difficult. I am not sure I have time to work on this right now, but since most of the work is done in this code base, I’m guess we just:

  • import this into vue-jest
  • before we do the usual vue-jest transform, we pass the input to this module, changing the code into a regular SFC
  • let vue-jest do the rest of the transform
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Make SonarCloud Play-Along Nicely with Jest
It's a pretty simple setup. I'm using Jest (version 25.1.0) installed globally with npm install jest -g (cos why not) with tests located...
Read more >
Getting jest to play nicely with webpack static assets imports ...
Turns out it was fine before, but now since the css is imported in the component file, jest does not know what to...
Read more >
Getting Started - Jest
You just successfully wrote your first test using Jest! This test used expect and toBe to test that two values were exactly identical....
Read more >
How to Make SonarCloud Play-Along Nicely with Jest - Morioh
You cannot pass Jest coverage data directly into SonarCloud, so you need to use an intermediary to convert it into a format SonarCloud...
Read more >
Testing your Solid.js code with jest - DEV Community ‍ ‍
Jest is currently one of the best options for front end testing, but it requires some setup to play nicely with Solid.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found