-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(jest-config):Support loading TS config files via docblock loader #15190
Conversation
✅ Deploy Preview for jestjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Thanks for sending a PR!
I think we should change default behaviour in a separate PR, just to keep the scope per PR down a bit |
Should I update docs in a separate PR ? after current one and PR which changes default behaviour lands |
Updating the docs here with info about the docblock makes sense. Even though we might delete parts of the new docs when changing default behaviour 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! just some nits 🙂
@@ -105,36 +121,57 @@ const loadTSConfigFile = async ( | |||
return configObject; | |||
}; | |||
|
|||
let registeredCompilerPromise: Promise<Service>; | |||
let registeredCompilerPromise: Promise<TsLoader>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this needs to be a Map<TsLoaderModule, Promise<TsLoader>>
? I'm thinking in cases where multi projects are used, and some project uses a different TS loader. That might already not work if the loaders get in the way of each other, tho.
Maybe a better thing would just be to save what module was loaded, and then throw an error if later another one is attempted to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added integration tests for different loaders in different projects and they seem to be working fine d2c3a8d
do we still need to save the loader and doesn't allow using a different one?
export default config; | ||
``` | ||
|
||
If you are using `ts-node`, you can set `JEST_CONFIG_TRANSPILE_ONLY` environment variable to `true` (case insensitive) to read configuration files without typechecking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for this PR, but maybe in a follow-up - should we drop this new env variable and use docblock config instead (like we support for test environment: https://jestjs.io/blog/2022/04/25/jest-28#inline-testenvironmentoptions)? Then people could also e.g. opt into using swc
(https://typestrong.org/ts-node/docs/swc/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would be better, will send PR for that
we might also need to add support for swc based loader at some point #12156
const tsLoader = docblockPragmas['jest-config-loader'] || 'ts-node'; | ||
|
||
if (Array.isArray(tsLoader)) { | ||
throw new TypeError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working when passing multiple loaders like this
/**@jest-config-loader ts-node esbuild-register*/
it simply returns a string 'ts-node esbuild-register'
instead of returning an array of strings ['ts-node','esbuild-register']
is this an expected behavior or a bug in jest-docblock
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's expected - for it to be an array you'd need to do
/**
* @jest-config-loader ts-node
* @jest-config-loader esbuild-register
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job, thanks!
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. |
Summary
Unblocks #13143
Unblocks #11989
Added support for loading Typescript configuration files by specifying a loader in a docblock comment in config file.
this is a continuation of work done in #13742
one can define a loader in a docblock comment like this:
if there is no loader defined it uses
ts-node
by default for loading a config file.currently there is support for
esbuild-register
andts-node
.Test plan
Added e2e tests