Path: @/test
- Unit tests for
parseArgs,formatError,mergePages, and method metadata coverage, plus integration tests that invoke the CLI as a subprocess, plus an end-to-end packaging test that installs the npm tarball - Uses Vitest as the test runner; integration tests in
cli.test.tsusetsxto run TypeScript source directly,build.test.tscompiles viatscand runs the builtdist/index.jsartifact, andpackaging.test.tsrunsnpm packand installs the tarball into a tmpdir
- Tests cover the pure utility modules in @/src: argument parsing, error formatting, pagination merging, and method metadata
- Integration tests in cli.test.ts exercise the full CLI binary by spawning
npx tsx src/index.tsas a child process, verifying end-to-end behavior including exit codes, stdout JSON structure, and stderr output - packaging.test.ts closes the loop on the npm distribution path documented in @/docs.md -- it is the guard against the
0.1.0regression wheredist/was missing from the published tarball - All tests run on every PR and on every push to
mainvia the workflows in @/.github/workflows - The test directory is excluded from TypeScript compilation via
tsconfig.json
parse-args.test.ts -- Tests the argument parser in isolation:
- Verifies
--key valuepairs,--key=valuesyntax, and standalone boolean flags - Confirms kebab-to-snake conversion (
--unfurl-linksbecomesunfurl_links) - Validates type coercion: booleans, numbers, JSON arrays/objects, and preservation of leading-zero strings
errors.test.ts -- Tests error formatting for each Slack error category:
- Platform errors (e.g.,
channel_not_found) produce suggestions referencing relevant API methods - Rate limit errors include retry timing
- Network errors surface the underlying error message
- Missing token errors suggest setting
SLACK_BOT_TOKEN
paginate.test.ts -- Unit tests for the mergePages function:
- Uses a
toAsyncIterablehelper to create async iterables from arrays of page objects - Verifies array concatenation across pages, preservation of metadata from the last page, handling of empty arrays and single pages
method-metadata.test.ts -- Coverage guard for method metadata:
- Asserts that
getMethodMetadatareturns a curated (non-fallback) description for every method inKNOWN_METHODS, ensuring new methods added to the catalog also get metadata entries
cli.test.ts -- Integration tests that run the CLI as a subprocess:
runClihelper spawns the CLI withexecFileand captures stdout/stderr/exit coderunCliWithStdinhelper usesspawnwith piped stdin for--json-inputtests- Tests use fake tokens (
xoxb-fake-token) which produce real Slackinvalid_autherrors, proving the full request path works without needing a valid token - Validates: no-args usage error, missing token error,
list-methodsoutput, structured JSON for API failures, stdin JSON input, source path in errors, suggestion text presence,--paginateflag acceptance,--dry-runbehavior,describecommand behavior, andlist-methodsfiltering/description options - Describe tests cover: known method metadata output (required/optional params, docs URL), fallback for unknown methods (
known: false), pagination support flags, deprecation notices, missing argument error, and spot-checks across newly-added namespaces (e.g.,dnd.setSnooze,usergroups.create,views.open,team.info) list-methodstests cover:--namespacefiltering (verifies all returned methods share the prefix and unrelated methods are excluded), empty namespace returning an empty array,--descriptionschanging the output shape to objects withmethodanddescriptionfields, and composition of both flags together- Suggestion tests cover: dry-run with misspelled methods verifying
suggestionsarray andwarningfield in JSON output, case-correction suggestions, and stderr "Did you mean" warnings before API calls
suggest.test.ts -- Unit tests for the findSimilarMethods function:
- Verifies exact matches return no suggestions, case-insensitive matches return the correctly-cased method, single-character typos find the right method, nonsense input returns empty, result count respects the
maxResultsparameter, and results are sorted by similarity (closest first)
build.test.ts -- Build verification tests that exercise the compiled output:
beforeAllrunstsconce; all tests share the resultingdist/index.js- Uses
node dist/index.jsdirectly (unlikecli.test.tswhich usesnpx tsx src/index.ts), verifying the actual build artifact that a global install would expose - Validates
--versionoutput,list-methodsJSON structure, and no-args usage error exit code
packaging.test.ts -- End-to-end packaging test that validates the npm distribution path:
beforeAllcreates two tmpdirs, runsnpm packon the project root to produce a.tgz, thennpm init -y+npm install --no-save <tarball>in the second tmpdir to simulate a downstream install- Asserts the installed
node_modules/.bin/nori-slackbinary exists and that running it withlist-methods --namespace chatreturns exit 0 with JSON containingchat.postMessage - Runs on every
npm testinvocation (not gated) so the tarball contents are continuously verified; thebeforeAllhas a 180s timeout becausenpm pack+npm installof the tarball is slow - This test is the enforcement mechanism for the packaging invariant documented in @/docs.md: if
prepare,files, orbinregress, this test fails before a broken version can be published
- Integration tests make real HTTP calls to Slack's API (with invalid tokens), so they require network access
- The
runClihelper sets a 10-second timeout to prevent hangs - Tests intentionally verify structure (JSON shape, field presence, field types) rather than exact string values, making them resilient to Slack API message changes
packaging.test.tsshells out tonpmand writes intoos.tmpdir(), so CI runners must have npm available and writable tmp space
Created and maintained by Nori.