question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
agilgur5commented, Mar 17, 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 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

1reaction
Aidurbercommented, Oct 11, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
The file will be discovered automatically, if it is named jest.config.js|ts|mjs|cjs|json . You can use --config flag to pass an explicit ...
Read more >
Jest: Passing custom arguments - Medium
In the post i'll show how to pass custom command line arguments to test suits run by Jest framework.
Read more >
Run/Debug Configuration: Jest | JetBrains Rider Documentation
In this dialog, create configurations for running Jest tests. For information on how to create Vitest tests for JavaScript and TypeScript code, ...
Read more >
Jest CLI Options - GitHub Pages
If you run Jest via npm test , you can still use the command line arguments by inserting ... CLI options take precedence...
Read more >
Run Jest tests only for current folder - Stack Overflow
If your basic command to invoke Jest is npm test , then try with run ... When setting up the npm script add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found