@@ -24,7 +24,8 @@ import {
2424import { Json } from "../../../src/json" ;
2525import { RecipeSpec } from "../../../src/test" ;
2626import { withDir } from "tmp-promise" ;
27- import { findMarker , MarkersKind } from "../../../src" ;
27+ import * as fs from "fs" ;
28+ import * as path from "path" ;
2829
2930describe ( "UpgradeDependencyVersion" , ( ) => {
3031
@@ -292,40 +293,62 @@ describe("UpgradeDependencyVersion", () => {
292293 } , { unsafeCleanup : true } ) ;
293294 } ) ;
294295
295- test ( "adds warning marker when version does not exist " , async ( ) => {
296+ test ( "throws when install fails for non-existent version " , async ( ) => {
296297 const spec = new RecipeSpec ( ) ;
297298 spec . recipe = new UpgradeDependencyVersion ( {
298299 packageName : "uuid" ,
299300 newVersion : "^999.0.0" // Non-existent version
300301 } ) ;
301302
302303 await withDir ( async ( repo ) => {
303- await spec . rewriteRun (
304+ await expect ( spec . rewriteRun (
304305 npm (
305306 repo . path ,
306307 typescript ( `const x = 1;` ) ,
307- {
308- // Version doesn't change, but warning marker is added
309- ...packageJson ( `
308+ packageJson ( `
310309 {
311310 "name": "test-project",
312311 "version": "1.0.0",
313312 "dependencies": {
314313 "uuid": "^9.0.0"
315314 }
316315 }
317- ` , ( actual : string ) => {
318- expect ( actual ) . toContain ( '/*~~(Failed to upgrade uuid to ^999.0.0' ) ;
319- return actual ;
320- } ) , afterRecipe : async ( doc : Json . Document ) => {
321- // Should have a warning marker
322- const warnMarker = findMarker ( doc , MarkersKind . MarkupWarn ) ;
323- expect ( warnMarker ) . toBeDefined ( ) ;
324- expect ( ( warnMarker as any ) . message ) . toContain ( "Failed to upgrade uuid" ) ;
316+ ` )
317+ )
318+ ) ) . rejects . toThrow ( "Failed to upgrade uuid to ^999.0.0" ) ;
319+ } , { unsafeCleanup : true } ) ;
320+ } ) ;
321+
322+ test ( "throws when install fails due to engine version mismatch" , async ( ) => {
323+ const spec = new RecipeSpec ( ) ;
324+ spec . recipe = new UpgradeDependencyVersion ( {
325+ packageName : "uuid" ,
326+ newVersion : "^10.0.0"
327+ } ) ;
328+
329+ await withDir ( async ( repo ) => {
330+ // given
331+ fs . writeFileSync ( path . join ( repo . path , '.npmrc' ) , 'engine-strict=true' ) ;
332+
333+ // when / then
334+ await expect ( spec . rewriteRun (
335+ npm (
336+ repo . path ,
337+ typescript ( `const x = 1;` ) ,
338+ packageJson ( `
339+ {
340+ "name": "test-project",
341+ "version": "1.0.0",
342+ "engines": {
343+ "node": "504.436"
344+ },
345+ "dependencies": {
346+ "uuid": "^9.0.0"
347+ }
325348 }
326- }
349+ ` )
327350 )
328- ) ;
351+ ) ) . rejects . toThrow ( / ^ E r r o r : F a i l e d t o u p g r a d e u u i d t o \^ 1 0 \. 0 \. 0 : / ) ;
329352 } , { unsafeCleanup : true } ) ;
330353 } ) ;
331354
0 commit comments