Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 5.65 KB

vitest_test.md

File metadata and controls

38 lines (26 loc) · 5.65 KB

Public API for Vitest rules

vitest_test

vitest_test(name, node_modules, config, data, snapshots, auto_configure_reporters,
            auto_configure_test_sequencer, snapshots_ext, quiet_snapshot_updates, timeout, size,
            kwargs)

vitest_test rule

Supports Bazel sharding. See https://docs.bazel.build/versions/main/test-encyclopedia.html#test-sharding.

PARAMETERS

Name Description Default Value
name A unique name for this target. none
node_modules Label pointing to the linked node_modules target where vitest is linked, e.g. //:node_modules. @vitest/coverage-v8 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 Vitest config file. See https://vitest.dev/config/file.html.

Supported config file types are ".js", ".cjs", ".mjs" which come from https://vitest.dev/config/file.html minus TypeScript since we this rule extends from the configuration. TypeScript vitest configs should be transpiled before being passed to vitest_test with rules_ts.
None
data Runtime dependencies of the Vitest 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 vitest -u or vitest --update 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,

vitest_test(
    name = "test",
    node_modules = "//:node_modules",
    config = "vitest.config.mjs",
    data = [
        "greetings/greetings.jsx",
        "greetings/greetings.test.jsx",
        "link/link.jsx",
        "link/link.test.jsx",
    ],
    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 vitest_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 vitest_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
auto_configure_reporters Let vitest_test configure reporters for Bazel test and xml test logs.

The default reporter is used for the standard test log and junit is used for the xml log. These reporters are appended to the list of reporters from the user Vitest config only if they are not already set.
True
auto_configure_test_sequencer Let vitest_test configure a custom test sequencer for Bazel test that support Bazel sharding.

Any custom test.sequence.sequencer value in a user Vitest config will be overridden.

See https://vitest.dev/config/#sequence-sequencer for more information on Vitest test.sequence.sequencer config option.
True
snapshots_ext The expected extensions for snapshot files. Defaults to .snap, the Vitest default. ".snap"
quiet_snapshot_updates When True, snapshot update stdout & stderr is hidden when the snapshot update is successful.

On a snapshot update failure, its stdout & stderr will always be shown.
False
timeout standard attribute for tests. Defaults to "short" if both timeout and size are unspecified. None
size standard attribute for tests None
kwargs Additional named parameters passed to both js_test and js_binary. See https://github.com/aspect-build/rules_js/blob/main/docs/js_binary.md none