Skip to content

basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") #4751

@nolde

Description

@nolde

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.10
  • node v6.10.3
  • vue v2.5.2
  • babel-jest v21.2.0
  • jest v21.2.1
  • jest-vue v0.8.1
  • vue-test-utils with v1.0.0.beta.3, v1.0.0.beta.2, v1.0.0.beta.1

Activity

cpojer

cpojer commented on Oct 24, 2017

@cpojer
Member

This seems like a problem with vue-test-utils, not a Jest issue.

nolde

nolde commented on Oct 24, 2017

@nolde
Author

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 requesting vue-test-utils on the first set of tests triggered the error, I suppose it is not there.

SimenB

SimenB commented on Oct 24, 2017

@SimenB
Member

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 bug

nolde

nolde commented on Oct 24, 2017

@nolde
Author

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

SimenB commented on Oct 24, 2017

@SimenB
Member

Can you delete C:\Program Files\nodejs\vue? And install vue locally in your project instead (and maybe do npm install --global vue)

nolde

nolde commented on Oct 24, 2017

@nolde
Author

It is installed locally, and there is no vue installed globally, only local to the project.

The vue that is being picked up seems to be the entry point for vue-cli command vue, which is pretty weird.

EDIT:
I have uninstalled vue-cli from global scope, and then the test passes. For some reason, the jest runtime is picking up that bash file instead of the actual vue component.

Thanks for the tip, @SimenB , I didn't realise it was picking the bash file up.

SimenB

SimenB commented on Oct 24, 2017

@SimenB
Member

If you install the cli globally, what does node -p "require.resolve('vue')" return? If that command returns something else than C:\Program Files\nodejs\vue, you found a bug in Jest

nolde

nolde commented on Oct 24, 2017

@nolde
Author

Running it inside a project that has vue installed, I get C:\git\<project-folder>\node_modules\vue\dist\vue.runtime.common.js

If I run it outside of a project folder, I get the vue-cli bash file, same one being required by jest.

SimenB

SimenB commented on Oct 24, 2017

@SimenB
Member

Yeah, that's a bug in the module resolution of Jest, then.

reopened this on Oct 24, 2017
SimenB

SimenB commented on Oct 24, 2017

@SimenB
Member

That said, I can't reproduce on mac. node -p "require.resolve('vue')" outside of a project throws Error: Cannot find module 'vue', even if vue-cli is installed globally.

nolde

nolde commented on Oct 24, 2017

@nolde
Author

Yeah, it seems to be related to Windows. My co-worker using mac installed vue-cli as well and nothing came up.

12 remaining items

akagrawat

akagrawat commented on May 15, 2020

@akagrawat

I was using below configuration in package.json file

"scripts": {
 "test": "node --inspect node_modules/.bin/cross-env API_HOST=url ember serve",
}

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.

 "test": "node_modules/.bin/cross-env API_HOST=url ember serve",
github-actions

github-actions commented on Feb 26, 2022

@github-actions

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

github-actions commented on Mar 28, 2022

@github-actions

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

github-actions commented on Apr 28, 2022

@github-actions

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.

locked as resolved and limited conversation to collaborators on Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cpojer@marekkaczkowski@SimenB@Havunen@gijswijs

        Issue actions

          `basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")` · Issue #4751 · jestjs/jest