-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
When importing vue-test-utils, I get a weird error that doesn't seem to be related to anything else other than the component itself. I am running the test with jest.
Test code:
import { shallow, createLocalVue } from 'vue-test-utils'
describe('App', () => {
it('should work', () => {
expect(true).toBe(true)
})
})If the import line is commented out, the test runs fine and passes; with the import in, I get the following error:
FAIL src\core\App.test.js
● Test suite failed to run
C:\Program Files\nodejs\vue:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
at Object.<anonymous> (node_modules/vue-test-utils/dist/vue-test-utils.js:5:27)
at Object.<anonymous> (src/core/App.test.js:2:21)That done, convinced that the problem was with vue-test-utils, I tried to create tests without using the component:
import Vue from 'vue'
import App from './App.vue'
describe('App', () => {
it('renders default layout if none is defined in', () => {
const Ctor = Vue.extend(App)
const instance = new Ctor().$mount()
expect(instance.layout).toBe('default')
})
})... aaaannnd I get the same error again. Therefore, the issue seems to be somewhere within the jest ecosystem.
I have removed the node_modules folder and reinstalled it all using npm install to make sure it was not a dependency issue with each test.
Jest config:
// package.json
"jest": {
"moduleFileExtensions": [
"js",
"vue"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue"
},
"mapCoverage": true,
"verbose": true
}Versions:
- Windows 10
npm v3.10.10node v6.10.3vue v2.5.2babel-jest v21.2.0jest v21.2.1jest-vue v0.8.1vue-test-utilswithv1.0.0.beta.3,v1.0.0.beta.2,v1.0.0.beta.1
maxfriedmann and XmlmXmlmX
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
cpojer commentedon Oct 24, 2017
This seems like a problem with
vue-test-utils, not a Jest issue.nolde commentedon Oct 24, 2017
It is not, as I mention on the original request.
Even without any reference to
vue-test-utils, I get the exact same error.It could be related to
jest-vue, but the fact that just requestingvue-test-utilson the first set of tests triggered the error, I suppose it is not there.SimenB commentedon Oct 24, 2017
require('vue')is pulling in a shell script not JavaScript. Does this happen in the node repl? If not, I'm inclined to calling this a jest bugnolde commentedon Oct 24, 2017
Just had a friend set up similar code in OSX; it works on his machine, fails in my Windows device.
Therefore, it is Windows environment related.
SimenB commentedon Oct 24, 2017
Can you delete
C:\Program Files\nodejs\vue? And installvuelocally in your project instead (and maybe donpm install --global vue)nolde commentedon Oct 24, 2017
It is installed locally, and there is no
vueinstalled globally, only local to the project.The
vuethat is being picked up seems to be the entry point forvue-clicommand vue, which is pretty weird.EDIT:
I have uninstalled
vue-clifrom global scope, and then the test passes. For some reason, the jest runtime is picking up that bash file instead of the actualvuecomponent.Thanks for the tip, @SimenB , I didn't realise it was picking the bash file up.
SimenB commentedon Oct 24, 2017
If you install the cli globally, what does
node -p "require.resolve('vue')"return? If that command returns something else thanC:\Program Files\nodejs\vue, you found a bug in Jestnolde commentedon Oct 24, 2017
Running it inside a project that has vue installed, I get
C:\git\<project-folder>\node_modules\vue\dist\vue.runtime.common.jsIf I run it outside of a project folder, I get the
vue-clibash file, same one being required byjest.SimenB commentedon Oct 24, 2017
Yeah, that's a bug in the module resolution of Jest, then.
SimenB commentedon Oct 24, 2017
That said, I can't reproduce on mac.
node -p "require.resolve('vue')"outside of a project throwsError: Cannot find module 'vue', even ifvue-cliis installed globally.nolde commentedon Oct 24, 2017
Yeah, it seems to be related to Windows. My co-worker using mac installed
vue-clias well and nothing came up.12 remaining items
akagrawat commentedon May 15, 2020
I was using below configuration in package.json file
The above config work for the Linux machine. But I have a windows machine and during npm run test I got this error.
In my case when I removed node --inspect than its work for me.
fix(x-platform): change path to webpack script
fix(x-platform): change path to webpack script
Make sure the refresh-ldm script works on Windows
chore: fix file paths in launch.json
Enhancing writers to be more flexible for integration into `easyUI5` (#…
github-actions commentedon Feb 26, 2022
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
github-actions commentedon Mar 28, 2022
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
github-actions commentedon Apr 28, 2022
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.