test: make negative tests fail when nothing throws

Merged
SR
10h ago
+31-95

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");
PackageAssertion
core (6), esbuild type checkexact node-minify message
cssnano"cssnano minification failed"
lightningcssSyntaxError (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.