@@ -11,7 +11,7 @@ export interface TestUtils {
1111
1212export interface Storage {
1313 /** A list of files and their content */
14- [ filePath : string ] : string | Uint8Array
14+ [ filePath : string ] : string | Uint8Array | { [ IS_A_SYMLINK ] : true ; filepath : string }
1515}
1616
1717export interface TestConfig < Extras extends { } > {
@@ -69,6 +69,14 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {
6969 }
7070}
7171
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+
7280async function prepareFileSystem ( base : string , storage : Storage ) {
7381 // Create a temporary directory to store the test files
7482 await fs . mkdir ( base , { recursive : true } )
@@ -77,6 +85,13 @@ async function prepareFileSystem(base: string, storage: Storage) {
7785 for ( let [ filepath , content ] of Object . entries ( storage ) ) {
7886 let fullPath = path . resolve ( base , filepath )
7987 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+
8095 await fs . writeFile ( fullPath , content , { encoding : 'utf-8' } )
8196 }
8297}
0 commit comments