Skip to content

Allow option to configure babelrc location for vue-jest #66

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

Open
AtofStryker opened this issue Mar 9, 2018 · 4 comments
Open

Allow option to configure babelrc location for vue-jest #66

AtofStryker opened this issue Mar 9, 2018 · 4 comments

Comments

@AtofStryker
Copy link

Is this currently an option? Currently running into the issue where vue-jest cannot find my .babelrc file when vue-jest's install directory is not within referencing directory.

example:
lerna-repo
-babelrc
-node_modules -> contains-vue jest
-lerna packages
--myComponent
--jestConfiguration

inside my jestConfiguration is a reference to the workspace vue-jest:

transform: {
'.*\.(vue)$': "../node_modules/vue-jest"
}

running the above fails because vue-jest cannot find my babelrc file. however, this works:

example:
lerna-repo
-babelrc
-node_modules -> contains-vue jest
-lerna packages
--myComponent
--jestConfiguration
--babelrc

to get around this, i am linking the parent babelrc file and removing it within npm lifecycle scripts.
version on npm is 5.6.0 and node is 8.9.4

@eddyerburgh
Copy link
Member

Agreed. We should use a jest global to get the location, similarly to how ts-jest does it—https://github.com/kulshekhar/ts-jest/blob/master/src/preprocessor.ts#L17

You can pass a global in in the Jest config object:

{
  "jest": {
    "globals": {
      "vue-jest": {
        "babelRcFile": "babelrc.json"
      }
    }
  }
} 

dcherman added a commit to dcherman/vue-jest that referenced this issue Apr 24, 2018
@klak-bm
Copy link

klak-bm commented May 23, 2018

Same problem here (using yarn workspaces and would like to have only one .babelrc file to maintain).

I think the priority is to look for a .babelrc file the same way Babel does it :
"Babel will look for a .babelrc in the current directory of the file being transpiled. If one does not exist, it will travel up the directory tree until it finds either a .babelrc, or a package.json with a "babel": {} hash within."

Source: https://babeljs.io/docs/usage/babelrc/#lookup-behavior

@eddyerburgh
Copy link
Member

We currently use the find-babel-config package to get the .babelrc using the root directory(https://github.com/vuejs/vue-jest/blob/master/lib/load-babel-config.js#L21). We could change this to use the file directory instead, like you suggest.

@TheCycoONE
Copy link
Contributor

Sorry, why are you passing a depth of 0 to findBabelConfig.sync(process.cwd(), 0). That makes it only look in the current working directory; when it should recurse down.

TheCycoONE added a commit to TheCycoONE/vue-jest that referenced this issue Jun 6, 2018
Now searches with a depth of infinity from the file path, as described
in vuejs#66.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants