Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

@neutrinojs/jest does not support some coverage options from .neutrinorc.js #1015

Closed
flouc001 opened this issue Aug 7, 2018 · 9 comments
Closed

Comments

@flouc001
Copy link

flouc001 commented Aug 7, 2018

Bug

Please try to answer the following questions:

  • What version of Neutrino are you using?
    8.3.0

  • Are you trying to use any presets? If so, which ones, and what versions?
    Yes:
    @neutrinojs/airbnb 8.3.0
    @neutrinojs/jest 8.3.0
    @neutrinojs/react-components 8.3.0

  • Are you using the Yarn client or the npm client? What version?
    Yarn v1.9.4

  • What version of Node.js are you using?
    Node v8.9.3

  • What operating system are you using?
    MacOS 10.13.4

  • What did you do?
    Added coverage options to the jest preset via .neutrinorc.js like so:

['@neutrinojs/jest', {
  collectCoverage: true,
  collectCoverageFrom: '**/src/components/**/*.{js,jsx}'
}]
  • What did you expect to happen?
    Coverage reports to be generated.
  • What actually happened, contrary to your expectations?
    No coverage was run.
@flouc001 flouc001 changed the title @neutrinojs/jest does not support some coverage options from .neutrinorc @neutrinojs/jest does not support some coverage options from .neutrinorc.js Aug 7, 2018
@edmorley
Copy link
Member

Hi!

To generate coverage reports when using the Neutrino 8 Jest preset, the --coverage option needs to be passed on the command line. See:
https://neutrinojs.org/packages/jest/#coverage-reporting

There should be no changes required to the Jest configuration in .neutrinorc.js.

Could you try that and report back with how it went? :-)

@edmorley
Copy link
Member

Looking at the Jest docs, using collectCoverage: true seems to be equivalent to --coverage on the CLI, however I'm presuming the reason that didn't work with Neutrino 8, is since it calls the API with an explicit coverage: args.coverage which will be false unless --coverage was passed to neutrino test, and that presumably takes precedence:
https://github.com/neutrinojs/neutrino/blob/v8.3.0/packages/jest/src/index.js#L118
https://jestjs.io/docs/en/configuration.html#collectcoverage-boolean

With Neutrino 9 (on master, not yet released), Jest's own CLI is used instead of invoking Jest by its API, and so I believe collectCoverage: true will then work as expected, should you wish to avoid needing to pass --coverage on the command line.

@flouc001
Copy link
Author

Hi @edmorley, maybe using collectCoverage was a poor example. Neutrino's docs state that you can use the jest property in the configuration file to supply any options jest recognises and it will apply them.

Take the snippet I provided above for example. I have set two options that I would like to be passed on to jest ( collectCoverage and collectCoverageFrom ). Currently it seems these settings get lost somewhere in the code for the neutrino preset.

If I run the neutrino test --coverage it still completely ignores the collectCoverageFrom option, this is not expected behaviour.

@edmorley
Copy link
Member

The options passed to the preset are merged using deepmerge, here:

return merge.all([
{
rootDir: root,
moduleDirectories,
moduleFileExtensions,
moduleNameMapper,
bail: true,
coveragePathIgnorePatterns: [neutrino.options.node_modules],
collectCoverageFrom,
testRegex,
transform: { [transformNames]: require.resolve('./transformer') },
globals: {
BABEL_OPTIONS: usingBabel
? omit(['cacheDirectory'], neutrino.config.module.rule('compile').use('babel').get('options'))
: {}
},
verbose: neutrino.options.debug
},
opts
]);
}

This does mean that for array based values, the arrays will be merged, rather than be replaced. As such at present, you'll end up with both the old and new value in the collectCoverageFrom array.

The Neutrino 8 Jest preset writes the configuration to a temporary file (a bit hacky and has been rewritten for Neutrino 9 on master) - if you find that file in the temporary directory, you can confirm what values are actually being written out.

Also, the default value for collectCoverageFrom should already include the '**/src/components/**/*.{js,jsx}' path, so long as it's under the neutrino.options.source directory? Was that not working?

@flouc001
Copy link
Author

I guess the merge is the undesirable operation in my case. Is this something that will be overridable in future versions?

@eliperelman
Copy link
Member

eliperelman commented Sep 11, 2018

In v9 you'll be able to overwrite the value from the jest.config.js file:

const neutrino = require('neutrino');

module.exports = {
  ...neutrino().jest(),
  collectCoverageFrom: /* whatever you overwrite */
};

@flouc001
Copy link
Author

flouc001 commented Sep 11, 2018

That sounds great! A worthwhile option in my opinion. I'll wait for v9 to drop.

@eliperelman
Copy link
Member

Closing as resolved.

@edmorley
Copy link
Member

@flouc001, Hi! We've just released a Neutrino 9 beta, if you'd like to try it out? See #1129.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants