Skip to content

test: prune redundant utils tests and fold lookup tables - #1099

Merged
sxzz merged 1 commit into
mainfrom
claude/prune-tests-utils-test-duplicates
Oct 14, 2026
Merged

sxzz merged 1 commit into
mainfrom
claude/prune-tests-utils-test-duplicates

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Requested by Brooklyn · project thread

AI usage

  • No AI was used in this PR.
  • AI was used: Claude Code (scheduled "prune unnecessary tests" routine)
    • I have carefully reviewed the AI-generated content myself.

Description

Before: a few unit tests in src/utils and packages/css could not fail when the product broke. Two tested the native Promise.withResolvers after the helper they once covered was removed, three repeated assertions a stronger neighbour already makes, and one had its only assertion behind an if. Several describe blocks were hand-unrolled input/output tables.

After: those 6 cases are gone, and one of them is folded into a real nested-lookup check that catches a regression the old test missed. 47 hand-unrolled cases are now 9 test.each tables with every row and test name kept. Only test files change.

How: each candidate was defended by mutating product code with the most realistic regression only it would catch, running the whole suite, and reverting. Every deleted case has another test that fails on that mutation.

Totals

  • Files touched: 6, all test files.
  • Cases deleted: 6 of 540 in the suite (Vitest collection at the merge-base: 536 passed, 4 skipped; after: 534 = 530 passed, 4 skipped).
  • Cases folded into a stronger test: 1 (readPackageJson › returns result with packageJsonPath property into reads package.json from directory).
  • Lookup-table rows folded into test.each: 47 rows in 9 tables; case count unchanged.
  • Net lines: -107 (+120 / -227).
  • Runtime saved: 33.0 ms, the summed duration of the removed cases.
  • Touched files' run time on this machine (Vitest "Duration", 3 runs): before 2.46 / 2.32 / 1.44 s, after 1.64 / 1.45 / 1.32 s. Transform and setup dominate, so most of that difference is noise.

Per file

  1. src/utils/general.test.ts › promiseWithResolvers (2 cases: returns a promise that resolves, resolve is callable before awaiting)
  2. src/utils/logger.test.ts › LogLevels › silent < error < warn < info (1 case)
    • Class: strict-subset duplicate. has correct numeric ordering asserts the exact values 0/1/2/3, which imply the ordering.
    • Best defense: mutation 2 (swap levels) fails both LogLevels tests, 7 other logger tests and exports › no entries.
    • Still covered by has correct numeric ordering.
  3. src/utils/logger.test.ts › suppressWarnings › warns normally when suppressWarnings is not set (1 case)
    • Class: strict-subset duplicate of createLogger › info level outputs all messages (same setup; that test already asserts warn is called once).
    • Best defense: mutation 3 (unset suppressWarnings suppresses everything) also fails info level outputs all messages, warn level outputs warnings and errors, warnOnce only warns once, both failOnWarn logger tests, e2e › failOnWarn and exports › no entries.
    • Still covered by info level outputs all messages and warn level outputs warnings and errors.
  4. packages/css/src/options.test.ts › modules defaults to empty object (1 case)
    • Class: strict-subset duplicate. Same input as defaults, whose toEqual already asserts modules: {}.
    • Best defense: mutation 4 (?? {} → ?? undefined) also fails defaults and custom options are passed through.
    • Still covered by defaults.
  5. src/utils/package.test.ts › returns result with packageJsonPath property (1 case, folded)
    • Class: strict-subset duplicate whose only assertion sat inside if (result).
    • Best defense: mutation 6 (disable the upward package.json search). The old test passed it.
    • Fold: reads package.json from directory now also reads from <testDir>/src/nested and asserts it resolves to the parent package.json. Under mutation 6 the folded test fails, along with 15 e2e/shims cases.

Folds (lookup tables → test.each, every row and name kept)

