Skip to content

Extract JavaScript backend test resources to files#23066

Open
riisi wants to merge 4 commits intopantsbuild:mainfrom
riisi:lockfiles
Open

Extract JavaScript backend test resources to files#23066
riisi wants to merge 4 commits intopantsbuild:mainfrom
riisi:lockfiles

Conversation

@riisi
Copy link
Contributor

@riisi riisi commented Feb 1, 2026

Migrate test_integration_test.py to use external test resource files instead of inlined rule_runner.write_files() calls. This follows the pattern established in the TypeScript backend and makes lockfiles easier to maintain with actual package manager commands.

Changes:

  • Add test_resources/ directory with jest_project and mocha_project
  • Add testutil.py with load_js_test_project() helper
  • Refactor tests to load base projects and override specific files
  • Remove unused fixtures (_find_lockfile_resource, jest_lockfile, etc.)

Ref: #22807

Summary of changes (Claude):

src/python/pants/backend/javascript/goals/
│
│  BEFORE                                     AFTER
│  ──────                                     ─────
│
│  test_integration_test.py                   test_integration_test.py
│  ├─ ~260 lines of inlined lockfiles,       ├─ loads via load_js_test_project()
│  │  package.json, source, BUILD content     ├─ overrides only per-test variations
│  ├─ hardcoded jest_dev_dependencies         ├─ reads deps from package.json (single source of truth)
│  └─ _find_lockfile_resource() fixtures      └─ removed unused fixtures
│
│  export_test.py                             export_test.py
│  └─ reads jest_resources/package-lock.json  └─ reads test_resources/jest_project/package-lock.json
│
│  jest_resources/  ──── DELETED ────────────→ (consolidated into test_resources/jest_project/)
│  ├─ BUILD            lockfiles only,
│  ├─ package.json     no source code
│  ├─ package-lock.json
│  ├─ pnpm-lock.yaml
│  └─ yarn.lock
│
│  mocha_resources/ ──── DELETED ────────────→ (consolidated into test_resources/mocha_project/)
│  ├─ BUILD
│  ├─ package.json
│  ├─ package-lock.json
│  ├─ pnpm-lock.yaml
│  └─ yarn.lock
│
│  (nothing)                                  testutil.py ─── NEW
│                                             └─ load_js_test_project(name, package_manager)
│                                                reads files from test_resources/, filters
│                                                lockfiles by package manager
│
│  (nothing)                                  test_resources/ ─── NEW
│                                             ├─ .gitignore, README.md
│                                             ├─ jest_project/    ← lockfiles from jest_resources/
│                                             │  ├─ BUILD, package.json, lockfiles (npm/pnpm/yarn)
│                                             │  └─ src/index.mjs, tests/index.test.js
│                                             └─ mocha_project/   ← lockfiles from mocha_resources/
│                                                ├─ BUILD, package.json, lockfiles (npm/pnpm/yarn)
│                                                └─ src/index.mjs, tests/index.test.mjs
│
│  BUILD                                      BUILD
│  ├─ test_integration_test deps:             ├─ test_integration_test deps:
│  │   ./jest_resources                       │   :jest_resources, :mocha_resources
│  │   ./mocha_resources                      ├─ export_test deps:
│  │   //...javascript:test_resources         │   :jest_resources
│  └─ export_test: no resource deps           ├─ resources(name="jest_resources",
│                                             │    sources=["test_resources/jest_project/**"])
│                                             └─ resources(name="mocha_resources",
│                                                  sources=["test_resources/mocha_project/**"])

Migrate test_integration_test.py to use external test resource files
instead of inlined rule_runner.write_files() calls. This follows the
pattern established in the TypeScript backend and makes lockfiles
easier to maintain with actual package manager commands.

Changes:
- Add test_resources/ directory with jest_project and mocha_project
- Add testutil.py with load_js_test_project() helper
- Refactor tests to load base projects and override specific files
- Remove unused fixtures (_find_lockfile_resource, jest_lockfile, etc.)

Ref: pantsbuild#22807

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@riisi riisi added the category:internal CI, fixes for not-yet-released features, etc. label Feb 1, 2026
@riisi riisi marked this pull request as ready for review February 1, 2026 21:54
@riisi riisi requested a review from sureshjoshi February 1, 2026 21:54
Copy link
Contributor

@benjyw benjyw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but you can tell from my question that I am not very familiar with this code.

"test_integration_test.py": {
"dependencies": ["./jest_resources", "./mocha_resources"],
"dependencies": [
"./jest_resources",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my education: what is the distinction between these jest_resources and the ones under test_resources/jest_project?

@sureshjoshi
Copy link
Member

sureshjoshi commented Feb 9, 2026

Just need to hold back on the merge here. There were a couple of things I saw briefly I didn't understand, but need to go back through the code properly and check out.

@riisi Is there any LLM disclosure here, for places for us to focus on reviewing?

Most of this looked good - but there were a couple of changes I didn't understand at a glance when I looked at this last week.

Need to carve out some time this week to review properly - it's mostly a mechanical change, but it's a big one.

- Move test_resources/ from javascript/ into goals/, colocating
  resources with their only consumer (test_integration_test.py)
- Move testutil.py into goals/ for the same reason
- Consolidate jest_resources/ and mocha_resources/ into
  test_resources/jest_project/ and test_resources/mocha_project/,
  eliminating confusing overlap between old and new resource dirs
- Delete unused basic_package/ (no test references it)
- Replace broad resources() glob with granular per-project targets:
  :jest_resources and :mocha_resources, so each test declares only
  the resources it actually needs
- Read jest_dev_dependencies fixture from package.json instead of
  hardcoding versions, making package.json the single source of truth
- Update export_test.py to read lockfile from consolidated location
- Clean up stale BUILD deps and README references

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@riisi
Copy link
Contributor Author

riisi commented Feb 20, 2026

I've removed the stale reference that @benjyw picked up. I've also tried to make the naming and location clearer / closer to consumers, and deps more granular. I think I was trying to minimise changes in the initial pass, but I think the clarity is better.

@sureshjoshi I'm using Claude here - I tried to make that implicit via commit message, but haven't been following the disclosure discussions sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:internal CI, fixes for not-yet-released features, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments