| name | testing |
|---|---|
| description | Runs TDD and unit tests for this repo using Mocha, Chai, sinon, nock, and @oclif/test. Use when writing or fixing tests, mocking HTTP or cliux, or when the user asks about test structure, coverage, or forbid-only behavior. |
- Runner: Mocha (
npm test,npm run test:unit:report) - Assertions: Chai
expect - Modules: sinon sandboxes for stubs/spies
- HTTP: nock — match hosts from
configHandler.get("region")and Developer Hub URLs (seegetDeveloperHubUrlin source) - CLI:
runCommand([...])from@oclif/test
- Add or adjust a single failing test that describes desired behavior.
- Implement the smallest change to pass.
- Refactor; keep tests green. Do not commit
.onlyorskip(CI uses--forbid-only).
- Create a sandbox per test file or per test:
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
});
afterEach(() => {
sandbox.restore();
});- Stub UI and side effects:
cliux.inquire,cliux.confirm,cliux.loader,fs.*,shelljs, etc., following neighboring tests in the same command. - Reuse
test/unit/helpers/auth-stub-helper.ts: callstubAuthentication(sandbox)instead of copyingconfigHandler.getstubs.
- Register expected HTTP calls on
region.cma, Developer Hub base URL, or other hosts used by the command under test. - In
afterEach, callnock.cleanAll()(and restore sinon) to avoid bleed between tests.
- Every behavior change should have at least one happy path and one error or guard-rail assertion (stderr, exit code, or message substring) where applicable.
- Hit real Contentstack or Developer Hub APIs from unit tests
- Rely on real auth tokens or
.envsecrets in tests