File Table Rows Mutation that still fails a row
src/utils/general.test.ts toArray 8 M9: both default-value rows
src/utils/general.test.ts resolveComma 4 M13: 2 rows
src/utils/general.test.ts slash 4 M8: 1 row
src/utils/fs.test.ts lowestCommonAncestor 7 M12: 1 row
src/utils/fs.test.ts stripExtname 6 M10: 2 rows
src/utils/json.test.ts detectIndent 5 M11: tab row
src/utils/logger.test.ts prettyFormat 3 M14: 1 row
src/utils/package.test.ts getPackageType (non-throwing rows) 4 M15: 2 rows
src/utils/package.test.ts normalizeFormat 6 M7: the module row

The collected test names for all 47 rows are identical before and after.

Kept after defense — do not re-nominate

No nominee survived its defense. Considered and left alone because they are not in a pruning class: packages/migrate/tests/index.test.ts › migrates single explicitly specified dir, src/features/plugin.test.ts › plain Rolldown plugin without hooks is a no-op, src/utils/package.test.ts › reads package.json with type field, src/utils/chunks.test.ts › returns empty array for empty input, the exports.test.ts inline snapshots and the testBuild file snapshots (they pin specific rendered states).

Case counts (Vitest collection)

file before after delta expected delta
src/utils/general.test.ts 37 35 -2 -2
src/utils/logger.test.ts 25 23 -2 -2
src/utils/package.test.ts 14 13 -1 -1
src/utils/fs.test.ts 23 23 0 0
src/utils/json.test.ts 13 13 0 0
packages/css/src/options.test.ts 12 11 -1 -1
touched total 124 118 -6 -6
whole suite 540 534 -6 -6

0 failures before and after, so 0 new failures. The 4 tests/exe.test.ts skips are identical before and after.

Mutations

Each was applied to product code, the whole suite was run, then the change was reverted (git diff showed no product files afterwards).

  1. src/features/pkg/index.ts:36, resolve replaced by a no-op: 5 e2e cases and issues "exports" feature produces incorrect output for multiple entry points #566 / Bug: Scoped CSS not transforming correctly; styles leaking to global scope without data-v attributes #837 fail; the promiseWithResolvers nominees pass.
  2. src/utils/logger.ts:23-24, warn/info levels swapped: both LogLevels tests, 7 more logger tests and exports › no entries fail.
  3. src/utils/logger.ts createSuppressWarnings, with no patterns returns () => true: the nominee plus the 7 tests listed under file 3 fail.
  4. packages/css/src/options.ts:240, ?? {} → ?? undefined: defaults, the nominee and custom options are passed through fail.
  5. src/utils/package.ts:19, reads dir + '/package.json' instead of the found path: 207 cases fail, including the nominee.
  6. src/utils/package.ts:16, findPackage({ cwd: dir, last: dir }) (no upward search): the folded reads package.json from directory and 15 e2e/shims cases fail; the old nominee passed.
  7. src/utils/package.ts:40, removed case 'module':: only the normalizes "module" to "es" row fails.
  8. src/utils/general.ts:34, replaceAll → replace: the slash row and deps.test › parseNodeModulesPath normalizes backslashes… fail.
  9. src/utils/general.ts:10, removed the defaultValue branch: 216 failures, including both default rows.
  10. src/utils/fs.ts:51, returns '' with no extension: 2 stripExtname rows and entry.test › toObjectEntry array entry fail.
  11. src/utils/json.ts:54, tab case returns match[1].length: detectIndent › tab and writeJsonFile › preserves tab indentation fail.
  12. src/utils/fs.ts:26, single path returns the path instead of its dirname: 152 failures, including the row.
  13. src/utils/general.ts:18, split(',') → split(', '): 2 resolveComma rows and css options › css.target with comma-separated values fail.
  14. src/utils/logger.ts:179, 'ESM' → 'ES': the prettyFormat es row fails.
  15. src/utils/package.ts:28, if (!pkg?.type) return 'commonjs': the 2 "returns undefined" rows fail.

What ran and what did not

  • Ran: the whole suite at the merge-base (3a51daa) and after, with per-test durations; the touched files 3 times each before and after; 15 whole-suite mutation runs; tsc --noEmit over the project; eslint --max-warnings 0 and prettier --check on the touched files. Dependencies were installed with pnpm 12.11.2 (the devEngines version) and --frozen-lockfile.
  • Not run: the whole-repo pnpm lint, the docs build, and the exe tests (skipped on this platform before and after).

