Skip to content

Commit 49a2958

Browse files
committed
formatting tests
1 parent 6bfd096 commit 49a2958

10 files changed

+143
-100
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/coverage
44
/dist
55
!/typedoc.json
6+
!/tsconfig-*.json
7+
!/.prettierignore

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# v4.1
22

33
- Improved hybrid module with no need to look at the `.default`
4-
dangly bit. `.default` preserved as a reference to `rimraf`
4+
dangly bit. `.default` preserved as a reference to `rimraf`
55
for compatibility with anyone who came to rely on it in v4.0.
66
- Accept and ignore `-rf` and `-fr` arguments to the bin.
77

test/default-tmp.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ const t = require('tap')
22

33
t.test('posix platform', async t => {
44
const { tmpdir } = require('os')
5-
const { defaultTmp, defaultTmpSync } = t.mock('../dist/cjs/src/default-tmp.js', {
6-
'../dist/cjs/src/platform.js': 'posix',
7-
})
5+
const { defaultTmp, defaultTmpSync } = t.mock(
6+
'../dist/cjs/src/default-tmp.js',
7+
{
8+
'../dist/cjs/src/platform.js': 'posix',
9+
}
10+
)
811
t.equal(defaultTmpSync('anything'), tmpdir())
912
t.equal(await defaultTmp('anything').then(t => t), tmpdir())
1013
})
@@ -20,19 +23,22 @@ t.test('windows', async t => {
2023
throw Object.assign(new Error('no ents here'), { code: 'ENOENT' })
2124
}
2225
}
23-
const { defaultTmp, defaultTmpSync } = t.mock('../dist/cjs/src/default-tmp.js', {
24-
os: {
25-
tmpdir: () => 'C:\\Windows\\Temp',
26-
},
27-
path: require('path').win32,
28-
'../dist/cjs/src/platform.js': 'win32',
29-
'../dist/cjs/src/fs.js': {
30-
statSync: tempDirCheck,
31-
promises: {
32-
stat: async path => tempDirCheck(path),
26+
const { defaultTmp, defaultTmpSync } = t.mock(
27+
'../dist/cjs/src/default-tmp.js',
28+
{
29+
os: {
30+
tmpdir: () => 'C:\\Windows\\Temp',
31+
},
32+
path: require('path').win32,
33+
'../dist/cjs/src/platform.js': 'win32',
34+
'../dist/cjs/src/fs.js': {
35+
statSync: tempDirCheck,
36+
promises: {
37+
stat: async path => tempDirCheck(path),
38+
},
3339
},
34-
},
35-
})
40+
}
41+
)
3642

3743
const expect = {
3844
'c:\\some\\path': 'C:\\Windows\\Temp',

test/delete-many-files.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ const START = (process.env.RIMRAF_TEST_START_CHAR || 'a').charCodeAt(0)
1313
const END = (process.env.RIMRAF_TEST_END_CHAR || 'f').charCodeAt(0)
1414
const DEPTH = +process.env.RIMRAF_TEST_DEPTH || 4
1515

16-
const {
17-
statSync,
18-
mkdirSync,
19-
readdirSync,
20-
} = require('../dist/cjs/src/fs.js')
16+
const { statSync, mkdirSync, readdirSync } = require('../dist/cjs/src/fs.js')
2117
const { writeFileSync } = require('fs')
2218
const { resolve, dirname } = require('path')
2319

test/ignore-enoent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const t = require('tap')
2-
const { ignoreENOENT, ignoreENOENTSync } = require('../dist/cjs/src/ignore-enoent.js')
2+
const {
3+
ignoreENOENT,
4+
ignoreENOENTSync,
5+
} = require('../dist/cjs/src/ignore-enoent.js')
36

47
const enoent = Object.assign(new Error('no ent'), { code: 'ENOENT' })
58
const eperm = Object.assign(new Error('eperm'), { code: 'EPERM' })

test/rimraf-manual.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
const t = require('tap')
22

3-
const { rimrafWindows, rimrafWindowsSync } = require('../dist/cjs/src/rimraf-windows.js')
3+
const {
4+
rimrafWindows,
5+
rimrafWindowsSync,
6+
} = require('../dist/cjs/src/rimraf-windows.js')
47

5-
const { rimrafPosix, rimrafPosixSync } = require('../dist/cjs/src/rimraf-posix.js')
8+
const {
9+
rimrafPosix,
10+
rimrafPosixSync,
11+
} = require('../dist/cjs/src/rimraf-posix.js')
612

7-
const { rimrafManual, rimrafManualSync } = require('../dist/cjs/src/rimraf-manual.js')
13+
const {
14+
rimrafManual,
15+
rimrafManualSync,
16+
} = require('../dist/cjs/src/rimraf-manual.js')
817

918
if (!process.env.__TESTING_RIMRAF_PLATFORM__) {
1019
const otherPlatform = process.platform !== 'win32' ? 'win32' : 'posix'

test/rimraf-move-remove.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ t.only('actually delete some stuff', async t => {
5757
// but actually do wait to clean them up, though
5858
t.teardown(() => Promise.all(danglers))
5959

60-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
61-
'../dist/cjs/src/fs.js': fsMock,
62-
})
60+
const { rimrafPosix, rimrafPosixSync } = t.mock(
61+
'../dist/cjs/src/rimraf-posix.js',
62+
{
63+
'../dist/cjs/src/fs.js': fsMock,
64+
}
65+
)
6366

6467
const { rimrafMoveRemove, rimrafMoveRemoveSync } = t.mock(
6568
'../dist/cjs/src/rimraf-move-remove.js',

test/rimraf-native.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ const fs = {
1212
},
1313
}
1414

15-
const { rimrafNative, rimrafNativeSync } = t.mock('../dist/cjs/src/rimraf-native.js', {
16-
'../dist/cjs/src/fs.js': fs,
17-
})
15+
const { rimrafNative, rimrafNativeSync } = t.mock(
16+
'../dist/cjs/src/rimraf-native.js',
17+
{
18+
'../dist/cjs/src/fs.js': fs,
19+
}
20+
)
1821

1922
t.test('calls the right node function', async t => {
2023
await rimrafNative('path', { x: 'y' })

test/rimraf-posix.js

Lines changed: 84 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
// }
99

1010
const t = require('tap')
11-
const { rimrafPosix, rimrafPosixSync } = require('../dist/cjs/src/rimraf-posix.js')
11+
const {
12+
rimrafPosix,
13+
rimrafPosixSync,
14+
} = require('../dist/cjs/src/rimraf-posix.js')
1215

1316
const fs = require('../dist/cjs/src/fs.js')
1417

@@ -56,92 +59,104 @@ t.test('actually delete some stuff', t => {
5659
})
5760

5861
t.test('throw unlink errors', async t => {
59-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
60-
'../dist/cjs/src/fs.js': {
61-
...fs,
62-
unlinkSync: path => {
63-
throw Object.assign(new Error('cannot unlink'), { code: 'FOO' })
64-
},
65-
promises: {
66-
...fs.promises,
67-
unlink: async path => {
62+
const { rimrafPosix, rimrafPosixSync } = t.mock(
63+
'../dist/cjs/src/rimraf-posix.js',
64+
{
65+
'../dist/cjs/src/fs.js': {
66+
...fs,
67+
unlinkSync: path => {
6868
throw Object.assign(new Error('cannot unlink'), { code: 'FOO' })
6969
},
70+
promises: {
71+
...fs.promises,
72+
unlink: async path => {
73+
throw Object.assign(new Error('cannot unlink'), { code: 'FOO' })
74+
},
75+
},
7076
},
71-
},
72-
})
77+
}
78+
)
7379
const path = t.testdir(fixture)
7480
t.throws(() => rimrafPosixSync(path, {}), { code: 'FOO' })
7581
t.rejects(rimrafPosix(path, {}), { code: 'FOO' })
7682
})
7783

7884
t.test('throw rmdir errors', async t => {
79-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
80-
'../dist/cjs/src/fs.js': {
81-
...fs,
82-
rmdirSync: path => {
83-
throw Object.assign(new Error('cannot rmdir'), { code: 'FOO' })
84-
},
85-
promises: {
86-
...fs.promises,
87-
rmdir: async path => {
85+
const { rimrafPosix, rimrafPosixSync } = t.mock(
86+
'../dist/cjs/src/rimraf-posix.js',
87+
{
88+
'../dist/cjs/src/fs.js': {
89+
...fs,
90+
rmdirSync: path => {
8891
throw Object.assign(new Error('cannot rmdir'), { code: 'FOO' })
8992
},
93+
promises: {
94+
...fs.promises,
95+
rmdir: async path => {
96+
throw Object.assign(new Error('cannot rmdir'), { code: 'FOO' })
97+
},
98+
},
9099
},
91-
},
92-
})
100+
}
101+
)
93102
const path = t.testdir(fixture)
94103
t.throws(() => rimrafPosixSync(path, {}), { code: 'FOO' })
95104
t.rejects(rimrafPosix(path, {}), { code: 'FOO' })
96105
})
97106

98107
t.test('throw unexpected readdir errors', async t => {
99-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
100-
'../dist/cjs/src/fs.js': {
101-
...fs,
102-
readdirSync: path => {
103-
throw Object.assign(new Error('cannot readdir'), { code: 'FOO' })
104-
},
105-
promises: {
106-
...fs.promises,
107-
readdir: async path => {
108+
const { rimrafPosix, rimrafPosixSync } = t.mock(
109+
'../dist/cjs/src/rimraf-posix.js',
110+
{
111+
'../dist/cjs/src/fs.js': {
112+
...fs,
113+
readdirSync: path => {
108114
throw Object.assign(new Error('cannot readdir'), { code: 'FOO' })
109115
},
116+
promises: {
117+
...fs.promises,
118+
readdir: async path => {
119+
throw Object.assign(new Error('cannot readdir'), { code: 'FOO' })
120+
},
121+
},
110122
},
111-
},
112-
})
123+
}
124+
)
113125
const path = t.testdir(fixture)
114126
t.throws(() => rimrafPosixSync(path, {}), { code: 'FOO' })
115127
t.rejects(rimrafPosix(path, {}), { code: 'FOO' })
116128
})
117129

118130
t.test('ignore ENOENTs from unlink/rmdir', async t => {
119-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
120-
'../dist/cjs/src/fs.js': {
121-
...fs,
122-
// simulate a case where two rimrafs are happening in parallel,
123-
// so the deletion happens AFTER the readdir, but before ours.
124-
rmdirSync: path => {
125-
fs.rmdirSync(path)
126-
fs.rmdirSync(path)
127-
},
128-
unlinkSync: path => {
129-
fs.unlinkSync(path)
130-
fs.unlinkSync(path)
131-
},
132-
promises: {
133-
...fs.promises,
134-
rmdir: async path => {
131+
const { rimrafPosix, rimrafPosixSync } = t.mock(
132+
'../dist/cjs/src/rimraf-posix.js',
133+
{
134+
'../dist/cjs/src/fs.js': {
135+
...fs,
136+
// simulate a case where two rimrafs are happening in parallel,
137+
// so the deletion happens AFTER the readdir, but before ours.
138+
rmdirSync: path => {
139+
fs.rmdirSync(path)
135140
fs.rmdirSync(path)
136-
return fs.promises.rmdir(path)
137141
},
138-
unlink: async path => {
142+
unlinkSync: path => {
143+
fs.unlinkSync(path)
139144
fs.unlinkSync(path)
140-
return fs.promises.unlink(path)
145+
},
146+
promises: {
147+
...fs.promises,
148+
rmdir: async path => {
149+
fs.rmdirSync(path)
150+
return fs.promises.rmdir(path)
151+
},
152+
unlink: async path => {
153+
fs.unlinkSync(path)
154+
return fs.promises.unlink(path)
155+
},
141156
},
142157
},
143-
},
144-
})
158+
}
159+
)
145160
const { statSync } = fs
146161
t.test('sync', t => {
147162
const path = t.testdir(fixture)
@@ -161,18 +176,21 @@ t.test('ignore ENOENTs from unlink/rmdir', async t => {
161176
t.test('rimraffing root, do not actually rmdir root', async t => {
162177
let ROOT = null
163178
const { parse } = require('path')
164-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
165-
path: {
166-
...require('path'),
167-
parse: path => {
168-
const p = parse(path)
169-
if (path === ROOT) {
170-
p.root = path
171-
}
172-
return p
179+
const { rimrafPosix, rimrafPosixSync } = t.mock(
180+
'../dist/cjs/src/rimraf-posix.js',
181+
{
182+
path: {
183+
...require('path'),
184+
parse: path => {
185+
const p = parse(path)
186+
if (path === ROOT) {
187+
p.root = path
188+
}
189+
return p
190+
},
173191
},
174-
},
175-
})
192+
}
193+
)
176194
t.test('async', async t => {
177195
ROOT = t.testdir(fixture)
178196
await rimrafPosix(ROOT, { preserveRoot: false })

test/rimraf-windows.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ t.only('actually delete some stuff', async t => {
5757
// but actually do wait to clean them up, though
5858
t.teardown(() => Promise.all(danglers))
5959

60-
const { rimrafPosix, rimrafPosixSync } = t.mock('../dist/cjs/src/rimraf-posix.js', {
61-
'../dist/cjs/src/fs.js': fsMock,
62-
})
60+
const { rimrafPosix, rimrafPosixSync } = t.mock(
61+
'../dist/cjs/src/rimraf-posix.js',
62+
{
63+
'../dist/cjs/src/fs.js': fsMock,
64+
}
65+
)
6366

6467
const { rimrafWindows, rimrafWindowsSync } = t.mock(
6568
'../dist/cjs/src/rimraf-windows.js',

0 commit comments

Comments
 (0)