jest icon indicating copy to clipboard operation
jest copied to clipboard

feat(jest-config): Support using esbuild-register for loading TS configs

Open MasterOdin opened this issue 2 years ago • 3 comments

Summary

PR adds support for using esbuild-register as a support loader for the jest.config.ts file. The user can opt into using it by using a docblock (@jest-config-loader) and suggested as part of #13143.

This PR would supercede the work done in #12041.

The motivation for the PR is that I do not use ts-node in my projects, rather I use esbuild (through tsx) and that esbuild-register allows for me to reuse existing modules I've installed for my project, rather than installing ts-node just to read the jest.config.ts file.

The eventual goal would be to add some additional modules (e.g. tsx), but that'll require a bit of upstream work first to support how jest enables and then disables the module after it's done parsing the jest.config.ts file.

Test plan

I've added a new e2e test that should pass:

$ yarn jest e2e/__tests__/readInitialOptions.test.ts
 PASS  e2e/__tests__/readInitialOptions.test.ts
  readInitialOptions
    ✓ should read from the cwd by default (67 ms)
    ✓ should read a jest.config.js file (60 ms)
    ✓ should read a package.json file (63 ms)
    ✓ should read a jest.config.ts file with ts-node (543 ms)
    ✓ should read a jest.config.ts file with esbuild-register (150 ms)
    ✓ should read a jest.config.mjs file (61 ms)
    ✓ should read a jest.config.json file (67 ms)
    ✓ should read a jest config exporting an async function (64 ms)
    ✓ should be able to skip config reading, instead read from cwd (66 ms)
    ✓ should give an error when there are multiple config files (59 ms)
    ✓ should be able to ignore multiple config files error (64 ms)

Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total
Snapshots:   0 total
Time:        1.542 s
Ran all test suites matching /e2e\/__tests__\/readInitialOptions.test.ts/i.

MasterOdin avatar Jan 07 '23 19:01 MasterOdin

Hi @MasterOdin!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Jan 07 '23 19:01 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar Jan 07 '23 21:01 facebook-github-bot

@MasterOdin ping 🙂

SimenB avatar Jan 14 '23 09:01 SimenB

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Apr 14 '23 10:04 github-actions[bot]

This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one.

github-actions[bot] avatar May 14 '23 10:05 github-actions[bot]

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Jun 14 '23 00:06 github-actions[bot]