rogeliog / jest-runner-mocha

A Mocha runner for Jest
70 stars 12 forks source link

Coverage and Babel 7 #19

Open MattJakeman opened 5 years ago

MattJakeman commented 5 years ago

I started using this yesterday and it's all working great apart from coverage. It seems to load in babel-core 6 and I get the error :

  Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.

  at throwVersionError (node_modules/@babel/helper-plugin-utils/lib/index.js:65:11)
  at Object.assertVersion (node_modules/@babel/helper-plugin-utils/lib/index.js:13:11)
  at api (node_modules/@babel/plugin-transform-flow-strip-types/lib/index.js:41:7)
  at node_modules/@babel/helper-plugin-utils/lib/index.js:19:12
  at Function.memoisePluginContainer (node_modules/babel-core/lib/transformation/file/options/option-manager.js:113:13)
  at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:146:32)
  at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
      at Array.map (<anonymous>)
  at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
  at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
  at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
  at compile (node_modules/babel-register/lib/node.js:103:45)
  at loader (node_modules/babel-register/lib/node.js:144:14)
  at Object.require.extensions.(anonymous function) [as .js] (node_modules/babel-register/lib/node.js:154:7)
      at Array.forEach (<anonymous>)
  at handle (node_modules/worker-farm/lib/child/index.js:44:8)

A yarn why brings back the following:

  yarn why babel-core
  yarn why v1.13.0
  warning package.json: No license field
  [1/4] Why do we have the module "babel-core"...?
  [2/4] Initialising dependency graph...
  warning todolistapi@1.0.0: No license field
  [3/4] Finding dependency...
  [4/4] Calculating file sizes...
  => Found "babel-core@6.26.3"
  info Reasons this module exists
     - "jest-runner-mocha#babel-register" depends on it
     - Hoisted from "jest-runner-mocha#babel-register#babel-core"
  info Disk size without dependencies: "1.1MB"
  info Disk size with unique dependencies: "11.23MB"
  info Disk size with transitive dependencies: "21.15MB"
  info Number of shared dependencies: 39
  Done in 1.04s.

Is there any way to force Babel 7 when running coverage? I'm using the following config options:

  jest-runner-mocha": {
      "cliOptions": {
        "compiler": "node_modules/@babel/register"
      },
      "coverageOptions": {
        "useBabelRc": true
      }
    }

I'm presuming the compiler option is being ignored when using coverage for some reason. I'd be happy to submit a PR but might need a pointer on where to start...

ljharb commented 5 years ago

Seems like worker-farm is using Babel 6, which means Babel 7 projects can’t work with it. #16 may be related.

MattJakeman commented 5 years ago

In that case, it looks like PR #18 will fix it. Is there any chance of getting that merged?

MattJakeman commented 5 years ago

I tried using the fork at https://github.com/patrickdawson/jest-runner-mocha directly using:

yarn add file:/xxxx/xxxx/xxxx/jest-runner-mocha

I was attempting this to see if the update in PR #18 would fix my issues. However I'm having some troubl with it and Jest throws an error, as follows:

  Validation Error:

    Jest Runner jest-runner-mocha cannot be found. Make sure the runner configuration option points to an existing node module.

Any pointers as to how I could get this up and running in my project from a local copy of the runner?