Anti-AIClone

Log date · Sat

How do you test Bun bundle output for correctness?

Run the same inputs against source and release output, then assert expected values. We compare ordinary and minified Bun bundles.

How do we know a Bun bundle still works?

Run the same inputs against the source and the final release artifact and compare actual results. A successful build or exit is not enough. With Bun 1.3.11, we built our sample both normally and with minification; all three inputs produced the same results as the source: 13, 23 and 8. The ordinary bundle was 331 bytes and the minified bundle 133 bytes.

The check is prompted by a Bun 1.4.1 renaming regression: some output could run while computing the wrong value. The 1.4.2 notes say it was fixed. [1] Our installed version is 1.3.11, so this demonstrates a testing method, not a test of the regression or its fix.

Results from our sample
QuestionResult
Did both builds match?All three outputs matched the source byte for byte.
What size was minified?133 bytes versus 331 for the ordinary bundle.
Does that establish correctness for all programs?No; it covers three inputs and one sample.

Why the 1.4.1 regression mattered

On September 5, 2026, Bun published its 1.4.2 notes; the GitHub release is timestamped 2026-09-05T05:55Z. [1][2] According to the notes, bun build in 1.4.1 could rename a nested var to the name of a let in the same block. Builds importing Elysia could then fail with a SyntaxError. The same bug could give a let the name of a parameter or catch binding: the output could execute but calculate a wrong value.

A syntax error is usually visible on load; a wrong value can be returned as an apparently normal response. The notes also describe an AsyncLocalStorage memory leak, worker_threads online event ordering, a JavaScriptCore update with about 350 upstream WebKit commits, and a Linux FileSink double-close after registration failure. [1] Those are other changes in the release, not results from our experiment.

Bundling and minification transform code; later stages such as obfuscation also deserve their own checks. This event establishes the Bun issue described in the release notes, not that another named tool has the same bug.

The sample: parameter, block and catch

We wrote a quote function: start with a parameter, add 7 from a block, then add twice a caught value. For inputs 0, 10 and -5 the expected results are 13, 23 and 8. A block-scoped let, a function-scoped var and a catch binding put several scopes into the same small program.

The complete sample we wrote.
function quote(base) {
  let total = base;
  {
    let adjustment = 7;
    var saved = adjustment;
    total += saved;
  }
  try { throw 3; } catch (error) {
    let adjustment = error * 2;
    total += adjustment;
  }
  return total;
}
for (const base of [0, 10, -5]) console.log(`${base}: ${quote(base)}`);

We built once normally and once with --minify, specifying the node target and cjs format, then ran each with Node 20.19.5. Bun documents entrypoints, targets and output formats for bun build. [3] These variants help distinguish ordinary bundling from minification; they are not a comparison of two Bun releases.

Reproduce the builds and byte comparisons; cmp is silent on a match.
bun build sample.cjs --target=node --format=cjs --outfile=plain.cjs
bun build sample.cjs --target=node --format=cjs --minify --outfile=mini.cjs
node sample.cjs > sample.out
node plain.cjs > plain.out
node mini.cjs > mini.out
cmp sample.out plain.out
cmp sample.out mini.out

What the results show

All three runs printed the same three lines. We ran cmp against each bundle and printed confirmation only after both succeeded. The minified version shortens the function and local names and changes some structure, yet retains the calculation for these inputs. The 331 and 133 byte sizes apply only to this sample; they are not a project-wide compression estimate.

Minified output and comparison result from our run.
== mini ==
0: 13
10: 23
-5: 8
Both bundles match source output.

Comparing artifacts alone has a blind spot: source and bundle can agree on the same business mistake. Give critical cases independent expected values and cover boundaries, error paths and realistic data shapes. The three arithmetic results here can be checked by hand, but they do not replace application-specific assertions.

Exact text comparison suits this deterministic command-line sample. For timestamps, randomness or unordered fields, compare normalized semantic results while retaining error codes and exception types. Do not filter away differences that matter.

Recommendations by case

These are engineering recommendations, not measured benefits from the sample. Treat each toolchain upgrade as a separate change and retain the last verified version and build configuration.

Choose by case
CaseRecommendation
Build or load fails with syntax errorKeep build logs, reduce to a reproducible sample and compare tool versions.
Program runs but results differFix inputs and compare source, plain bundle and each transformation stage.
Transformed output matchesContinue critical business, error and platform tests; three cases do not cover every path.
A problem appears after upgradeIsolate the upgrade, roll back to a verified version and provide maintainers a minimal sample.

Retain each intermediate artifact, command, version and test report to locate the first stage that differs. For side effects, use an isolated environment with resettable data. When comparing database state or requests, assert expected contents as well as checking that the process stays alive.

Run this on your own app

The following is a template for a deterministic command-line entry. Use your project’s real release build and test entrypoint, keep runtime, input, environment and dependencies consistent, and substitute your own paths.

Command template: replace the entry and release options and create the output directory first.
bun --version
bun build ./src/entry.js --target=node --format=cjs --minify --outfile=./dist/entry.cjs
node ./src/entry.js > source-result.txt
node ./dist/entry.cjs > release-result.txt
cmp source-result.txt release-result.txt

Add independent expected-value assertions to automated tests and make a failing exit status stop release. If the pipeline also produces an obfuscated bundle or executable, rerun the same cases on the final artifact that will actually ship. When a difference appears, start diagnosis at the last stage that passed.

Your checklist

  • Pin exact Bun and downstream transformation versions.
  • Run the same critical inputs against source and every build stage.
  • Assert independent expected values for normal, boundary and error cases.
  • Test the final artifact and retain the results.
  • Make upgrades separate changes and keep a verified rollback version.

Primary sources

All sources and reproduction status ↗