@@ -18,6 +18,19 @@ This skill covers project-specific testing patterns for the B2C CLI project.
1818
1919## Running Tests
2020
21+ For coding agents (minimal output - only failures shown):
22+
23+ ``` bash
24+ # Run tests - only failures + summary
25+ pnpm run test:agent
26+
27+ # Run tests for specific package
28+ pnpm --filter @salesforce/b2c-tooling-sdk run test:agent
29+ pnpm --filter @salesforce/b2c-cli run test:agent
30+ ```
31+
32+ For debugging (full output with coverage):
33+
2134``` bash
2235# Run all tests with coverage
2336pnpm run test
@@ -307,6 +320,59 @@ const client = new WebDavClient(TEST_HOST, mockAuth);
307320const customAuth = new MockAuthStrategy (' custom-token' );
308321```
309322
323+ ## Silencing Test Output
324+
325+ Commands may produce console output (tables, formatted displays) even in tests. Use these helpers to keep test output clean.
326+
327+ ### Using runSilent for Output Capture
328+
329+ The ` runSilent ` helper uses oclif's ` captureOutput ` to suppress stdout/stderr:
330+
331+ ``` typescript
332+ import { runSilent } from ' ../../helpers/test-setup.js' ;
333+
334+ it (' returns data in non-JSON mode' , async () => {
335+ const command = new MyCommand ([], {} as any );
336+ // ... setup ...
337+
338+ // Silences any console output from the command
339+ const result = await runSilent (() => command .run ());
340+
341+ expect (result .data ).to .exist ;
342+ });
343+ ```
344+
345+ Use ` runSilent ` when:
346+ - Testing non-JSON output modes (tables, formatted displays)
347+ - The test doesn't need to verify console output content
348+ - You want clean test output with only pass/fail summary
349+
350+ ### When Output Verification is Needed
351+
352+ If you need to verify console output, stub ` ux.stdout ` directly:
353+
354+ ``` typescript
355+ import { ux } from ' @oclif/core' ;
356+
357+ it (' prints table in non-JSON mode' , async () => {
358+ const stdoutStub = sinon .stub (ux , ' stdout' );
359+
360+ await command .run ();
361+
362+ expect (stdoutStub .called ).to .be .true ;
363+ });
364+ ```
365+
366+ ### stubParse Sets Silent Logging
367+
368+ The ` stubParse ` helper automatically sets ` 'log-level': 'silent' ` to reduce pino logger output:
369+
370+ ``` typescript
371+ // stubParse includes silent log level by default
372+ stubParse (command , {server: ' test.demandware.net' });
373+ // Equivalent to: {server: 'test.demandware.net', 'log-level': 'silent'}
374+ ```
375+
310376## Command Test Guidelines
311377
312378Command tests should focus on ** command-specific logic** , not trivial flag verification.
@@ -445,15 +511,43 @@ pnpm run test
445511open coverage/index.html
446512```
447513
514+ ## Test Helpers Reference
515+
516+ ### CLI Package (` packages/b2c-cli/test/helpers/ ` )
517+
518+ | Helper | Purpose |
519+ | --------| ---------|
520+ | ` runSilent(fn) ` | Capture and suppress stdout/stderr from command execution |
521+ | ` stubParse(command, flags, args) ` | Stub oclif's parse method with flags (includes silent log level) |
522+ | ` createTestCommand(CommandClass, config, flags, args) ` | Create command instance with stubbed parse |
523+ | ` createIsolatedConfigHooks() ` | Mocha hooks for config isolation |
524+ | ` createIsolatedEnvHooks() ` | Mocha hooks for env var isolation |
525+
526+ ### SDK Package (` packages/b2c-tooling-sdk/test/helpers/ ` )
527+
528+ | Helper | Purpose |
529+ | --------| ---------|
530+ | ` MockAuthStrategy ` | Mock authentication for API clients |
531+ | ` stubParse(command, flags, args) ` | Stub oclif's parse method (includes silent log level) |
532+ | ` createNullStream() ` | Create a writable stream that discards output |
533+ | ` CapturingStream ` | Writable stream that captures output for assertions |
534+
535+ ### SDK Test Utils (exported from package)
536+
537+ ``` typescript
538+ import { isolateConfig , restoreConfig } from ' @salesforce/b2c-tooling-sdk/test-utils' ;
539+ ```
540+
448541## Writing Tests Checklist
449542
4505431 . Create test file in ` test/ ` mirroring source structure
4515442 . Use ` .test.ts ` suffix
4525453 . Import from package names, not relative paths
4535464 . Set up MSW server for HTTP tests (avoid fake timers)
4545475 . Use ` isolateConfig() ` /` restoreConfig() ` for config-dependent tests
455- 6 . Use ` pollInterval ` option for polling operations
456- 7 . Use MockAuthStrategy for authenticated clients
457- 8 . Test both success and error paths
458- 9 . Focus on command-specific logic, not trivial delegation
459- 10 . Run tests: ` pnpm --filter <package> run test `
548+ 6 . Use ` runSilent() ` for commands that produce console output
549+ 7 . Use ` pollInterval ` option for polling operations
550+ 8 . Use MockAuthStrategy for authenticated clients
551+ 9 . Test both success and error paths
552+ 10 . Focus on command-specific logic, not trivial delegation
553+ 11 . Run tests: ` pnpm --filter <package> run test `
0 commit comments