Install dependencies and verify you can execute the CLI:
Sanity check your local setup:
# Install dependencies
npm install
# Run the local code
./src/user-entrypoint.mjs
# Make sure you can build the distributions:
npm run build
If you change code and want to see how it behaves from a customer-perspective:
./src/user-entrypoint.mjs <command> <subcommand> [--option ...]
You can run the tests with:
npm run test
This project has 3 runnable entrypoints (a raw ESM one, a built CJS one, and an SEA one). You can read more about them here.
- Prefer to throw errors instead of exiting the process. Exit is harder to mock well in tests, and the global error-handler in
src/cli.mjs
should already do verbosity-aware error-handling. You can request a specific exit code by attaching anexitCode
property to your error before throwing it. The error-handling has a series of tests inyargs-test/general-cli.mjs
; if you find a case where throwing results in bad output to the user, replicate that case in a test suite. - Prefer to re-throw an existing error after modifying its message over catching and throwing a newly-constructed error. The
exitCode
andstack
properties on the existing error are worth keeping.
- Prefer to mock the "far" edges of the application - methods on
fs
, complex async libraries (e.g.,http#Server
),fetch
. This results in the test code traversing all of the CLI's business logic, but not interacting with error-prone external resources like disk, network, port availability, etc.sinon
records all calls to a mock, and allows asserting against them. Use this if, e.g., your business logic callsfetch
multiple times. Prefer to run local tests in watch mode with (e.g., withThis is currently broken.yarn local-test
) while developing.- Use debug logs to output the shape of objects (especially network responses) to determine how to structure mocks. For instance, to get a quick mock for a network request caused by
fauna schema status ...
, set the situation up and runfauna schema status ... --verbosity 5
. You can then use the logged objects as mocks.
- Fetch is not particularly amenable to debugging, but if you need to see the raw requests being made, open a netcat server locally (
nc -l 8080
) and then change the code to call the netcat server, either by passing the flag--url http://localhost:8080
or by editing the code. - This project has debug logging with a somewhat configurable logging strategy. To use it, provide either:
--verbose-component foo
, which logs all debug info for the componentfoo
. Because it's an array, you can specify it multiple times. To see the available components, look at the help or tab completion.--verbosity level
, wherelevel
is a number from 0 (no debug logging) to 5 (all debug logging) for all components.
- To investigate why a sinon stub is failing in a way you don't expect, you can log out
stub.args
, which is an array of the arguments provided each time the stub was called. This can be particularly helpful for assertions where the error message is hard to read or involves objects that don't stringify correctly (like FormData). - To trigger SEA builds on all supported OS/architecture combinations, make changes and push commits to the
build
branch in github. This will trigger github actions that build the SEA binaries.