vitest_helpers.ts

view source

Declarations
#

3 declarations

find_test_files
#

vitest_helpers.ts view source

(fs_paths: FsPaths, dir: string): Promise<FsSearchResult[]> import {find_test_files} from '@fuzdev/gro/vitest_helpers.js';

Finds the files gro test would run in dir with its default pattern, by Vitest's own rules rather than Gro's search_filters, which Vitest never sees: a test beneath a build/ or .-prefixed directory runs, so it's found here too.

Symlinks are followed as Vitest follows them, through fs_paths, so a link out of the project reaches what it points at, and a dangling one is skipped. A path is matched as it's named through the links, and the pattern can match a directory's name, so each real directory is searched at most once with and once without a matching name above it. That finds every file Vitest would and ends on a loop, which Vitest follows one level in.

fs_paths

opens dir and each symlink beneath it

type FsPaths

dir

the test directory, absolute

type string

returns

Promise<FsSearchResult[]>

the test files sorted by path, named through the links, with kind the listed one; an empty array when nothing is at dir

throws

  • FsError - when `dir` isn't a directory, or a listing or a symlink's resolution fails

project_has_vitest
#

vitest_helpers.ts view source

(fs_paths: FsPaths, log?: Logger | undefined): Promise<boolean> import {project_has_vitest} from '@fuzdev/gro/vitest_helpers.js';

Whether the project's package.json declares Vitest as a direct dependency. Peer deps don't count - a package peered on Vitest is built to work with one, which says nothing about whether the package has tests of its own to run. Read without the schema, as only its dependencies matter, and one that can't be read declares nothing.

fs_paths

reads the project's package.json

type FsPaths

log?

reports a package.json that exists but can't be read or parsed; with none, stays silent

type Logger
optional

returns

Promise<boolean>

whether the project declares Vitest

TEST_FILE_PATTERN
#

vitest_helpers.ts view source

".test." import {TEST_FILE_PATTERN} from '@fuzdev/gro/vitest_helpers.js';

The file pattern gro test passes to Vitest by default, which keeps the files whose path beneath the test directory contains it, ignoring case.

Depends on
#

Imported by
#