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.

Documentation in regards to Test Environment

See original GitHub issue

šŸš€ Feature Proposal

(Possibly not a feature proposal, but also not a bug per se)

Having recently invested time in understanding Jest properly, one of the hardest concepts to understand was the term ā€œtest environmentā€. This was especially hard in relation to these configuration options:

globalSetup: './globalSetup.js',
globalTeardown: './globalTeardown.js',
testEnvironment: './myTestEnvironment',
setupFiles: ['./setupFiles'],
setupFilesAfterEnv: ['./setupFilesAfterEnv'],

For reference, it is good to explain some terminology:

test file testA.test.js test case test() # or it() test suite describe() (I am not sure this is true. Reason is that the documentation seems to use the word ā€œtest fileā€ and ā€œtest suiteā€ interchangeably but actually always mean ā€œtest fileā€. Never seen describe() referred specifically to ā€œtest suiteā€ in the Jest documentation, so maybe it isnā€™t a test suite?)

The problem I had with the documentation

If we take these terms, together with the ā€œtest environmentā€ term and the above configuration options, I found some parts of the documentation ambiguous.

https://jestjs.io/docs/en/configuration#setupfiles-array

Since every test runs in its own environment,

Concern: It should probably say ā€œevery test fileā€ instead of ā€œevery testā€. Refer to terminology above.

https://jestjs.io/docs/en/configuration#setupfilesafterenv-array

A list of paths to modules that run some code to configure or set up the testing framework before each test.

Concern: It should probably say ā€œbefore each test fileā€ instead of ā€œbefore each testā€. Refer to terminology above.

https://jestjs.io/docs/en/configuration#globalsetup-string

This option allows the use of a custom global setup module which exports an async function that is triggered once before all test suites.

Concern: Not sure what to write here, but ā€œbefore all test suitesā€ can be interpreted in various ways as a test suite can be considered a describe() block.

Solution proposal

It would be good to go through both the Configuring Jest and Jest CLI Options documentation, and possible all other docs, to align this properly.

I also think that in general, having a completely specific section (possibly as a guide) describing what a test environment is and how it relates to the above specified configuration options would be great. The way I learnt was to setup a project and testing all these files with a bunch of console.log to actually see what happened.

Motivation

To make it easier for newcomers to understand Jest and how to extend its functionality.

Pitch

It belongs in the main Jest documentation as that is what users refer to when learning Jest.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Feb 28, 2022

The bot runs every 10 minutes, doesnā€™t react to the comment event šŸ™‚

But yes, we should explain this better

0reactions
thernstigcommented, Feb 28, 2022

unstale

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Is Test Documentation Necessary in Software Testing?
Test documentation enables developers or other team members to learn the specifics of testing conducted on a system or product, allowing themĀ ...
Read more >
Software Testing Documentation: Types & Examples - PFLB
Test documentation includes all files that contain information on the testing team's strategy, progress, metrics, and achieved results. The combination of allĀ ...
Read more >
Test Environment for Software Testing - Guru99
A testing environment is a setup of software and hardware for the testing teams to execute test cases. In other words, it supports...
Read more >
What Is a Test Environment? A Guide to Managing Your Testing
Additionally, detailed documentation enables the testing engineer to set up different test environments, such as staging and production Ā ...
Read more >
How to Build a Testing Strategy and Environment
The question of how to build a testing environment is dependent upon the test plan and the test strategy. Both documents are immenselyĀ ......
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