Excluded pull requests

Files changed by these open PRs were skipped: #1098, #1097, #1093, #1092, #1089, #1085, #1080, #1078, #1077, #1074, #1068, #1049, #920. None of the files this PR changes is touched by them.

Age check (cutoff: 30 days, 2026-09-14)

Deleted case First added
promiseWithResolvers × 2 2026-01-30 (096b051, #737); rewritten to the native API 2026-07-24 (3dec506)
LogLevels › silent < error < warn < info 2026-01-30 (096b051)
warns normally when suppressWarnings is not set 2026-07-13 (dc51011)
modules defaults to empty object 2026-03-16 (2a88a67, #834)
returns result with packageJsonPath property 2026-01-30 (096b051)

None of the deleted cases was added for a bug, and none is in a permission, security or entitlement suite.

Checks

  • Tests: whole suite 534 collected, 530 passed, 4 skipped, 0 failed.
  • Type-check: tsc --noEmit clean.
  • Lint: eslint --max-warnings 0 on the touched files clean.
  • Format: prettier --check on the touched files clean.

To revert: git revert 7de10074d02924a2de03a1214386c7ccc448a326.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PxVsmvB9xfZKfVnUonY8kf

Delete tests that cannot fail when the product breaks:
- `promiseWithResolvers` tests exercised native `Promise.withResolvers`
  after the helper was removed in 3dec506
- `LogLevels` ordering test is implied by the exact-value test
- `warns normally when suppressWarnings is not set` duplicates
  `info level outputs all messages`
- `modules defaults to empty object` duplicates the css `defaults` test
- `returns result with packageJsonPath property` had a guarded assertion;
  fold it into `reads package.json from directory` as a real nested
  lookup check

Fold hand-unrolled input/output tests into `test.each` tables, keeping
every row and test name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PxVsmvB9xfZKfVnUonY8kf
@netlify

netlify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 7de1007
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/6acfc2c53e56264f7b216fd7
😎 Deploy Preview https://deploy-preview-1099--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Oct 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown@1099 -D
npm i https://pkg.pr.new/rolldown/tsdown@1099 -D
yarn add https://pkg.pr.new/rolldown/tsdown@1099.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown/create-tsdown@1099 -D
npm i https://pkg.pr.new/rolldown/tsdown/create-tsdown@1099 -D
yarn add https://pkg.pr.new/rolldown/tsdown/create-tsdown@1099.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1099 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1099 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@1099.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1099 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1099 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@1099.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1099 -D
npm i https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1099 -D
yarn add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@1099.tgz -D

commit: 7de1007

@Brooooooklyn Brooooooklyn self-assigned this Oct 14, 2026
@Brooooooklyn
Brooooooklyn marked this pull request as ready for review October 14, 2026 17:59
Copilot AI balanced review requested due to automatic review settings October 14, 2026 17:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T18:01:41.226035Z 7de1007 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The test-only changes preserve existing coverage, strengthen package lookup checks, and have no identified blocking issues.

0 open findings

What changed in this PR

Simplifies tsdown’s utility and CSS tests without changing production code.

Changes:

  • Removes six redundant or obsolete test cases.
  • Consolidates 47 cases into nine test.each tables, preserving names and assertions.
  • Strengthens package lookup coverage with a nested-directory check.
File Description
src/​utils/​package.test.ts Consolidates format/type cases and strengthens parent-package lookup coverage.
src/​utils/​logger.test.ts Removes duplicate checks and parameterizes format tests.
src/​utils/​json.test.ts Parameterizes indentation tests.
src/​utils/​general.test.ts Consolidates utility cases and removes native Promise tests.
src/​utils/​fs.test.ts Parameterizes ancestor and extension tests.
packages/​css/​src/​options.test.ts Removes a duplicate CSS modules default check.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@sxzz
sxzz merged commit b46c0d4 into main Oct 14, 2026
18 checks passed
@sxzz
sxzz deleted the claude/prune-tests-utils-test-duplicates branch October 14, 2026 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants