@@ -3,18 +3,20 @@ const mockNpm = require('../../fixtures/mock-npm')
33const { cleanCwd } = require ( '../../fixtures/clean-snapshot' )
44
55const mockExplore = async ( t , exec , {
6- RPJ_ERROR = null ,
6+ PJ_ERROR = null ,
77 RUN_SCRIPT_ERROR = null ,
88 RUN_SCRIPT_EXIT_CODE = 0 ,
99 RUN_SCRIPT_SIGNAL = null ,
1010} = { } ) => {
11- let RPJ_CALLED = ''
12- const mockRPJ = async path => {
13- if ( RPJ_ERROR ) {
14- throw RPJ_ERROR
15- }
16- RPJ_CALLED = cleanCwd ( path )
17- return { some : 'package' }
11+ let PJ_CALLED = ''
12+ const mockPJ = {
13+ normalize : async path => {
14+ if ( PJ_ERROR ) {
15+ throw PJ_ERROR
16+ }
17+ PJ_CALLED = cleanCwd ( path )
18+ return { content : { some : 'package' } }
19+ } ,
1820 }
1921
2022 let RUN_SCRIPT_EXEC = null
@@ -41,7 +43,7 @@ const mockExplore = async (t, exec, {
4143
4244 const mock = await mockNpm ( t , {
4345 mocks : {
44- 'read- package-json-fast ' : mockRPJ ,
46+ '@npmcli/ package-json' : mockPJ ,
4547 '@npmcli/run-script' : mockRunScript ,
4648 } ,
4749 config : {
@@ -53,7 +55,7 @@ const mockExplore = async (t, exec, {
5355
5456 return {
5557 ...mock ,
56- RPJ_CALLED ,
58+ PJ_CALLED ,
5759 RUN_SCRIPT_EXEC ,
5860 output : cleanCwd ( mock . joinedOutput ( ) ) . trim ( ) ,
5961 }
@@ -62,11 +64,11 @@ const mockExplore = async (t, exec, {
6264t . test ( 'basic interactive' , async t => {
6365 const {
6466 output,
65- RPJ_CALLED ,
67+ PJ_CALLED ,
6668 RUN_SCRIPT_EXEC ,
6769 } = await mockExplore ( t , [ 'pkg' ] )
6870
69- t . match ( RPJ_CALLED , / \/ p k g \/ p a c k a g e . j s o n $ / )
71+ t . ok ( PJ_CALLED . endsWith ( '/pkg' ) )
7072 t . strictSame ( RUN_SCRIPT_EXEC , 'shell-command' )
7173 t . match ( output , / E x p l o r i n g \{ C W D \} \/ [ \w - _ / ] + \n T y p e ' e x i t ' o r \^ D w h e n f i n i s h e d / )
7274} )
@@ -75,11 +77,11 @@ t.test('interactive tracks exit code', async t => {
7577 t . test ( 'code' , async t => {
7678 const {
7779 output,
78- RPJ_CALLED ,
80+ PJ_CALLED ,
7981 RUN_SCRIPT_EXEC ,
8082 } = await mockExplore ( t , [ 'pkg' ] , { RUN_SCRIPT_EXIT_CODE : 99 } )
8183
82- t . match ( RPJ_CALLED , / \/ p k g \/ p a c k a g e . j s o n $ / )
84+ t . ok ( PJ_CALLED . endsWith ( '/pkg' ) )
8385 t . strictSame ( RUN_SCRIPT_EXEC , 'shell-command' )
8486 t . match ( output , / E x p l o r i n g \{ C W D \} \/ [ \w - _ / ] + \n T y p e ' e x i t ' o r \^ D w h e n f i n i s h e d / )
8587
@@ -123,11 +125,11 @@ t.test('interactive tracks exit code', async t => {
123125t . test ( 'basic non-interactive' , async t => {
124126 const {
125127 output,
126- RPJ_CALLED ,
128+ PJ_CALLED ,
127129 RUN_SCRIPT_EXEC ,
128130 } = await mockExplore ( t , [ 'pkg' , 'ls' ] )
129131
130- t . match ( RPJ_CALLED , / \/ p k g \/ p a c k a g e . j s o n $ / )
132+ t . ok ( PJ_CALLED . endsWith ( '/pkg' ) )
131133 t . strictSame ( RUN_SCRIPT_EXEC , 'ls' )
132134
133135 t . strictSame ( output , '' )
@@ -164,10 +166,10 @@ t.test('usage if no pkg provided', async t => {
164166} )
165167
166168t . test ( 'pkg not installed' , async t => {
167- const RPJ_ERROR = new Error ( 'plurple' )
169+ const PJ_ERROR = new Error ( 'plurple' )
168170
169171 await t . rejects (
170- mockExplore ( t , [ 'pkg' , 'ls' ] , { RPJ_ERROR } ) ,
172+ mockExplore ( t , [ 'pkg' , 'ls' ] , { PJ_ERROR } ) ,
171173 { message : 'plurple' }
172174 )
173175} )
0 commit comments