vuejs / vue-jest

Jest Vue transformer
MIT License
744 stars 157 forks source link

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

Open AtofStryker opened 6 years ago

AtofStryker commented 6 years ago

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 commented 6 years ago

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"
      }
    }
  }
} 
klak-bm commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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.