-
Notifications
You must be signed in to change notification settings - Fork 27
Tests failing when importing components using absolute path #25
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
Comments
I've seen issues where {
"config": {
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/var/folders/hg/g_zf05ys5cbdzk8m06zcy13c0000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"globals": {},
"haste": {
"providesModuleNodeModules": []
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"vue"
],
"moduleNameMapper": [
[
"src/components/([^\\.]*)$",
"/Users/[removed]/src/components/$1.vue"
],
[
"^vue$",
"vue/dist/vue.common.js"
],
[
"src/([^\\.]*)$",
"/Users/[removed]/src/$1.vue"
],
[
"(.*)/(.*)$",
"$1/$2.vue"
]
],
"modulePathIgnorePatterns": [],
"name": "efafa39470c546c1dfd58eaa0ef88734",
"resetMocks": false,
"resetModules": false,
"rootDir": "/Users/[removed]",
"roots": [
"/Users/[removed]"
],
"setupFiles": [],
"snapshotSerializers": [
"/Users/[removed]/node_modules/jest-serializer-html/index.js"
],
"testEnvironment": "jest-environment-jsdom",
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)(spec|test).js?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": "",
"testRunner": "/Users/[removed]/node_modules/jest-jasmine2/build/index.js",
"testURL": "about:blank",
"timers": "real",
"transform": [
[
"^.+\\.js$",
"/Users/[removed]/node_modules/babel-jest/build/index.js"
],
[
".*\\.(vue)$",
"/Users/[removed]/node_modules/jest-vue-preprocessor/index.js"
]
],
"transformIgnorePatterns": [
"/node_modules/"
]
},
"framework": "jasmine2",
"globalConfig": {
"bail": false,
"collectCoverageFrom": [
"src/**/*.{js,jsx}"
],
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"expand": false,
"mapCoverage": false,
"noStackTrace": false,
"notify": false,
"projects": [
"/Users/[removed]"
],
"rootDir": "/Users/[removed]",
"testPathPattern": "",
"testResultsProcessor": null,
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "20.0.4"
} |
I had a similar problem and solved it with these module name mappings. I don't think this issue is related to "moduleNameMapper": {
"^@/components/([^\\.]*)$": "<rootDir>/src/components/$1.vue",
"^@(.*)$": "<rootDir>/src$1",
"^src/components/([^\\.]*)$": "<rootDir>/src/components/$1.vue",
"^vue$": "vue/dist/vue.common.js"
} These regexes probably aren't optimal but it worked for me. |
@psalaets I think you're right, I've used some default and didn't tested much other ways/paths how to import components. This needs to be covered in tests and probably updated README so people are aware of the need to set properly |
Hi folks, I manage to make it work by adding "^@[/](.+)": "<rootDir>/src/$1", I'm far from a regex expert so I'm not sure which one is the "most correct", but it worked for me. This is my final moduleNameMapper, just in case someone stumbles upon this thread: "moduleNameMapper": {
"^@[/](.+)": "<rootDir>/src/$1",
"^components[/](.+)": "<rootDir>/src/components/$1",
"src/components/([^\\.]*)$": "<rootDir>/src/components/$1.vue",
"^vue$": "vue/dist/vue.common.js",
"src/([^\\.]*)$": "<rootDir>/src/$1.vue",
"(.*)/(.*)$": "$1/$2.vue"
},
completely agree |
That workaround is not viable if you have a mix of vue files and js files imported..
To your jest config And remove the |
Uh oh!
There was an error while loading. Please reload this page.
Current behavior
Tests fail when absolute path import is used
Expected behavior
All tests to pass (as they do when I replace the absolute path with the relative equivalent one).
Minimal reproduction of the problem with instructions
Just running tests with some component import. Only when using relative paths the test is able to import them:
Console output:
Obviously, my
import Component from @/components/Whatever
works properly in my app.Just in case, my jest object config from
package.json
:Tried adding a new line in ModuleNameMapper:
"@/([^\\.]*)$": "<rootDir>/src/$1.vue",
but did not work. I'm not sure if that even make sense :)I'm using
vue-cli
, so inwebpack.base.conf.js
there's the@
alias setup:Please tell us about your environment:
Node version : 8.1.2 (npm 5.3.0)
Platform: OSX
Thanks for your time!
The text was updated successfully, but these errors were encountered: