@@ -99,6 +99,9 @@ describe('#readPackage()', () => {
9999 name : 'concurrently' ,
100100 version : '6.4.0' ,
101101 } ;
102+ vi . spyOn ( fs , 'existsSync' ) . mockImplementation ( ( path : PathOrFileDescriptor ) => {
103+ return path === 'package.json' ;
104+ } ) ;
102105 vi . spyOn ( fs , 'readFileSync' ) . mockImplementation ( ( path : PathOrFileDescriptor ) => {
103106 if ( path === 'package.json' ) {
104107 return JSON . stringify ( expectedPackage ) ;
@@ -118,6 +121,47 @@ describe('#readPackage()', () => {
118121 expect ( ( ) => ExpandWildcard . readPackage ( ) ) . not . toThrow ( ) ;
119122 expect ( ExpandWildcard . readPackage ( ) ) . toEqual ( { } ) ;
120123 } ) ;
124+
125+ it ( 'can read package.json5' , ( ) => {
126+ const expectedPackage = {
127+ name : 'concurrently' ,
128+ version : '6.4.0' ,
129+ scripts : {
130+ 'test:unit' : '' ,
131+ } ,
132+ } ;
133+ vi . spyOn ( fs , 'existsSync' ) . mockImplementation ( ( path : PathOrFileDescriptor ) => {
134+ return path === 'package.json5' ;
135+ } ) ;
136+ vi . spyOn ( fs , 'readFileSync' ) . mockImplementation ( ( path : PathOrFileDescriptor ) => {
137+ if ( path === 'package.json5' ) {
138+ return `/* comment */\n${ JSON . stringify ( expectedPackage ) } ` ;
139+ }
140+ return '' ;
141+ } ) ;
142+
143+ const actualReadPackage = ExpandWildcard . readPackage ( ) ;
144+ expect ( actualReadPackage ) . toEqual ( expectedPackage ) ;
145+ } ) ;
146+
147+ it ( 'prefers package.json over package.json5' , ( ) => {
148+ const expectedPackage = {
149+ name : 'from-json' ,
150+ version : '1.0.0' ,
151+ } ;
152+ vi . spyOn ( fs , 'existsSync' ) . mockImplementation ( ( path : PathOrFileDescriptor ) => {
153+ return path === 'package.json' || path === 'package.json5' ;
154+ } ) ;
155+ vi . spyOn ( fs , 'readFileSync' ) . mockImplementation ( ( path : PathOrFileDescriptor ) => {
156+ if ( path === 'package.json' ) {
157+ return JSON . stringify ( expectedPackage ) ;
158+ }
159+ return '' ;
160+ } ) ;
161+
162+ const actualReadPackage = ExpandWildcard . readPackage ( ) ;
163+ expect ( actualReadPackage ) . toEqual ( expectedPackage ) ;
164+ } ) ;
121165} ) ;
122166
123167it ( 'returns same command if not an npm run command' , ( ) => {
0 commit comments