Skip to content

test: add runnable smoke tests for examples#46

Merged
samlaycock merged 2 commits into
mainfrom
issue-34-example-smoke-tests
May 13, 2026
Merged

test: add runnable smoke tests for examples#46
samlaycock merged 2 commits into
mainfrom
issue-34-example-smoke-tests

Conversation

@samlaycock

@samlaycock samlaycock commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #34.

Adds runnable smoke coverage for the examples directory so example drift is caught by the test suite and by the dedicated Bun script.

Changes

  • Added test/examples-smoke.test.ts, which discovers every examples/*.ts file and registers one Bun smoke test per example for independent failure reporting.
  • Added bun run examples:smoke for running the example smoke coverage directly.
  • Made examples/batch-job.ts deterministic by injecting a UserApi dependency instead of performing real network calls during example execution.
  • Documented the preferred future-example rule in conventions/TESTING.md: examples must stay deterministic, fast, and free of real network calls.
  • Added a patch changeset for the testing/docs coverage improvement.

Verification

  • bun run examples:smoke
  • bun fmt
  • bun lint:fix
  • bun test
  • bun typecheck
  • bun lint

Add a Bun smoke test that discovers and executes every TypeScript example so examples fail CI when they drift from the public API.

Make the batch-job example deterministic by injecting a test UserApi instead of performing a real network request during example execution.

Document the examples smoke workflow and include a patch changeset.
@samlaycock samlaycock marked this pull request as ready for review May 13, 2026 07:24
@greptile-apps

greptile-apps Bot commented May 13, 2026

Copy link
Copy Markdown

Greptile Summary

Adds runnable smoke coverage for the examples/ directory: a new test file discovers all .ts examples and executes each as a separate Bun subprocess, batch-job.ts is made deterministic via a stubbed UserApi dependency, and the testing convention is documented.

  • test/examples-smoke.test.ts registers one test per example file (using readdirSync at module scope), ensuring every example is exercised and failures are reported independently.
  • examples/batch-job.ts replaces the live fetch call with an injected UserApi dependency and a stubUserApi implementation, making the example safe to run in CI without network access.
  • package.json gains an examples:smoke script and conventions/TESTING.md documents the determinism requirement for future examples.

Confidence Score: 5/5

Safe to merge — changes are additive test infrastructure with no impact on library behaviour.

The diff adds a smoke test harness, a deterministic stub for one example, a new npm script, and a documentation line. No production code is modified, and the approach (per-file subprocesses, module-scope file discovery) is sound.

test/examples-smoke.test.ts has two minor style points worth a quick look before merging.

Important Files Changed

Filename Overview
test/examples-smoke.test.ts New smoke test file that discovers and runs each example as a subprocess; bare expect() outside a test block and .quiet() suppressing stderr are minor concerns
examples/batch-job.ts Refactored to inject a stubbed UserApi dependency instead of making real network calls; deterministic and self-contained
package.json Adds examples:smoke script pointing to the new test file
conventions/TESTING.md Documents the new convention: examples must be deterministic, fast, and free of real network calls
.changeset/runnable-examples-smoke.md Patch changeset entry for the smoke coverage addition

Reviews (2): Last reviewed commit: "test: address example smoke review feedb..." | Re-trigger Greptile

Comment thread test/examples-smoke.test.ts Outdated
Comment thread examples/batch-job.ts Outdated
Comment thread examples/batch-job.ts Outdated
Register one smoke test per TypeScript example so multiple failures are reported independently.

Rename the batch-job example dependency provider from testUserApi to stubUserApi to better communicate that it is example stub wiring.
@samlaycock samlaycock merged commit bdaaf2d into main May 13, 2026
2 checks passed
@samlaycock samlaycock deleted the issue-34-example-smoke-tests branch May 13, 2026 14:42
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.

P3: Add runnable smoke tests for examples

1 participant