Skip to main content

write-tests

Write tests for datadog-ci commands and helpers using established repository patterns.

Informations de source

Dépôt
datadog/datadog-ci
Dernière activité de la source
4 août 2026 à 08:06
Langue détectée de SKILL.md
anglais
Étoiles
163
Forks
73

Options d'installation

Le prompt qui vérifie d'abord la source est sélectionné par défaut. Vous pouvez passer à une commande directe ou télécharger une copie locale.

Vérifiez les fichiers source

Lisez SKILL.md et les fichiers associés affichés par SkillsMP avant de décider de l'installer.

Affichage de SKILL.md

SKILL.md
Instructions source · Aperçu en lecture seule
name
write-tests
description
Write tests for datadog-ci commands and helpers using established repository patterns.
# Write Tests Write tests for datadog-ci commands and helpers following the repo's established patterns. Before writing tests, read existing tests in the same package to match local patterns. ## Conventions - Place tests in `__tests__/*.test.ts` next to the source, fixtures in `__tests__/fixtures/` ## Key test utilities From `packages/base/src/helpers/__tests__/testing-tools.ts`: - **`createMockContext(opts?)`** -- creates a mock context with `stdout` and `stderr` writable streams. Use `context.stdout.toString()` / `context.stderr.toString()` to check output. - **`makeRunCLI(commandClass, baseArgs, opts?)`** -- returns an async function `(extraArgs, extraEnv?) => {context, code}` that registers and runs a command through the full CLI pipeline. - **`createCommand(commandClass, context?)`** -- instantiates a command with mock context and resolved option defaults. Good for unit-testing command methods directly. - **`MOCK_DATADOG_API_KEY`**, **`MOCK_BASE_URL`** -- standard mock values. - **`getRequestError(status, {errors?, message?})`** -- creates a mock `RequestError`. ## Patterns - Use `jest.spyOn()` for mocking, restore in `afterEach` or use `jest.restoreAllMocks()` - Use `jest.mock()` for module-level mocks when needed - Table-driven tests with `describe.each` / `test.each` where appropriate - Check both stdout output and exit code - For commands that make HTTP requests, mock the request layer (e.g., `fetch`) ## Running tests ```sh yarn test # all tests yarn test <path> # specific package or file yarn test --testPathPattern # regex match ```
Voir sur GitHub