Skip to content

Commit ed7b2a6

Browse files
committed
test: chmod ordering is nondeterministic
This just snapshots *whether* we had some chmods, since many of these cases, it can be one of 2 different files in either order.
1 parent 4cb1d47 commit ed7b2a6

File tree

2 files changed

+29
-57
lines changed

2 files changed

+29
-57
lines changed

tap-snapshots/test/rimraf-windows.js.test.cjs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -113,56 +113,26 @@ Array [
113113
]
114114
`
115115

116-
exports[`test/rimraf-windows.js TAP handle EPERMs on unlink by trying to chmod 0o666 async > must match snapshot 1`] = `
117-
Array [
118-
Array [
119-
"chmod",
120-
"{CWD}/test/tap-testdir-rimraf-windows-handle-EPERMs-on-unlink-by-trying-to-chmod-0o666-async/test/a",
121-
"438",
122-
],
123-
]
116+
exports[`test/rimraf-windows.js TAP handle EPERMs on unlink by trying to chmod 0o666 async > chmods 1`] = `
117+
1
124118
`
125119

126-
exports[`test/rimraf-windows.js TAP handle EPERMs on unlink by trying to chmod 0o666 sync > must match snapshot 1`] = `
127-
Array [
128-
Array [
129-
"chmodSync",
130-
"{CWD}/test/tap-testdir-rimraf-windows-handle-EPERMs-on-unlink-by-trying-to-chmod-0o666-sync/test/a",
131-
"438",
132-
],
133-
]
120+
exports[`test/rimraf-windows.js TAP handle EPERMs on unlink by trying to chmod 0o666 sync > chmods 1`] = `
121+
1
134122
`
135123

136-
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod raises something other than ENOENT async > must match snapshot 1`] = `
137-
Array []
124+
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod raises something other than ENOENT async > chmods 1`] = `
125+
0
138126
`
139127

140-
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod raises something other than ENOENT sync > must match snapshot 1`] = `
141-
Array [
142-
Array [
143-
"chmodSync",
144-
"{CWD}/test/tap-testdir-rimraf-windows-handle-EPERMs-chmod-raises-something-other-than-ENOENT-sync/test/a",
145-
"438",
146-
],
147-
]
128+
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod raises something other than ENOENT sync > chmods 1`] = `
129+
1
148130
`
149131

150-
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod returns ENOENT async > must match snapshot 1`] = `
151-
Array [
152-
Array [
153-
"chmod",
154-
"{CWD}/test/tap-testdir-rimraf-windows-handle-EPERMs-chmod-returns-ENOENT-async/test/a",
155-
"438",
156-
],
157-
]
132+
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod returns ENOENT async > chmods 1`] = `
133+
1
158134
`
159135

160-
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod returns ENOENT sync > must match snapshot 1`] = `
161-
Array [
162-
Array [
163-
"chmodSync",
164-
"{CWD}/test/tap-testdir-rimraf-windows-handle-EPERMs-chmod-returns-ENOENT-sync/test/a",
165-
"438",
166-
],
167-
]
136+
exports[`test/rimraf-windows.js TAP handle EPERMs, chmod returns ENOENT sync > chmods 1`] = `
137+
1
168138
`

test/rimraf-windows.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ const t = require('tap')
22
const { parse, basename, relative } = require('path')
33
const { statSync } = require('fs')
44
t.formatSnapshot = calls =>
5-
calls.map(args =>
6-
args.map(arg =>
7-
String(arg)
8-
.split(process.cwd())
9-
.join('{CWD}')
10-
.replace(/\\/g, '/')
11-
.replace(/.*\/(\.[a-z]\.)[^/]*$/, '{tmpfile}')
12-
)
13-
)
5+
Array.isArray(calls)
6+
? calls.map(args =>
7+
args.map(arg =>
8+
String(arg)
9+
.split(process.cwd())
10+
.join('{CWD}')
11+
.replace(/\\/g, '/')
12+
.replace(/.*\/(\.[a-z]\.)[^/]*$/, '{tmpfile}')
13+
)
14+
)
15+
: calls
1416

1517
const fixture = {
1618
a: 'a',
@@ -310,14 +312,14 @@ t.test('handle EPERMs on unlink by trying to chmod 0o666', async t => {
310312
// nest it so that we clean up the mess
311313
const path = t.testdir({ test: fixture }) + '/test'
312314
rimrafWindowsSync(path, {})
313-
t.matchSnapshot(CHMODS)
315+
t.matchSnapshot(CHMODS.length, 'chmods')
314316
t.end()
315317
})
316318
t.test('async', async t => {
317319
// nest it so that we clean up the mess
318320
const path = t.testdir({ test: fixture }) + '/test'
319321
await rimrafWindows(path, {})
320-
t.matchSnapshot(CHMODS)
322+
t.matchSnapshot(CHMODS.length, 'chmods')
321323
t.end()
322324
})
323325
t.end()
@@ -374,14 +376,14 @@ t.test('handle EPERMs, chmod returns ENOENT', async t => {
374376
// nest it so that we clean up the mess
375377
const path = t.testdir({ test: fixture }) + '/test'
376378
rimrafWindowsSync(path, {})
377-
t.matchSnapshot(CHMODS)
379+
t.matchSnapshot(CHMODS.length, 'chmods')
378380
t.end()
379381
})
380382
t.test('async', async t => {
381383
// nest it so that we clean up the mess
382384
const path = t.testdir({ test: fixture }) + '/test'
383385
await rimrafWindows(path, {})
384-
t.matchSnapshot(CHMODS)
386+
t.matchSnapshot(CHMODS.length, 'chmods')
385387
t.end()
386388
})
387389
t.end()
@@ -438,14 +440,14 @@ t.test('handle EPERMs, chmod raises something other than ENOENT', async t => {
438440
// nest it so that we clean up the mess
439441
const path = t.testdir({ test: fixture }) + '/test'
440442
t.throws(() => rimrafWindowsSync(path, {}), { code: 'EPERM' })
441-
t.matchSnapshot(CHMODS)
443+
t.matchSnapshot(CHMODS.length, 'chmods')
442444
t.end()
443445
})
444446
t.test('async', async t => {
445447
// nest it so that we clean up the mess
446448
const path = t.testdir({ test: fixture }) + '/test'
447449
t.rejects(rimrafWindows(path, {}), { code: 'EPERM' })
448-
t.matchSnapshot(CHMODS)
450+
t.matchSnapshot(CHMODS.length, 'chmods')
449451
t.end()
450452
})
451453
t.end()

0 commit comments

Comments
 (0)