Skip to content

gazelle/javascript,typescript: resolve test config setup files as deps - #4649

Merged
TrapsterDK merged 1 commit into
mainfrom
gazelle-test-config-string-deps
Oct 28, 2026
Merged

TrapsterDK merged 1 commit into
mainfrom
gazelle-test-config-string-deps

Conversation

@TrapsterDK

Copy link
Copy Markdown
Collaborator

Follow-up to #4644 for the other languages: modules that a test tool loads by a string declaration instead of an import.

Implemented

JavaScript and TypeScript: jest.config.*, vitest.config.*, and vite.config.* (any JS/TS module extension) add deps for literal entries of setupFiles, setupFilesAfterEnv, globalSetup, globalTeardown, and snapshotSerializers.

  • string values or arrays of strings, quoted or bare keys, nested (test: { setupFiles })
  • a leading <rootDir>/ is read as the config's directory
  • dynamic entries (calls, concatenation, templates, spreads, variables) are skipped; literal entries next to them are kept
  • relative entries resolve to local targets; package entries go through the npm lookup, # gazelle:resolve, and # gazelle:dx_ignore_import

Code: gazelle/common/jstestconfig.go, used through common.ParseSourceImportRefs from both extensions. Tests: gazelle/common/jstestconfig_test.go and new generation fixtures gazelle/{javascript,typescript}/testdata/test_config. bazel test //gazelle/common:common_test //gazelle/javascript/... //gazelle/typescript/... passes.

Considered, not implemented

  • Jest testEnvironment, reporters, transform, preset, runner: names map to packages by prefix rules (jsdom to jest-environment-jsdom) or include built-ins, so not a static literal mapping.
  • Mocha .mocharc.* require, Karma, package.json jest key: config is JSON/YAML or not a source the extension parses.
  • Ruby RSpec .rspec --require spec_helper: a non-source file that would need to add a dep to every spec under it; require in spec_helper.rb is already an import.
  • Elixir Code.require_file(..., __DIR__) in test_helper.exs: a file-path load that needs srcs/data, not a module dep.
  • Java, Kotlin, Scala: JUnit @ExtendWith/@RunWith/@Suite are class references and already resolve; META-INF/services and junit-platform.properties are resources, not sources.
  • Go: no string module loading in go test; //go:embed is data.
  • Rust: #[path] changes module layout within the crate, not deps.
  • PHP phpunit.xml bootstrap, Lua busted .busted helper: XML/Lua config files the extensions do not parse.
  • Julia include("x.jl"): same-package file inclusion, not a dependency.
  • Python pytest.ini/pyproject.toml addopts = -p plugin and pytest11 entry points: config and packaging metadata, not sources.

🤖 Generated with Claude Code

Literal setupFiles, setupFilesAfterEnv, globalSetup, globalTeardown, and
snapshotSerializers entries in jest, vitest, and vite configs now add the
named modules to the config's rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011u9TXHDZrfmzFQ2WT8QAKK
@TrapsterDK
TrapsterDK merged commit 594621e into main Oct 28, 2026
0 of 32 checks passed
@TrapsterDK
TrapsterDK deleted the gazelle-test-config-string-deps branch October 28, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant