I would like to move my jest config out of my package.json, i am trying to use the --config as suggested here but get the error argv.config.match is not a function
"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --config jest.config.js", "eject": "react-scripts eject", },
hutber@hutber-mac:/var/www/management/node$ npm test -u > [email protected] test /var/www/management/node > react-scripts test --config jest.config.js Usage: test.js [--config=<pathToConfigFile>] [TestPathPattern] argv.config.match is not a function npm ERR! Test failed. See above for more details.
Create React App uses Jest as its test runner. To prepare for this integration, we did a major revamp of Jest so if you heard bad things about it years ago, give it another try. Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser.
Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in React. npx on the first line is not a typo — it's a package runner tool that comes with npm 5.2+.
For me appending -- --config=jest.config.js
worked.
So the whole string react-scripts test -- --config jest.config.js
in your case.
TL;DR
Add --
before your options.
"test": "react-scripts test -- --config=jest.config.js",
The problem here is with react-scripts
not seeing the options being passed to it. We can demonstrate this by running it directly.
./node_modules/.bin/react-scripts test --config=jest.config.js # argv.config.match is not a function ./node_modules/.bin/react-scripts test -- --config=jest.config.js # This works.
How you pass options to scripts varies depending on which versions of npm or Yarn you use. For completeness, here are the results for the variations:
# This runs, but completely ignores the option. npm test --config=jest.config.js # These result in "argv.config.match is not a function," indicating that the # options were not understood. npm test -- --config=jest.config.js yarn test -- --config=jest.config.js yarn test --config=jest.config.js
create react app sets up the test script in package.json
with
"test": "react-scripts test",
You can set additional options like so.
"test": "react-scripts test -- --config=jest.config.js",
Something like this might work if you want to send options through the CLI.
"test": "react-scripts test --",
yarn test --bail # comes through as react-scripts test -- --bail
Here are a few resources to explain the different usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With