Skip to content

test: add build smoke tests for ESM, CJS, and TypeScript exports#37

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
OlaGreat:test/build-export-smoke-tests
Jun 16, 2026
Merged

test: add build smoke tests for ESM, CJS, and TypeScript exports#37
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
OlaGreat:test/build-export-smoke-tests

Conversation

@OlaGreat

Copy link
Copy Markdown
Contributor

Summary

Source tests import directly from src/, so they can pass even when the built package's exports are broken. This PR adds smoke tests that exercise the actual dist/ output the way a real consumer would, plus wires them into CI right after the build step.

  • tests/smoke/esm.smoke.mjsimports dist/index.mjs (native ESM) and exercises GuildPassClient, GuildPassError, GuildPassErrorCode, and several utility/config exports, asserting both shape and runtime behaviour (client wiring, error codes).
  • tests/smoke/cjs.smoke.cjsrequire()s dist/index.js (CommonJS) and runs the same checks.
  • tests/smoke/types.smoke.ts + tsconfig.smoke.json — a compile-only (noEmit) TypeScript check that imports types from the built dist/index.d.ts (not src) and verifies they resolve and type-check correctly. skipLibCheck is explicitly disabled for this check only, since the whole point is to validate the declaration file itself — leaving it on (as the base tsconfig.json does) would silently skip the exact errors we're trying to catch.
  • A new test:smoke script runs all three checks in sequence: node tests/smoke/esm.smoke.mjs && node tests/smoke/cjs.smoke.cjs && tsc -p tsconfig.smoke.json.
  • .github/workflows/ci.yml runs pnpm test:smoke as a new step immediately after pnpm build.
  • tsconfig.json now excludes tests/smoke from the main project compile, since those files reference dist/*, which doesn't exist yet when pnpm typecheck runs (before the build step) in CI.

Bug found and fixed while building this

Writing the smoke tests surfaced a real, pre-existing issue: package.json#exports listed conditions in the order require, import, types. tsup/esbuild explicitly warns that this ordering means the types condition can never be reached, since require/import match first for their respective resolution contexts. The conventional and correct order is types first, so resolvers checking the condition map find it before falling through to a module condition. Fixed by reordering to types, require, import. After the fix, pnpm build no longer emits the exports-order warning.

Verification

I manually verified the smoke tests actually catch breakage (not just "always green"):

  • Stripped an export out of the built dist/index.mjsnode tests/smoke/esm.smoke.mjs fails with a clear SyntaxError: ... does not provide an export named ... and a non-zero exit code.
  • Renamed a class inside dist/index.d.tstsc -p tsconfig.smoke.json fails with TS2304: Cannot find name 'GuildPassClient' and a non-zero exit code.

Also ran the full existing pipeline locally to confirm no regressions: pnpm lint, pnpm typecheck, pnpm test:run (20/20 passing), pnpm build, pnpm test:smoke — all green.

Test plan

  • pnpm install
  • pnpm typecheck — passes (smoke files excluded pre-build, as expected)
  • pnpm test:run — 20/20 unit tests pass
  • pnpm build — no exports-order warning
  • pnpm test:smoke — ESM import, CJS require, and type-check all pass against dist/
  • Confirmed each smoke check fails loudly when the corresponding export/type is broken (see Verification above)
  • CI run on this PR (will run automatically)

Closes #23

Source-level tests passed while the published exports map listed
"types" after "require"/"import", which esbuild/tsup flags as
unreachable - TypeScript could silently resolve the wrong condition
for a downstream consumer. Fix the condition order and add a
test:smoke script that imports the built dist/index.mjs via ESM,
requires dist/index.js via CommonJS, and type-checks against
dist/index.d.ts, so CI catches export breakage after pnpm build
instead of only checking src.
@Lakes41 Lakes41 merged commit bbebdc0 into Adamantine-guild:main Jun 16, 2026
1 check passed
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.

Add distribution-level smoke tests for package exports

2 participants