Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set custom jest.config.{js,ts} even with --config flag in test CLI command #150

Closed
SeedyROM opened this issue Jun 19, 2019 · 5 comments · Fixed by #526
Closed

Cannot set custom jest.config.{js,ts} even with --config flag in test CLI command #150

SeedyROM opened this issue Jun 19, 2019 · 5 comments · Fixed by #526
Labels
kind: feature New feature or request

Comments

@SeedyROM
Copy link

SeedyROM commented Jun 19, 2019

Current Behavior

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.

Expected behavior

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.

Suggested solution(s)

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!

Additional context

The example bug repo is available here.

Your environment

Software Version(s)
TSDX 0.7.1
TypeScript 3.5.2
Browser NA
yarn 1.15.2
Operating System Ubuntu 16.04
@Aidurber
Copy link
Contributor

@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.

@SeedyROM
Copy link
Author

SeedyROM commented Oct 19, 2019

@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.

@agilgur5
Copy link
Collaborator

agilgur5 commented Feb 5, 2020

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 wmonk/create-react-app-typescript#396)

Root cause is actually Jest's very bare programmatic API: jestjs/jest#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

@wzup
Copy link

wzup commented Mar 3, 2020

The same error here. How to fix?

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 3, 2020

@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.

@agilgur5 agilgur5 added the kind: feature New feature or request label Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants