@@ -73,23 +73,68 @@ describe("create command", () => {
7373 } ) ;
7474
7575 it ( "creates git-repo docset" , async ( ) => {
76- const cliPath = join ( process . cwd ( ) , "dist/index.js" ) ;
77- const cmd = `node ${ cliPath } create --preset git-repo --id react-docs --name "React Docs" --url https://github.com/facebook/react.git` ;
76+ const { createCommand } = await import ( "../commands/create.js" ) ;
7877
79- execSync ( cmd , { cwd : testDir } ) ;
78+ const originalCwd = process . cwd ;
79+ const originalLog = console . log ;
80+ process . cwd = ( ) => testDir ;
81+ console . log = ( ) => { } ;
82+
83+ try {
84+ await createCommand . parseAsync ( [
85+ "node" ,
86+ "create" ,
87+ "--preset" ,
88+ "git-repo" ,
89+ "--id" ,
90+ "react-docs" ,
91+ "--name" ,
92+ "React Docs" ,
93+ "--url" ,
94+ "https://github.com/facebook/react.git" ,
95+ ] ) ;
8096
81- const config = await fs . readFile ( configPath , "utf-8" ) ;
82- expect ( config ) . toContain ( "id: react-docs" ) ;
83- expect ( config ) . toContain ( "name: React Docs" ) ;
84- expect ( config ) . toContain ( "url: https://github.com/facebook/react.git" ) ;
85- expect ( config ) . toContain ( "type: git_repo" ) ;
97+ const config = await fs . readFile ( configPath , "utf-8" ) ;
98+ expect ( config ) . toContain ( "id: react-docs" ) ;
99+ expect ( config ) . toContain ( "name: React Docs" ) ;
100+ expect ( config ) . toContain ( "url: https://github.com/facebook/react.git" ) ;
101+ expect ( config ) . toContain ( "type: git_repo" ) ;
102+ } finally {
103+ process . cwd = originalCwd ;
104+ console . log = originalLog ;
105+ }
86106 } ) ;
87107
88108 it ( "fails with invalid path" , async ( ) => {
89- const cliPath = join ( process . cwd ( ) , "dist/index.js" ) ;
90- const cmd = `node ${ cliPath } create --preset local-folder --id test --name "Test" --path ./nonexistent` ;
109+ const { createCommand } = await import ( "../commands/create.js" ) ;
91110
92- expect ( ( ) => execSync ( cmd , { cwd : testDir , stdio : "pipe" } ) ) . toThrow ( ) ;
111+ const originalCwd = process . cwd ;
112+ const originalLog = console . log ;
113+ const originalError = console . error ;
114+ process . cwd = ( ) => testDir ;
115+ console . log = ( ) => { } ;
116+ console . error = ( ) => { } ;
117+
118+ try {
119+ await expect (
120+ createCommand . parseAsync ( [
121+ "node" ,
122+ "create" ,
123+ "--preset" ,
124+ "local-folder" ,
125+ "--id" ,
126+ "test" ,
127+ "--name" ,
128+ "Test" ,
129+ "--path" ,
130+ "./nonexistent" ,
131+ ] ) ,
132+ ) . rejects . toThrow ( ) ;
133+ } finally {
134+ process . cwd = originalCwd ;
135+ console . log = originalLog ;
136+ console . error = originalError ;
137+ }
93138 } ) ;
94139
95140 it ( "creates config file when missing and creates symlinks for local folder" , async ( ) => {
@@ -146,13 +191,46 @@ describe("create command", () => {
146191 } ) ;
147192
148193 it ( "fails with duplicate ID" , async ( ) => {
149- const cliPath = join ( process . cwd ( ) , "dist/index.js" ) ;
150- // Create first docset
151- const cmd1 = `node ${ cliPath } create --preset local-folder --id test-docs --name "Test Docs" --path ./docs` ;
152- execSync ( cmd1 , { cwd : testDir } ) ;
153-
154- // Try to create duplicate
155- const cmd2 = `node ${ cliPath } create --preset local-folder --id test-docs --name "Test Docs 2" --path ./docs` ;
156- expect ( ( ) => execSync ( cmd2 , { cwd : testDir , stdio : "pipe" } ) ) . toThrow ( ) ;
194+ const { createCommand } = await import ( "../commands/create.js" ) ;
195+
196+ const originalCwd = process . cwd ;
197+ const originalLog = console . log ;
198+ process . cwd = ( ) => testDir ;
199+ console . log = ( ) => { } ;
200+
201+ try {
202+ // Create first docset
203+ await createCommand . parseAsync ( [
204+ "node" ,
205+ "create" ,
206+ "--preset" ,
207+ "local-folder" ,
208+ "--id" ,
209+ "test-docs" ,
210+ "--name" ,
211+ "Test Docs" ,
212+ "--path" ,
213+ "./docs" ,
214+ ] ) ;
215+
216+ // Try to create duplicate - should throw
217+ await expect (
218+ createCommand . parseAsync ( [
219+ "node" ,
220+ "create" ,
221+ "--preset" ,
222+ "local-folder" ,
223+ "--id" ,
224+ "test-docs" ,
225+ "--name" ,
226+ "Test Docs 2" ,
227+ "--path" ,
228+ "./docs" ,
229+ ] ) ,
230+ ) . rejects . toThrow ( ) ;
231+ } finally {
232+ process . cwd = originalCwd ;
233+ console . log = originalLog ;
234+ }
157235 } ) ;
158236} ) ;
0 commit comments