1
1
import { onTestFinished , test , TestOptions } from 'vitest'
2
+ import * as os from 'node:os'
2
3
import * as fs from 'node:fs/promises'
3
4
import * as path from 'node:path'
4
5
import * as proc from 'node:child_process'
@@ -12,6 +13,7 @@ export interface TestUtils {
12
13
export interface StorageSymlink {
13
14
[ IS_A_SYMLINK ] : true
14
15
filepath : string
16
+ type : 'file' | 'dir' | undefined
15
17
}
16
18
17
19
export interface Storage {
@@ -75,10 +77,11 @@ async function setup<T>(config: TestConfig<T>): Promise<TestUtils> {
75
77
}
76
78
77
79
const IS_A_SYMLINK = Symbol ( 'is-a-symlink' )
78
- export function symlinkTo ( filepath : string ) : StorageSymlink {
80
+ export function symlinkTo ( filepath : string , type ?: 'file' | 'dir' ) : StorageSymlink {
79
81
return {
80
82
[ IS_A_SYMLINK ] : true as const ,
81
83
filepath,
84
+ type,
82
85
}
83
86
}
84
87
@@ -93,7 +96,14 @@ async function prepareFileSystem(base: string, storage: Storage) {
93
96
94
97
if ( typeof content === 'object' && IS_A_SYMLINK in content ) {
95
98
let target = path . resolve ( base , content . filepath )
96
- await fs . symlink ( target , fullPath )
99
+
100
+ let type : string = content . type
101
+
102
+ if ( os . platform ( ) === 'win32' && content . type === 'dir' ) {
103
+ type = 'junction'
104
+ }
105
+
106
+ await fs . symlink ( target , fullPath , type )
97
107
continue
98
108
}
99
109
0 commit comments