|
8 | 8 | - Use only jest for writing test cases and refer existing unit test under the /src folder. |
9 | 9 | - Do not create code comments for any changes. |
10 | 10 |
|
| 11 | +## Integration tests |
| 12 | + |
| 13 | +- Unit tests mock the CLI's own classes, so they keep passing when behaviour changes. |
| 14 | + Integration tests (`test/integration/`) exist to catch what unit tests cannot: they run a |
| 15 | + real oclif command end to end and assert on what the CLI *does*. |
| 16 | +- Run them with `npm run test:integration` (they are also part of `npm test`). |
| 17 | +- Only three things are replaced: the terminal prompt (`inquirer`), the `open` package, and |
| 18 | + the Contentstack management SDK, which resolves its base URL as `https://<host>:443` and so |
| 19 | + cannot be pointed at a local server. Apollo, the GraphQL documents, the CLI config store, |
| 20 | + flag parsing, the filesystem and `git` all run for real. |
| 21 | +- The Launch API is a local HTTP server (`test/integration/harness/launch-api.ts`) that the CLI |
| 22 | + reaches through a temporary region config. It records every GraphQL operation, so tests assert |
| 23 | + on the operations and variables the CLI actually sent rather than on internal method calls. |
| 24 | +- Assert on the observable contract - operation sequence, request variables, prompt sequence, |
| 25 | + `.cs-launch.json` contents, stdout, exit code. Never stub a method on a command or adapter; |
| 26 | + that is what makes these tests survive a refactor and fail on a behaviour change. |
| 27 | +- Register a response for every operation a flow needs and finish with |
| 28 | + `session.api.assertNoUnhandledOperations()` and `prompts.assertScriptFullyConsumed()`, so a |
| 29 | + renamed operation or an added prompt fails loudly instead of passing quietly. |
| 30 | +- V2 (epic CL-4867) removes the bare `csdx launch` command in favour of `projects:create`, |
| 31 | + `environments:create` and `deployments:create`. `launch-github.test.ts` and |
| 32 | + `launch-file-upload.test.ts` therefore describe behaviour that has to be *ported* to those |
| 33 | + commands, not a command that survives — read a failure there as "the new command does something |
| 34 | + different", and repoint the spec rather than deleting the assertion. |
| 35 | +- Tests named after a `CL-` ticket pin a bug that was already fixed once. Do not relax them. |
0 commit comments