Skip to content

Commit 06f2848

Browse files
committed
eperm ci
1 parent 4b1790e commit 06f2848

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

.github/workflows/eperm.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: CI
1+
name: EPERM
22

33
on:
44
workflow_dispatch:
55
inputs:
66
iterations:
7-
default: '20000'
7+
description: How many iterations to run
88

99
jobs:
1010
test:
@@ -26,6 +26,6 @@ jobs:
2626
run: npm install
2727

2828
- name: Run Tests
29-
run: npm test -- test/integration/eperm.ts
29+
run: npm test -- test/integration/eperm.ts --disable-coverage
3030
env:
3131
RIMRAF_TEST_EPERM_ITERATIONS: ${{ inputs.iterations }}

test/integration/eperm.ts

+55-12
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@ import t, { Test } from 'tap'
22
import { mkdirSync, readdirSync, writeFileSync } from 'fs'
33
import { sep, join } from 'path'
44
import { globSync } from 'glob'
5-
import { windows, windowsSync } from '../../src/index.js'
65
import { randomBytes } from 'crypto'
76
import assert from 'assert'
87

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+
915
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
1424

15-
t.plan(10)
1625
const dir = t.testdir()
1726
const readdir = () => readdirSync(dir)
1827

@@ -46,6 +55,14 @@ const setup = (t: Test) => {
4655
}
4756
}
4857

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+
4966
const assertContents = (expected: boolean = false) => {
5067
const found = readdir()
5168
assert(
@@ -82,6 +99,7 @@ const setup = (t: Test) => {
8299
iteration += 1
83100
yield {
84101
matches,
102+
tick,
85103
error: (error: unknown, path: string) =>
86104
new RunError('rimraf error', { path, error }),
87105
assertResult: (result: [string, boolean][]) => {
@@ -99,11 +117,7 @@ const setup = (t: Test) => {
99117
}),
100118
)
101119
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()
107121
},
108122
}
109123
}
@@ -117,7 +131,9 @@ const setup = (t: Test) => {
117131
// errors consistently in Windows CI environments.
118132
// https://github.com/sindresorhus/del/blob/chore/update-deps/test.js#L116
119133
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)
121137
for (const { matches, error, assertResult } of setup(t)()) {
122138
assertResult(
123139
matches.map(path => {
@@ -132,6 +148,8 @@ t.test('windows does not throw EPERM', t => {
132148
})
133149

134150
t.test('async', async t => {
151+
t.plan(10)
152+
const { windows } = await mockWindows(t)
135153
for (const { matches, error, assertResult } of setup(t)()) {
136154
assertResult(
137155
await Promise.all(
@@ -147,5 +165,30 @@ t.test('windows does not throw EPERM', t => {
147165
}
148166
})
149167

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+
150193
t.end()
151194
})

0 commit comments

Comments
 (0)