@@ -8,52 +8,67 @@ import { existsSync } from "fs";
88import { mkdir , writeFile , rm } from "node:fs/promises" ;
99import { handler } from "../index" ;
1010
11- const mockAssetDirectoryPath = path . join ( __dirname , "mock-dir" ) ;
12- const mockOutputPath = path . join ( __dirname , "mock-dir-output" ) ;
11+ const __assetDirectoryPath = path . join ( __dirname , "mock-dir" ) ;
12+ const __outputPath = path . join ( __dirname , "mock-dir-output" ) ;
1313describe ( "Handler" , ( ) => {
1414 beforeAll ( async function Arrange ( ) {
15- await rm ( mockAssetDirectoryPath , { recursive : true , force : true } ) ;
16- await rm ( mockOutputPath , { recursive : true , force : true } ) ;
17- await mkdir ( mockAssetDirectoryPath ) ;
18- await mkdir ( mockOutputPath ) ;
15+ await rm ( __assetDirectoryPath , { recursive : true , force : true } ) ;
16+ await rm ( __outputPath , { recursive : true , force : true } ) ;
17+ await mkdir ( __assetDirectoryPath ) ;
18+ await mkdir ( __outputPath ) ;
1919 } ) ;
2020
2121 it ( "should fail in absence of path inputs " , async function ( ) {
2222 expect . assertions ( 2 ) ;
2323 await expect ( handler ( "" , "" ) ) . rejects . toThrowError ( "undefined input path" ) ;
24- await expect ( handler ( undefined , undefined ) ) . rejects . toThrowError ( "undefined input path" ) ;
24+ await expect ( handler ( undefined , undefined ) ) . rejects . toThrowError (
25+ "undefined input path"
26+ ) ;
2527 } ) ;
2628
2729 it ( "should fail for invalid cdk asset path" , async function ( ) {
2830 expect . assertions ( 1 ) ;
29- await expect ( handler ( "invalidPath" , mockOutputPath ) ) . rejects . toThrowError ( / ( E N O E N T ) .+ ( i n v a l i d P a t h ) / g) ;
31+ await expect ( handler ( "invalidPath" , __outputPath ) ) . rejects . toThrowError (
32+ / ( E N O E N T ) .+ ( i n v a l i d P a t h ) / g
33+ ) ;
3034 } ) ;
3135
3236 it ( "should succeed if cdk assets not found" , async function ( ) {
33- await expect ( handler ( mockAssetDirectoryPath , "invalidPath" ) ) . resolves . toBeUndefined ( ) ;
37+ await expect (
38+ handler ( __assetDirectoryPath , "invalidPath" )
39+ ) . resolves . toBeUndefined ( ) ;
3440 } ) ;
3541
3642 it ( "should fail for invalid output path" , async function ( ) {
3743 // Arrange
3844 expect . assertions ( 1 ) ;
39- const mockAssetPath = path . join ( mockAssetDirectoryPath , "./asset.cdkAsset.zip" ) ;
45+ const mockAssetPath = path . join (
46+ __assetDirectoryPath ,
47+ "./asset.cdkAsset.zip"
48+ ) ;
4049 await writeFile ( mockAssetPath , "NoOp" ) ;
4150 // Act, Assert
42- await expect ( handler ( mockAssetDirectoryPath , "invalidPath" ) ) . rejects . toThrowError ( / ( E N O E N T ) .+ ( i n v a l i d P a t h ) / g) ;
51+ await expect (
52+ handler ( __assetDirectoryPath , "invalidPath" )
53+ ) . rejects . toThrowError ( / ( E N O E N T ) .+ ( i n v a l i d P a t h ) / g) ;
4354 // Cleanup
4455 await rm ( mockAssetPath ) ;
4556 } ) ;
4657
4758 it ( "should successfully stage zip for valid paths" , async function ( ) {
4859 const zipName = "asset.cdkAsset.zip" ;
49- const mockAssetPath = path . join ( mockAssetDirectoryPath , zipName ) ;
60+ const mockAssetPath = path . join ( __assetDirectoryPath , zipName ) ;
5061 await writeFile ( mockAssetPath , "NoOp" ) ;
51- await expect ( handler ( mockAssetDirectoryPath , mockOutputPath ) ) . resolves . toBeUndefined ( ) ;
52- expect ( existsSync ( path . join ( mockOutputPath , zipName . split ( "asset." ) . pop ( ) ! ) ) ) . toBe ( true ) ;
62+ await expect (
63+ handler ( __assetDirectoryPath , __outputPath )
64+ ) . resolves . toBeUndefined ( ) ;
65+ expect (
66+ existsSync ( path . join ( __outputPath , zipName . split ( "asset." ) . pop ( ) ! ) )
67+ ) . toBe ( true ) ;
5368 } ) ;
5469
5570 afterAll ( async function Cleanup ( ) {
56- await rm ( mockAssetDirectoryPath , { recursive : true , force : true } ) ;
57- await rm ( mockOutputPath , { recursive : true , force : true } ) ;
71+ await rm ( __assetDirectoryPath , { recursive : true , force : true } ) ;
72+ await rm ( __outputPath , { recursive : true , force : true } ) ;
5873 } ) ;
5974} ) ;
0 commit comments