•  
      request #28289 Use a function to define Jest configuration
    Infos
    #28289
    Joris MASSON (jmasson)
    2022-09-09 07:38
    2022-09-08 17:10
    29862
    Details
    Use a function to define Jest configuration

    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:

    1. 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.
    2. As opposed to require(), import is hoisted at the top of the file. Nothing runs before it.
    3. The @tuleap/build-system-configurator exposes a plain object, which is executed as soon as it is imported.
    4. The plain object reads the DISABLE_TS_TYPECHECK variable, which is undefined.
    5. 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.

    Dev tools
    Empty
    Empty
    • [ ] enhancement
    • [x] internal improvement
    Empty
    Stage
    Joris MASSON (jmasson)
    Closed
    Empty
    Attachments
    Empty
    References

    Follow-ups