The test command's --config, -c flags throw a nondescript error when passed any value.
$ yarn run tsdx test --config=./jest.config.js --env=jsdom
...Usage...
argv.config.match is not a function
This also doesn't load the test command in watch mode as the documentation specified.
Either having a jest.config.{js,ts} in the project root or specifying one via the config flag in your tsdx test should actually be loaded on setup.
Quickfix:
Just move all your configuration into package.json under the "jest" key.
Long term fix:
I can't seem to find the bug first thing in index.ts, but this is definitely where things are going wrong.
I will update this issue as I study it more!
The example bug repo is available here.
| Software | Version(s) |
| ---------------- | ---------- |
| TSDX | 0.7.1 |
| TypeScript | 3.5.2 |
| Browser | NA |
| yarn | 1.15.2 |
| Operating System | Ubuntu 16.04 |
@SeedyROM @jaredpalmer I'm taking a quick look at this and I'm unsure what would be the correct fix.
The easiest is to check if the args already contain a config (here), if it does then don't push the tsdx config.
Or do we merge in the contents of the supplied config with the tsdx config? It would probably need to be a deep merge if you need to add in custom transforms into your jest config such as CSS transforms.
@Aidurber I think a deep merge would be appropriate, but I'm not an expert on this library. So take my opinion with a grain of salt.
Ran into this myself during some testing (and, notably, TSDX itself uses jest --config) and did some further investigation.
This same error, argv.config.match is not a function also occurs with CRA (tried it myself), as it uses the same code for config:
https://github.com/facebook/create-react-app/blob/687c4ebf211ad30238f2d59e063b8171e015bfc7/packages/react-scripts/scripts/test.js#L73-L82
(also https://github.com/wmonk/create-react-app-typescript/issues/396)
Root cause is actually Jest's very bare programmatic API: https://github.com/facebook/jest/issues/5048
Until Jest's programmatic API becomes better, I do think checking if argv already has a config and merging that in would be optimal.
Currently package.json.jest and jest.config.js aren't deep merged, just shallow merged.
Also this is related to #100 as jest.config.js was previously not read at all, by default or with --config until #229
The same error here. How to fix?
@wzup you can use a jest.config.js in your project root already (was added in #229 above). I wrote up a PR for --config a few days ago in #526 above.
Most helpful comment
Ran into this myself during some testing (and, notably, TSDX itself uses
jest --config) and did some further investigation.This same error,
argv.config.match is not a functionalso occurs with CRA (tried it myself), as it uses the same code for config:https://github.com/facebook/create-react-app/blob/687c4ebf211ad30238f2d59e063b8171e015bfc7/packages/react-scripts/scripts/test.js#L73-L82
(also https://github.com/wmonk/create-react-app-typescript/issues/396)
Root cause is actually Jest's very bare programmatic API: https://github.com/facebook/jest/issues/5048
Until Jest's programmatic API becomes better, I do think checking if
argvalready has a config and merging that in would be optimal.Currently
package.json.jestandjest.config.jsaren't deep merged, just shallow merged.Also this is related to #100 as
jest.config.jswas previously not read at all, by default or with--configuntil #229