rules_jest
rules_jest copied to clipboard
Supprt .ts and .cts config files via Node type-stripping
Changes are visible to end-users: yes
- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: no
TypeScript Jest configuration files can be parsed using Node's type stripping functionality.
.mts has been omitted as it is not supported by Jest.
Closes #229
Test plan
- Manual testing;
If on Node version >= 22.6.0, < 23.6.0, run a jest_test target with a .ts or .cts config file with:
env = {
"NODE_OPTIONS": "--experimental-strip-types",
},
Node versions >= 23.6.0 should just work, as type stripping is enabled by default. Node versions < 22.6.0 do not have type stripping support.
Test
52 test targets passed
Targets
//:case3 [k8-fastbuild] 4s //docs:update_test [k8-fastbuild] 151ms //example/(simple_group):cjs_config_test [k8-fastbuild] 5s //example/(simple_group):gen_config_test [k8-fastbuild] 5s //example/(simple_group):js_config_test [k8-fastbuild] 5s //example/(simple_group):json_config_test [k8-fastbuild] 6s //example/(simple_group):mjs_config_test [k8-fastbuild] 5s //example/(simple_group):other_target_config_test [k8-fastbuild] 5s //example/(simple_group):target_config_test [k8-fastbuild] 5s //example/(simple_group):test [k8-fastbuild] 5s //example/(simple_group):test_user_data [k8-fastbuild] 5s //example/custom_reporters:case1_test [k8-fastbuild] 5s //example/custom_reporters:case2_test [k8-fastbuild] 5s //example/custom_sequencer:case1_test [k8-fastbuild] 12s //example/custom_sequencer:case2_test [k8-fastbuild] 10s //example/custom_snapshot_resolver:test [k8-fastbuild] 8s //example/custom_snapshot_resolver_files:test [k8-fastbuild] 6s //example/esm:test [k8-fastbuild] 5s //example/esm_transform:test [k8-fastbuild] 6s //example/esm_type_module:test [k8-fastbuild] 5s //example/multiple_snapshots:test [k8-fastbuild] 7s //example/sharding:test [k8-fastbuild] 10s //example/simple:cjs_config_test [k8-fastbuild] 6s //example/simple:gen_config_test [k8-fastbuild] 6s //example/simple:js_config_test [k8-fastbuild] 5s //example/simple:json_config_test [k8-fastbuild] 5s //example/simple:mjs_config_test [k8-fastbuild] 5s //example/simple:other_target_config_test [k8-fastbuild] 5s //example/simple:target_config_test [k8-fastbuild] 5s //example/simple:test [k8-fastbuild] 5s //example/simple:test_user_data [k8-fastbuild] 5s //example/snapshots:test [k8-fastbuild] 7s //example/snapshots_files:test [k8-fastbuild] 7s //jest/tests/case10:test [k8-fastbuild] 5s //jest/tests/case10a:test [k8-fastbuild] 5s //jest/tests/env_inherit:test [k8-fastbuild] 5s //jest/tests/fixed_args:fixed_args_test [k8-fastbuild] 923ms //jest/tests/fixed_args:test [k8-fastbuild] 4s //jest/tests/package_json_module:test [k8-fastbuild] 8s //jest/tests:case1 [k8-fastbuild] 5s //jest/tests:case11a [k8-fastbuild] 5s //jest/tests:case11b [k8-fastbuild] 5s //jest/tests:case12 [k8-fastbuild] 5s //jest/tests:case13 [k8-fastbuild] 5s //jest/tests:case14 [k8-fastbuild] 5s //jest/tests:case2a [k8-fastbuild] 4s //jest/tests:case2b [k8-fastbuild] 5s //jest/tests:case5 [k8-fastbuild] 4s //jest/tests:case6 [k8-fastbuild] 5s //jest/tests:case7 [k8-fastbuild] 5s //jest/tests:case8 [k8-fastbuild] 5s //jest/tests:case9 [k8-fastbuild] 5s
Total test execution time was 4m 37s. 13 tests (20.0%) were fully cached saving 814ms.
Buildifier
Format
What's the reason for doing this with rules_jest specifically? I'd like to have some discussions about this in rules_js before we start enabling it for random files such as jest config...
@jbedard forgive me if I'm lacking context, but I feel like rules_jest shouldn't limit which config file types can be passed to Jest. Should rules_jest not just plumb through whatever file is provided, and if Jest or Node can't parse it, then just let them error?
Compiling the config file with ts_project beforehand will work, but it's extra boilerplate that doesn't really provide any benefit if I'm already type checking the config file in another target.
If Jest and the latest version of Node both support TypeScript config files without any additional configuration, why should rules_jest disallow TypeScript?
I'd like to have some discussions about this in rules_js before we start enabling it for random files such as jest config...
Just so we're on the same page, this PR doesn't enable/enforce the usage of type stripping in rules_jest, it just removes the restriction on .ts and .cts config file types so that people who have type stripping enabled can use TypeScript.