@@ -2,17 +2,26 @@ import t, { Test } from 'tap'
2
2
import { mkdirSync , readdirSync , writeFileSync } from 'fs'
3
3
import { sep , join } from 'path'
4
4
import { globSync } from 'glob'
5
- import { windows , windowsSync } from '../../src/index.js'
6
5
import { randomBytes } from 'crypto'
7
6
import assert from 'assert'
8
7
8
+ const isWinCI = process . env . CI && process . platform === 'win32'
9
+
10
+ const mockWindows = async ( t : Test ) =>
11
+ ( await t . mockImport (
12
+ '../../src/index.js' ,
13
+ ) ) as typeof import ( '../../src/index.js' )
14
+
9
15
const setup = ( t : Test ) => {
10
- const [ iterations , depth , fileCount , fileKb ] =
11
- process . env . CI && process . platform === 'win32' ?
12
- [ Number ( process . env ?. RIMRAF_TEST_EPERM_ITERATIONS ?? 1000 ) , 15 , 7 , 100 ]
13
- : [ 200 , 8 , 3 , 10 ]
16
+ const depth = 10
17
+ const fileCount = 7
18
+ const fileKb = 100
19
+ const iterations =
20
+ process . env ?. RIMRAF_TEST_EPERM_ITERATIONS ?
21
+ + process . env . RIMRAF_TEST_EPERM_ITERATIONS
22
+ : isWinCI ? 1000
23
+ : 100
14
24
15
- t . plan ( 10 )
16
25
const dir = t . testdir ( )
17
26
const readdir = ( ) => readdirSync ( dir )
18
27
@@ -46,6 +55,14 @@ const setup = (t: Test) => {
46
55
}
47
56
}
48
57
58
+ const tick = ( ) => {
59
+ if ( iteration % ( iterations / 10 ) === 0 ) {
60
+ const now = Date . now ( )
61
+ t . ok ( true , `${ iteration } (${ now - previous } ms / ${ now - start } ms)` )
62
+ previous = now
63
+ }
64
+ }
65
+
49
66
const assertContents = ( expected : boolean = false ) => {
50
67
const found = readdir ( )
51
68
assert (
@@ -82,6 +99,7 @@ const setup = (t: Test) => {
82
99
iteration += 1
83
100
yield {
84
101
matches,
102
+ tick,
85
103
error : ( error : unknown , path : string ) =>
86
104
new RunError ( 'rimraf error' , { path, error } ) ,
87
105
assertResult : ( result : [ string , boolean ] [ ] ) => {
@@ -99,11 +117,7 @@ const setup = (t: Test) => {
99
117
} ) ,
100
118
)
101
119
assertContents ( )
102
- if ( iteration % ( iterations / 10 ) === 0 ) {
103
- const now = Date . now ( )
104
- t . ok ( true , `${ iteration } (${ now - previous } ms / ${ now - start } ms)` )
105
- previous = now
106
- }
120
+ tick ( )
107
121
} ,
108
122
}
109
123
}
@@ -117,7 +131,9 @@ const setup = (t: Test) => {
117
131
// errors consistently in Windows CI environments.
118
132
// https://github.com/sindresorhus/del/blob/chore/update-deps/test.js#L116
119
133
t . test ( 'windows does not throw EPERM' , t => {
120
- t . test ( 'sync' , t => {
134
+ t . test ( 'sync' , async t => {
135
+ t . plan ( 10 )
136
+ const { windowsSync } = await mockWindows ( t )
121
137
for ( const { matches, error, assertResult } of setup ( t ) ( ) ) {
122
138
assertResult (
123
139
matches . map ( path => {
@@ -132,6 +148,8 @@ t.test('windows does not throw EPERM', t => {
132
148
} )
133
149
134
150
t . test ( 'async' , async t => {
151
+ t . plan ( 10 )
152
+ const { windows } = await mockWindows ( t )
135
153
for ( const { matches, error, assertResult } of setup ( t ) ( ) ) {
136
154
assertResult (
137
155
await Promise . all (
@@ -147,5 +165,30 @@ t.test('windows does not throw EPERM', t => {
147
165
}
148
166
} )
149
167
168
+ if ( isWinCI ) {
169
+ t . test ( 'async error' , async t => {
170
+ t . intercept ( process , 'platform' , { value : 'posix' } )
171
+ const { windows } = await mockWindows ( t )
172
+ let error = null
173
+ try {
174
+ for ( const { matches, error, tick } of setup ( t ) ( ) ) {
175
+ await Promise . all (
176
+ matches . map ( async path => {
177
+ try {
178
+ return [ path , await windows ( path ) ]
179
+ } catch ( er ) {
180
+ throw error ( er , path )
181
+ }
182
+ } ) ,
183
+ )
184
+ tick ( )
185
+ }
186
+ } catch ( e ) {
187
+ error = e
188
+ }
189
+ t . comment ( error )
190
+ } )
191
+ }
192
+
150
193
t . end ( )
151
194
} )
0 commit comments