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

Relative imports in multi-file-components do not work in subfolders #48

Open
kiyui opened this issue Jan 2, 2018 · 0 comments
Open

Comments

@kiyui
Copy link

kiyui commented Jan 2, 2018

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request

Current behavior

Multiple file components such as components/HelloWorld/ cannot import files
relatively in jest if the script is in a subfolder:

<script src="./script/index.js"></script>

Because inside the script, if we do the following:

import { greeter } from './lib/something'

Jest will throw the following error looking for lib/something because it
looks for the file relative to index.vue instead of script/index.js.

 FAIL  test/unit/specs/HelloWorld.spec.js
  ● Test suite failed to run

    Cannot find module './lib/something' from 'index.vue'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:191:17)
      at src/components/HelloWorld/index.vue:8:18
      at Object.<anonymous> (src/components/HelloWorld/index.vue:18:3)

Current fix is to not put index.js inside a subfolder. Alternatively, the following can be done:

<script>
import Component from './script/index';
export default Component;
</script>

Expected behavior

Files imported inside a script should be relative to the script path instead of the index.vue file.
The workaround shouldn't be necessary (or should be documented).

Minimal reproduction of the problem with instructions
I've created a test repo here

  • Do npm install
  • Running npm run start works just fine
  • Running npm run test will throw the error

(I hope this is sufficient, and that my suspicion for origin of behaviour is correct)

What is the motivation / use case for changing the behavior?

Avoid using the workaround as it works as is with Webpack.

Please tell us about your environment:

  • jest-vue-preprocessor: 1.1.X
    "jest-vue-preprocessor": "git+https://github.com/vire/jest-vue-preprocessor.git",
  • Node version : [ OSX | Linux | Windows ]
    v9.3.0

  • Platform: [ OSX | Linux | Windows ]
    Linux

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

1 participant