@@ -10,16 +10,38 @@ import { moshVocabulary } from "../src/commands.mjs";
1010import { runScript } from "../src/runtime.mjs" ;
1111import { createRegistry } from "../src/registry.mjs" ;
1212
13+ const BIN = fileURLToPath ( new URL ( "../bin/moshcode.mjs" , import . meta. url ) ) ;
14+
1315test ( "moshcode --version prints the package version" , ( ) => {
1416 const expected = JSON . parse ( readFileSync ( new URL ( "../package.json" , import . meta. url ) , "utf8" ) ) . version ;
15- const result = spawnSync ( process . execPath , [ fileURLToPath ( new URL ( "../bin/moshcode.mjs" , import . meta . url ) ) , "--version" ] , {
17+ const result = spawnSync ( process . execPath , [ BIN , "--version" ] , {
1618 encoding : "utf8" ,
1719 } ) ;
1820 assert . equal ( result . status , 0 ) ;
1921 assert . equal ( result . stdout . trim ( ) , expected ) ;
2022 assert . equal ( result . stderr , "" ) ;
2123} ) ;
2224
25+ for ( const command of [ "engines" , "tools" ] ) {
26+ test ( `moshcode ${ command } --json prints machine-readable install status` , ( ) => {
27+ const result = spawnSync ( process . execPath , [ BIN , command , "--json" ] , {
28+ encoding : "utf8" ,
29+ } ) ;
30+
31+ assert . equal ( result . status , 0 ) ;
32+ assert . equal ( result . stderr , "" ) ;
33+ const entries = JSON . parse ( result . stdout ) ;
34+ assert . ok ( entries . length > 0 ) ;
35+ for ( const entry of entries ) {
36+ assert . deepEqual ( Object . keys ( entry ) , [ "name" , "description" , "binary" , "installed" ] ) ;
37+ assert . equal ( typeof entry . name , "string" ) ;
38+ assert . equal ( typeof entry . description , "string" ) ;
39+ assert . equal ( typeof entry . binary , "string" ) ;
40+ assert . equal ( typeof entry . installed , "boolean" ) ;
41+ }
42+ } ) ;
43+ }
44+
2345function dryCtx ( ) {
2446 return { dryRun : true , lines : [ ] , out ( l ) { this . lines . push ( l ) ; } } ;
2547}
0 commit comments