Skip to content

test: make negative tests fail when nothing throws - #2953

Merged
srod merged 2 commits into
developfrom
advisor/003-make-throw-tests-falsifiable
Nov 23, 2026
Merged

srod merged 2 commits into
developfrom
advisor/003-make-throw-tests-falsifiable

Conversation

@srod

@srod srod commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

14 "should throw" tests passed even when nothing threw. They used try { return await minify() } catch { expect(err)… }, so a resolved promise skipped the assertion. They now assert the rejection:

-try {
-    return await minify(settings);
-} catch (err) {
-    return expect(err).not.toBeNull();
-}
+await expect(minify(settings)).rejects.toThrow("cssnano minification failed");
Package Assertion
core (6), esbuild type check exact node-minify message
cssnano "cssnano minification failed"
lightningcss SyntaxError (the library's message text varies between versions)
esbuild js, google-closure-compiler, swc, terser, uglify-js .toThrow() with no argument (third-party messages)

Tests only. No changeset.

Evidence

  • Before: giving the "no input" core test an input left it green.
    After: the same edit fails it with promise resolved … instead of rejecting.
  • With tests/fixtures/css-errors renamed, the cssnano and lightningcss tests now fail (they got No content provided). Before, any error passed them.
  • bun run test: 71 files, 1080 tests pass. Lint, typecheck, ci-guard-type-suppressions.sh pass.

Merge Danger

Door: two-way

Blast Radius: tests

No runtime code changes.


Summary by cubic

Updates 14 "should throw" tests so they fail when minify() resolves instead of rejecting. The old try/catch pattern returned successfully on a resolved promise and skipped the assertion; tests now use expect(...).rejects.toThrow(...).

Assertions

  • Core, cssnano, esbuild, and google-closure-compiler assert their exact error message.
  • lightningcss asserts a SyntaxError since the library message varies between versions.
  • swc, terser, and uglify-js assert that any error is thrown, as third-party messages are not stable.

Tests only, no changeset.

Written for commit a5e3413. Summary will update on new commits.

View guided diff Turn on auto-fix

@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e090d09

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/core/__tests__/core.test.ts Resolved
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.63%. Comparing base (34a46a1) to head (a5e3413).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2953   +/-   ##
========================================
  Coverage    98.63%   98.63%           
========================================
  Files           70       70           
  Lines         2052     2052           
  Branches       625      625           
========================================
  Hits          2024     2024           
  Misses          28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@srod
srod merged commit 39689fe into develop Nov 23, 2026
6 checks passed
@srod
srod deleted the advisor/003-make-throw-tests-falsifiable branch November 23, 2026 16:55
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