Skip to content

Commit c72278a

Browse files
lukekarrysisaacs
authored andcommitted
Use tap.intercept to test bin
This removes the need for checking test only environs in the bin script.
1 parent 549d1e8 commit c72278a

2 files changed

Lines changed: 147 additions & 166 deletions

File tree

src/bin.mts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#!/usr/bin/env node
22
import type { RimrafAsyncOptions } from './index.js'
33
import { rimraf } from './index.js'
4-
54
import { loadPackageJson } from 'package-json-from-dist'
65

7-
const { version } = loadPackageJson(import.meta.url, '../package.json')
6+
const { version } = loadPackageJson(import.meta.url, '../package.json') as {
7+
version: string
8+
}
89

910
const runHelpForUsage = () =>
1011
console.error('run `rimraf --help` for usage information')
1112

12-
export const help = `rimraf version ${version}
13+
const help = `rimraf version ${version}
1314
1415
Usage: rimraf <path> [<path> ...]
1516
Deletes all files and folders at "path", recursively.
@@ -84,7 +85,7 @@ const interactiveRimraf = async (
8485
return result
8586
})
8687
})
87-
processQueue()
88+
void processQueue()
8889
return p
8990
}
9091
const rl = createInterface({
@@ -127,10 +128,6 @@ const main = async (...args: string[]) => {
127128
return true
128129
}
129130

130-
if (process.env.__RIMRAF_TESTING_BIN_FAIL__ === '1') {
131-
throw new Error('simulated rimraf failure')
132-
}
133-
134131
const opt: RimrafAsyncOptions = {}
135132
const paths: string[] = []
136133
let dashdash = false
@@ -257,18 +254,11 @@ const main = async (...args: string[]) => {
257254

258255
return 0
259256
}
260-
main.help = help
261-
main.version = version
262257

263-
export default main
264-
265-
if (process.env.__TESTING_RIMRAF_BIN__ !== '1') {
266-
const args = process.argv.slice(2)
267-
main(...args).then(
268-
code => process.exit(code),
269-
er => {
270-
console.error(er)
271-
process.exit(1)
272-
},
273-
)
274-
}
258+
main(...process.argv.slice(2)).then(
259+
code => process.exit(code),
260+
er => {
261+
console.error(er)
262+
process.exit(1)
263+
},
264+
)

0 commit comments

Comments
 (0)