-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli): docs, doctor, context commands do not use configuratio…
…n directly anymore (#32578) This is a refactor that follows #32558. The effort is to ensure that the `configuration` object is not directly used by commands and instead, the relevant information is passed directly to the function. - doctor: no options needed - docs: 1 option needed - context: in addition to a few options, the context command also saves *some* values to `cdk.context.json`. this requires some modifications to the `Context` object to support this. We move away from using the archaic API in `command-api.ts`. This seems to be an old effort to standardize CLI commands that was only used for doctor/docs/context. We have since evolved to use command-specific property bags. Since this is a refactor PR. I aim to change no functionality of the CLI. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
17 changed files
with
264 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
import * as child_process from 'child_process'; | ||
import { mocked } from 'jest-mock'; | ||
import { CommandHandler } from '../lib/command-api'; | ||
import { realHandler } from '../lib/commands/docs'; | ||
const argv = { | ||
browser: 'echo %u', | ||
commandHandler: undefined as (CommandHandler | undefined), | ||
}; | ||
import { docs } from '../lib/commands/docs'; | ||
|
||
// eslint-disable-next-line no-console | ||
console.log = jest.fn(); | ||
jest.mock('child_process'); | ||
|
||
describe('`cdk docs`', () => { | ||
|
||
test('exits with 0 when everything is OK', async () => { | ||
const mockChildProcessExec: any = (_: string, cb: (err?: Error, stdout?: string, stderr?: string) => void) => cb(); | ||
mocked(child_process.exec).mockImplementation(mockChildProcessExec); | ||
|
||
const result = await realHandler({ args: argv } as any); | ||
const result = await docs({ browser: 'echo %u' }); | ||
expect(result).toBe(0); | ||
}); | ||
|
||
test('exits with 0 when opening the browser fails', async () => { | ||
const mockChildProcessExec: any = (_: string, cb: (err: Error, stdout?: string, stderr?: string) => void) => cb(new Error('TEST')); | ||
mocked(child_process.exec).mockImplementation(mockChildProcessExec); | ||
|
||
const result = await realHandler({ args: argv } as any); | ||
const result = await docs({ browser: 'echo %u' }); | ||
expect(result).toBe(0); | ||
}); | ||
}); |
Oops, something went wrong.