11import assert from 'assert' ;
22import sinon from 'sinon' ;
3+ import { z } from 'zod' ;
34import { cli } from '../../cli/cli.js' ;
5+ import { CommandInfo } from '../../cli/CommandInfo.js' ;
46import { Logger } from '../../cli/Logger.js' ;
57import { telemetry } from '../../telemetry.js' ;
68import { app } from '../../utils/app.js' ;
@@ -16,11 +18,15 @@ describe(commands.DOCS, () => {
1618 let logger : Logger ;
1719 let loggerLogSpy : sinon . SinonSpy ;
1820 let getSettingWithDefaultValueStub : sinon . SinonStub ;
21+ let commandInfo : CommandInfo ;
22+ let commandOptionsSchema : z . ZodTypeAny ;
1923
2024 before ( ( ) => {
2125 sinon . stub ( telemetry , 'trackEvent' ) . resolves ( ) ;
2226 sinon . stub ( pid , 'getProcessName' ) . callsFake ( ( ) => '' ) ;
2327 sinon . stub ( session , 'getId' ) . callsFake ( ( ) => '' ) ;
28+ commandInfo = cli . getCommandInfo ( command ) ;
29+ commandOptionsSchema = commandInfo . command . getSchemaToParse ( ) ! ;
2430 } ) ;
2531
2632 beforeEach ( ( ) => {
@@ -59,8 +65,18 @@ describe(commands.DOCS, () => {
5965 assert . notStrictEqual ( command . description , null ) ;
6066 } ) ;
6167
68+ it ( 'passes validation with no options' , ( ) => {
69+ const actual = commandOptionsSchema . safeParse ( { } ) ;
70+ assert . strictEqual ( actual . success , true ) ;
71+ } ) ;
72+
73+ it ( 'fails validation with unknown options' , ( ) => {
74+ const actual = commandOptionsSchema . safeParse ( { option : "value" } ) ;
75+ assert . strictEqual ( actual . success , false ) ;
76+ } ) ;
77+
6278 it ( 'should log a message and return if autoOpenLinksInBrowser is false' , async ( ) => {
63- await command . action ( logger , { options : { } } ) ;
79+ await command . action ( logger , { options : commandOptionsSchema . parse ( { } ) } ) ;
6480 assert ( loggerLogSpy . calledWith ( app . packageJson ( ) . homepage ) ) ;
6581 } ) ;
6682
@@ -74,7 +90,7 @@ describe(commands.DOCS, () => {
7490 }
7591 throw 'Invalid url' ;
7692 } ) ;
77- await command . action ( logger , { options : { } } ) ;
93+ await command . action ( logger , { options : commandOptionsSchema . parse ( { } ) } ) ;
7894 assert ( openStub . calledWith ( app . packageJson ( ) . homepage ) ) ;
7995 } ) ;
8096} ) ;
0 commit comments