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.

Should test configuration `setupTests.{ts,js}` be per-application? Should tests be run globally against the project or are they run against specific applications?

See original GitHub issue

Should test configuration setupTests.{ts,js} be per-application?

I noticed that CRA would only load the setupTests.{js,ts} of one application and amended our test configuration to load the test configuration of each application. This was done because I didn’t want any one application to be special-cased as containing the configuration for all other application’s tests, however since all of the setupTest files are loaded when the tests are run, it means that if you make a change to the configuration you do so for everybody. There could be conflicts.

Should tests be run globally against the project or will they be run against specific applications?

I thought the former was what we were trying to achieve, and if that’s the case and presuming that others agree that distributing configuration across a repository is a Bad Idea™, then it seems like a good idea to move to having a single setupTests.{js,ts} at the root of the modular project.

However, it’s also possible that every application could have their own modular test [app-name] command that they run. This would certainly be helpful when migrating applications with differing test configuration into a single repository. Additionally:

  • Are there long-term benefits to making modular test work this way?
  • What about packages and widgets that aren’t part of the application, but are depended upon by it – how would we know that the tests for these should be run with a particular application’s modular test [app-name] command and that its setupTests configuration will run these correctly?
  • When you make a change to a design system that affects all application’s within a single repository, what test command would you use to make sure nothing is broken – presumably there would still need to be a modular test command without an [app-name] argument that can run all of the tests and that would need to be configured with every single setupTests.{ts,js} within the repository?

See also: https://github.com/jpmorganchase/modular/pull/100#discussion_r490486855

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
threepointonecommented, Sep 18, 2020

Honestly, maybe that’s a good place to draw a line in the sand. They’re welcome to unmock/remock in individual files, and if it’s a lot, they can codemod the boilerplate. Let’s strive for a singular setupTests for now, and play it by ear. Should be an enlightening exercise.

0reactions
sebinsuacommented, Sep 21, 2020

I’ll make this change this week.

What I’m tempted to do is to leave the logic which loads packages/*/src/setupTest.{js,ts} since this is CRA-like (and their docs would tell people to put setupTests files here – the other possibility I guess is that I could console.warn about this). But, importantly, I would copy the default setupTests.{js,ts} file into the modular root by default and document that this is the correct location.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest 'setupFiles' with <rootDir> breaks libs/apps tests #2344
Prerequisites I am running the latest version I checked the documentation (nx.dev) and found no answer I checked to make sure that this ......
Read more >
Testing with Spring Boot's @TestConfiguration Annotation
The @TestConfiguration annotation is a useful aid for writing unit tests of components in a Spring Boot application. It allows us to define ......
Read more >
Configuring Jest
A global setup module configured in a project (using multi-project runner) will be triggered only when you run at least one test from...
Read more >
46. Testing
A Spring Boot application is a Spring ApplicationContext , so nothing very special has to be done to test it beyond what you...
Read more >
Setup | Testing Library
In these docs we'll demonstrate configuring Jest, but you should be able to do similar things with any testing framework (React Testing Library ......
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