After request #27529, we can set environment variables to control whether Jest should try to do the typechecking or not (among other things). In an ES module context (type="module"
in package.json
), we are forced to use import
instead of require()
to get the base Jest configuration. The following facts apply:
-
require()
could be called anywhere, so we could easily write an env variable, call it, and it would read the env variable in the right order.
- As opposed to
require()
, import
is hoisted at the top of the file. Nothing runs before it.
- The
@tuleap/build-system-configurator
exposes a plain object, which is executed as soon as it is import
ed.
- The plain object reads the
DISABLE_TS_TYPECHECK
variable, which is undefined.
- The "specific" jest configuration then executes and writes the
DISABLE_TS_TYPECHECK
, but it's too late as it has already been read.
The workaround to this problem was to set DISABLE_TS_TYPECHECK
in the package.json
test
script, before jest
. However, it does not work when running jest
directly, which is what our IDE does when we run tests directly in the test file. It would fail due to some obscure TypeScript error, because it would (wrongly) try to do the typechecking.
To address this in a better way, we should modify @tuleap/build-system-configurator
so that it exposes a function. Functions only execute when called, which means we can safely import
it, define some env variables, and then call it, and it will see our env variables.
This "breaking" change in the configurator means we have to update all jest.config
files.