mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-12-01 03:02:13 +08:00
Strips ANSI escape codes from captured `stdout` and `stderr` before comparing test output to snapshots. When `FORCE_COLOR` is set (some terminals and tools set it), Node colorizes logged errors, so `main-token-get-owner-set-client-error.test.js` fails locally even though it passes in CI. With this change, snapshots match regardless of color settings. CI output is unchanged. Split out from #411. Co-authored-by: Aiqiao Yan <55104035+aiqiaoy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Tests
Add one test file per scenario. You can run them in isolation with:
node tests/post-token-set.test.js
All tests are run together in tests/index.js, which can be executed with Node's built-in test runner
node --test tests/index.js
or with npm
npm test
How the tests work
The output from the tests is captured into a snapshot (tests/index.js.snapshot). It includes all requests sent by our scripts to verify it's working correctly and to prevent regressions.
To update snapshots after an intentional change:
node --test --test-update-snapshots tests/index.js
How to add a new test
We have tests both for the main.js and post.js scripts.
- If you do not expect an error, take main-token-permissions-set.test.js as a starting point.
- If your test has an expected error, take main-missing-client-and-app-id.test.js as a starting point.