test: add build smoke tests for ESM, CJS, and TypeScript exports#37
Merged
Lakes41 merged 1 commit intoJun 16, 2026
Merged
Conversation
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.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 actualdist/output the way a real consumer would, plus wires them into CI right after the build step.tests/smoke/esm.smoke.mjs—importsdist/index.mjs(native ESM) and exercisesGuildPassClient,GuildPassError,GuildPassErrorCode, and several utility/config exports, asserting both shape and runtime behaviour (client wiring, error codes).tests/smoke/cjs.smoke.cjs—require()sdist/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 builtdist/index.d.ts(notsrc) and verifies they resolve and type-check correctly.skipLibCheckis explicitly disabled for this check only, since the whole point is to validate the declaration file itself — leaving it on (as the basetsconfig.jsondoes) would silently skip the exact errors we're trying to catch.test:smokescript 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.ymlrunspnpm test:smokeas a new step immediately afterpnpm build.tsconfig.jsonnow excludestests/smokefrom the main project compile, since those files referencedist/*, which doesn't exist yet whenpnpm typecheckruns (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#exportslisted conditions in the orderrequire,import,types.tsup/esbuild explicitly warns that this ordering means thetypescondition can never be reached, sincerequire/importmatch first for their respective resolution contexts. The conventional and correct order istypesfirst, so resolvers checking the condition map find it before falling through to a module condition. Fixed by reordering totypes,require,import. After the fix,pnpm buildno longer emits the exports-order warning.Verification
I manually verified the smoke tests actually catch breakage (not just "always green"):
dist/index.mjs→node tests/smoke/esm.smoke.mjsfails with a clearSyntaxError: ... does not provide an export named ...and a non-zero exit code.dist/index.d.ts→tsc -p tsconfig.smoke.jsonfails withTS2304: 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 installpnpm typecheck— passes (smoke files excluded pre-build, as expected)pnpm test:run— 20/20 unit tests passpnpm build— no exports-order warningpnpm test:smoke— ESM import, CJS require, and type-check all pass againstdist/Closes #23