@@ -11,7 +11,7 @@ export interface TestUtils {
11
11
12
12
export interface Storage {
13
13
/** A list of files and their content */
14
- [ filePath : string ] : string | Uint8Array
14
+ [ filePath : string ] : string | Uint8Array | { [ IS_A_SYMLINK ] : true ; filepath : string }
15
15
}
16
16
17
17
export interface TestConfig < Extras extends { } > {
@@ -69,6 +69,14 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {
69
69
}
70
70
}
71
71
72
+ const IS_A_SYMLINK = Symbol ( 'is-a-symlink' )
73
+ export const symlinkTo = function ( filepath : string ) {
74
+ return {
75
+ [ IS_A_SYMLINK ] : true as const ,
76
+ filepath,
77
+ }
78
+ }
79
+
72
80
async function prepareFileSystem ( base : string , storage : Storage ) {
73
81
// Create a temporary directory to store the test files
74
82
await fs . mkdir ( base , { recursive : true } )
@@ -77,6 +85,13 @@ async function prepareFileSystem(base: string, storage: Storage) {
77
85
for ( let [ filepath , content ] of Object . entries ( storage ) ) {
78
86
let fullPath = path . resolve ( base , filepath )
79
87
await fs . mkdir ( path . dirname ( fullPath ) , { recursive : true } )
88
+
89
+ if ( typeof content === 'object' && IS_A_SYMLINK in content ) {
90
+ let target = path . resolve ( base , content . filepath )
91
+ await fs . symlink ( target , fullPath )
92
+ continue
93
+ }
94
+
80
95
await fs . writeFile ( fullPath , content , { encoding : 'utf-8' } )
81
96
}
82
97
}
0 commit comments