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.

Allow testMatch to be configurable in jest

See original GitHub issue

I want to be able to pass different testMatch https://jestjs.io/docs/en/configuration#testmatch-arraystring for Jest to run tests in specific folders

Currently, it runs tests in the entire codebase. My case is that we have a bunch of microservices, with some shared code in the parent level, such as dependencies. serverless-bundle is one of them (so it’s not installed in every MS, although it is listed in the serverless’ plugin list).

Although the rest seems to work (for example, webpack), here https://github.com/AnomalyInnovations/serverless-bundle/blob/master/scripts/config/createJestConfig.js#L23 the testMatch is hardcoded, ponting to the entire codebase. So when I run tests from one service it gets run in others. Allowing this to be configurable would allow me to run tests in a subfolder (which is only the microservice I’m interested in)

Thanks in advance

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
jayaircommented, Feb 23, 2020

@gndelia @pal I looked into it a bit more and I got this to work. Let’s take your structure:

/proy1 
  |- package.json // can run npm test from here, referring to parent `package.json`
  |- file1.js
  |- file2.js
  |- serverless.yml
/proy2
  |- package.json // can run npm test from here, referring to parent `package.json`
  |- file3.js
  |- file4.js
  |- serverless.yml
package.json // => here serverless-bundle is installed, in the root folder, as well as other plugins

In proy1/package.json use this as your test command:

  "scripts": {
    "test": "npm --prefix ./../ test proy1"
  },

This will only run the tests inside proy1/.

Let me know if that works for you.

1reaction
palcommented, Mar 25, 2020

Thanks for that idea @gndelia, it won’t work in my case however, since I’m only using a single package.json in my root dir.

For now, I’m able to use a prefix on test names and run tests using yarn test -t TESTPREFIX, or npm test -t FOLDERNAME. 🤷‍♂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
Allows for a label to be printed alongside a test while it is running. This becomes more useful in multi-project repositories where there...
Read more >
Configuring Jest compiled - w3resource
In this tutorial we will focus on configuring Jest. Jest's configuration can be defined inside the package.json file of your project, ...
Read more >
How to use different jest.config.js for unit and component tests?
To specify different config files you can use the --config option. For example if you have a tests/jest.config.js file configuration for ...
Read more >
config Flag and testMatch Option - Testing JavaScript
Run Tests with a Different Configuration using Jest's --config Flag and testMatch Option. Sometimes you may have situations where configuration needs to be ......
Read more >
Top 5 jest-config Code Examples - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
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