diff --git a/docs/jest_test.md b/docs/jest_test.md index d8bedaf..22b0367 100644 --- a/docs/jest_test.md +++ b/docs/jest_test.md @@ -26,7 +26,7 @@ Supports updating snapshots with `bazel run {name}_update_snapshots` if `snapsho | :------------- | :------------- | :------------- | | name | A unique name for this target. | none | | node_modules | Label pointing to the linked node_modules target where jest is linked, e.g. `//:node_modules`. `jest-cli` must be linked into the node_modules supplied. `jest-junit` is also required by default when `auto_configure_reporters` is True.

NB: Only the required npm packages are included in data from `//:node_modules`. Other npm packages are not included as inputs. | none | -| config | "Optional Jest config file. See https://jestjs.io/docs/configuration.

Supported config file types are ".js", ".cjs", ".mjs", ".json" which come from https://jestjs.io/docs/configuration minus TypeScript since we this rule extends from the configuration. TypeScript jest configs should be transpiled before being passed to jest_test with [rules_ts](https://github.com/aspect-build/rules_ts). | `None` | +| config | "Optional Jest config file. See https://jestjs.io/docs/configuration.

Supported config file types are ".js", ".cjs", ".mjs", ".ts", ".cts", ".json" which come from https://jestjs.io/docs/configuration. TypeScript jest configs can either be transpiled before being passed to jest_test with [rules_ts](https://github.com/aspect-build/rules_ts), or loaded natively with Node's [type stripping](https://nodejs.org/en/learn/typescript/run-natively) functionality. | `None` | | data | Runtime dependencies of the Jest test.

This should include all test files, configuration files & files under test. | `[]` | | snapshots | If True, a `{name}_update_snapshots` binary target is generated that will update all existing `__snapshots__` directories when `bazel run`. This is the equivalent to running `jest -u` or `jest --updateSnapshot` outside of Bazel, except that new `__snapshots__` will not automatically be created on update. To bootstrap a new `__snapshots__` directory, you can create an empty one and then run the `{name}_update_snapshots` target to populate it.

If the name of the snapshot directory is not the default `__snapshots__` because of a custom snapshot resolver, you can specify customize the snapshot directories with a `glob` or a static list. For example,

jest_test(
    name = "test",
    node_modules = "//:node_modules",
    config = "jest.config.js",
    data = [
        "greetings/greetings.js",
        "greetings/greetings.test.js",
        "link/link.js",
        "link/link.test.js",
    ],
    snapshots = glob(["**/__snaps__"], exclude_directories = 0),
)


or with a static list,

    snapshots = [
        "greetings/__greetings_snaps__",
        "link/__link_snaps__",
    ]


Snapshots directories must not contain any files except for snapshots. There must also be no BUILD files in the snapshots directories since they must be part of the same Bazel package that the `jest_test` target is in.

If snapshots are _not_ configured to output to a directory that contains only snapshots, you may alternately set `snapshots` to a list of snapshot files expected to be generated by this `jest_test` target. These must be source files and all snapshots that are generated must be explicitly listed. You may use a `glob` such as `glob(["**/*.snap"])` to generate this list, in which case all snapshots must already be on disk so they are discovered by `glob`. | `False` | | run_in_band | When True, the `--runInBand` argument is passed to the Jest CLI so that all tests are run serially in the current process, rather than creating a worker pool of child processes that run tests. See https://jestjs.io/docs/cli#--runinband for more info.

This is the desired default behavior under Bazel since Bazel expect each test process to use up one CPU core. To parallelize a single jest_test across many cores, use `shard_count` instead which is supported by `jest_test`. See https://docs.bazel.build/versions/main/test-encyclopedia.html#test-sharding. | `True` | diff --git a/jest/defs.bzl b/jest/defs.bzl index f7abf84..e9f93ba 100644 --- a/jest/defs.bzl +++ b/jest/defs.bzl @@ -66,9 +66,10 @@ def jest_test( config: "Optional Jest config file. See https://jestjs.io/docs/configuration. - Supported config file types are ".js", ".cjs", ".mjs", ".json" which come from https://jestjs.io/docs/configuration - minus TypeScript since we this rule extends from the configuration. TypeScript jest configs should be transpiled - before being passed to jest_test with [rules_ts](https://github.com/aspect-build/rules_ts). + Supported config file types are ".js", ".cjs", ".mjs", ".ts", ".cts", ".json" which come from https://jestjs.io/docs/configuration. + TypeScript jest configs can either be transpiled before being passed to jest_test with + [rules_ts](https://github.com/aspect-build/rules_ts), or loaded natively with Node's + [type stripping](https://nodejs.org/en/learn/typescript/run-natively) functionality. data: Runtime dependencies of the Jest test. diff --git a/jest/private/jest_test.bzl b/jest/private/jest_test.bzl index 2f2b673..e49e49d 100644 --- a/jest/private/jest_test.bzl +++ b/jest/private/jest_test.bzl @@ -6,7 +6,7 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts") load("@bazel_skylib//lib:paths.bzl", "paths") _attrs = dicts.add(js_binary_lib.attrs, { - "config": attr.label(allow_single_file = [".js", ".cjs", ".mjs", ".json"]), + "config": attr.label(allow_single_file = [".js", ".cjs", ".mjs", ".ts", ".cts", ".json"]), "auto_configure_reporters": attr.bool(default = True), "auto_configure_test_sequencer": attr.bool(default = True), "run_in_band": attr.bool(default = True),