Giter VIP home page Giter VIP logo

Comments (7)

mikemklee avatar mikemklee commented on July 17, 2024

Potentially a duplicate of #493

from vue-jest.

rogatty avatar rogatty commented on July 17, 2024

@mikemklee try this:

	globals: {
		'vue-jest': {
			compilerOptions: {
				whitespace: 'preserve',
			},
		},
	},

Works for me 🙂

from vue-jest.

mikemklee avatar mikemklee commented on July 17, 2024

@rogatty
I tried both:

globals: {
  '@vue/vue3-jest': ...

and

globals: {
  'vue-jest': ...

but neither seem to work for me sadly.

Do you mind sharing what versions you are using for jest, vue-jest, and @vue/test-utils?

from vue-jest.

mikemklee avatar mikemklee commented on July 17, 2024

Upon further debugging, I noticed that the @vue/vue3-jest/lib/process.js::processScriptSetup() is early exiting, causing the compilerOptions to not get respected.

function processScriptSetup(descriptor, filePath, config) {
  if (!descriptor.scriptSetup) { // <---  this will cause this method to early exit
    return null
  }
  const vueJestConfig = getVueJestConfig(config)

  const content = compileScript(descriptor, {
    id: filePath,
    refTransform: true,
    ...vueJestConfig.compilerOptions
  })
  const contentMap = mapLines(descriptor.scriptSetup.map, content.map)

  const transformer = resolveTransformer(
    descriptor.scriptSetup.lang,
    vueJestConfig
  )

  const result = transformer.process(content.content, filePath, config)
  result.map = mapLines(contentMap, result.map)

  return result
}

I think by descriptor.scriptSetup, it's trying to look for the
<script setup></script>

which is a new addition in vue 3.

For vue 2 components, descriptor.scriptSetup will always be null.

from vue-jest.

rogatty avatar rogatty commented on July 17, 2024

@mikemklee versions I'm using:

jest: 27.3.1
@vue/vue3-jest: 27.0.0
@vue/test-utils: 2.3.2

I don't use <script setup></script> yet, I'm in the middle of migration to Vue 3. I use @vue/compat in the app but not in the tests.

If you use .vue files with <template> then it should go through processTemplate, I think:

...vueJestConfig.compilerOptions

from vue-jest.

mikemklee avatar mikemklee commented on July 17, 2024

@rogatty
interesting, could you elaborate on what you said about using @vue/compat in the app, but not in the tests?

is it possible to have the app running with the compat build, while also keeping the tests passing as-is?

context:
me and my team are also in the middle of our migration to Vue 3, and our tests are mostly failing after we:

  • installed the compat build
  • bumped vue-test-utils to v2

and we would like to figure out the best path forward that would minimize the amount of friction/changes required

from vue-jest.

rogatty avatar rogatty commented on July 17, 2024

@mikemklee there is https://www.npmjs.com/package/vue-test-utils-compat but it doesn't support the latest vue-test-utils. It uses monkey patching and is very brittle.

There were some other issues I don't remember, and we've decided it's better to just migrate most of the tests, skip a few of problematic ones for now, and upgrade the app logic where necessary.

from vue-jest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.