@@ -15,6 +15,8 @@ describe("create-symlink", () => {
1515 fs . unlink . mockResolvedValue ( ) ;
1616 fs . symlink . mockResolvedValue ( ) ;
1717 fs . pathExists . mockResolvedValue ( true ) ;
18+ fs . outputFile . mockResolvedValue ( ) ;
19+ fs . remove . mockResolvedValue ( ) ;
1820 cmdShim . mockResolvedValue ( ) ;
1921
2022 if ( process . platform !== "win32" ) {
@@ -86,5 +88,33 @@ describe("create-symlink", () => {
8688 expect ( fs . unlink ) . toHaveBeenLastCalledWith ( dst ) ;
8789 expect ( fs . symlink ) . toHaveBeenLastCalledWith ( src , dst , type ) ;
8890 } ) ;
91+
92+ it ( "creates stub symlink to executable that doesn't exist yet" , async ( ) => {
93+ const src = path . resolve ( "./packages/package-3/cli.js" ) ;
94+ const dst = path . resolve ( "./packages/package-1/node_modules/.bin/package-3" ) ;
95+ const type = "exec" ;
96+
97+ fs . pathExists . mockResolvedValueOnce ( false ) ;
98+
99+ await createSymlink ( src , dst , type ) ;
100+
101+ expect ( fs . outputFile ) . toHaveBeenLastCalledWith ( src , "" ) ;
102+ expect ( cmdShim ) . toHaveBeenLastCalledWith ( src , dst ) ;
103+ expect ( fs . remove ) . toHaveBeenLastCalledWith ( src ) ;
104+ } ) ;
105+
106+ it ( "does not swallow cmd-shim errors when executable doesn't exist yet" , async ( ) => {
107+ cmdShim . mockImplementationOnce ( ( ) => Promise . reject ( new Error ( "oh no" ) ) ) ;
108+ fs . pathExists . mockResolvedValueOnce ( false ) ;
109+
110+ try {
111+ await createSymlink ( "src" , "dst" , "exec" ) ;
112+ } catch ( err ) {
113+ expect ( err . message ) . toBe ( "oh no" ) ;
114+ expect ( fs . remove ) . toHaveBeenLastCalledWith ( "src" ) ;
115+ }
116+
117+ expect . hasAssertions ( ) ;
118+ } ) ;
89119 }
90120} ) ;
0 commit comments