@@ -24,6 +24,7 @@ import {
2424import { Json } from "../../../src/json" ;
2525import { RecipeSpec } from "../../../src/test" ;
2626import { withDir } from "tmp-promise" ;
27+ import { findMarker , MarkersKind } from "../../../src" ;
2728import * as fs from "fs" ;
2829import * as path from "path" ;
2930import * as semver from "semver" ;
@@ -294,33 +295,42 @@ describe("UpgradeDependencyVersion", () => {
294295 } , { unsafeCleanup : true } ) ;
295296 } ) ;
296297
297- test ( "throws when install fails for non-existent version" , async ( ) => {
298+ test ( "adds warning marker when install fails for non-existent version" , async ( ) => {
298299 const spec = new RecipeSpec ( ) ;
299300 spec . recipe = new UpgradeDependencyVersion ( {
300301 packageName : "uuid" ,
301302 newVersion : "^999.0.0" // Non-existent version
302303 } ) ;
303304
304305 await withDir ( async ( repo ) => {
305- await expect ( spec . rewriteRun (
306+ await spec . rewriteRun (
306307 npm (
307308 repo . path ,
308309 typescript ( `const x = 1;` ) ,
309- packageJson ( `
310- {
311- "name": "test-project",
312- "version": "1.0.0",
313- "dependencies": {
314- "uuid": "^9.0.0"
310+ {
311+ ...packageJson ( `
312+ {
313+ "name": "test-project",
314+ "version": "1.0.0",
315+ "dependencies": {
316+ "uuid": "^9.0.0"
317+ }
315318 }
319+ ` , ( actual : string ) => {
320+ expect ( actual ) . toContain ( '/*~~(Failed to upgrade uuid to ^999.0.0' ) ;
321+ return actual ;
322+ } ) , afterRecipe : async ( doc : Json . Document ) => {
323+ const warnMarker = findMarker ( doc , MarkersKind . MarkupWarn ) ;
324+ expect ( warnMarker ) . toBeDefined ( ) ;
325+ expect ( ( warnMarker as any ) . message ) . toContain ( "Failed to upgrade uuid to ^999.0.0" ) ;
316326 }
317- ` )
327+ }
318328 )
319- ) ) . rejects . toThrow ( "Failed to upgrade uuid to ^999.0.0" ) ;
329+ ) ;
320330 } , { unsafeCleanup : true } ) ;
321331 } ) ;
322332
323- test ( "throws when install fails due to engine version mismatch" , async ( ) => {
333+ test ( "adds warning marker when install fails due to engine version mismatch" , async ( ) => {
324334 const spec = new RecipeSpec ( ) ;
325335 spec . recipe = new UpgradeDependencyVersion ( {
326336 packageName : "uuid" ,
@@ -332,24 +342,33 @@ describe("UpgradeDependencyVersion", () => {
332342 fs . writeFileSync ( path . join ( repo . path , '.npmrc' ) , 'engine-strict=true' ) ;
333343
334344 // when / then
335- await expect ( spec . rewriteRun (
345+ await spec . rewriteRun (
336346 npm (
337347 repo . path ,
338348 typescript ( `const x = 1;` ) ,
339- packageJson ( `
340- {
341- "name": "test-project",
342- "version": "1.0.0",
343- "engines": {
344- "node": "504.436"
345- },
346- "dependencies": {
347- "uuid": "^9.0.0"
349+ {
350+ ...packageJson ( `
351+ {
352+ "name": "test-project",
353+ "version": "1.0.0",
354+ "engines": {
355+ "node": "504.436"
356+ },
357+ "dependencies": {
358+ "uuid": "^9.0.0"
359+ }
348360 }
361+ ` , ( actual : string ) => {
362+ expect ( actual ) . toContain ( '/*~~(Failed to upgrade uuid to ^10.0.0' ) ;
363+ return actual ;
364+ } ) , afterRecipe : async ( doc : Json . Document ) => {
365+ const warnMarker = findMarker ( doc , MarkersKind . MarkupWarn ) ;
366+ expect ( warnMarker ) . toBeDefined ( ) ;
367+ expect ( ( warnMarker as any ) . message ) . toContain ( "Failed to upgrade uuid to ^10.0.0" ) ;
349368 }
350- ` )
369+ }
351370 )
352- ) ) . 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 : / ) ;
371+ ) ;
353372 } , { unsafeCleanup : true } ) ;
354373 } ) ;
355374
0 commit comments