diff --git a/cli_arg_parsing.test.ts b/cli_arg_parsing.test.ts index b73228c..5219975 100644 --- a/cli_arg_parsing.test.ts +++ b/cli_arg_parsing.test.ts @@ -4,20 +4,20 @@ function parseArgvInTestMode(argv: Array) { return parseArgv(argv, { outputAndExitOnError: false }) } -test.skip("rejects too many file arguments", () => { +test("rejects too many file arguments", () => { expect(() => { - parseArgv(["file1.xsc", "file2.xsc"], { outputAndExitOnError: false }) + parseArgvInTestMode(["file1.xsc", "file2.xsc"]) }).toThrow() }) -test.skip("rejects unknown format", () => { +test("rejects unknown format", () => { expect(() => { - parseArgv(["--format", "transcribe_version_999"], { outputAndExitOnError: false }) + parseArgvInTestMode(["--format", "transcribe_version_999"]) }).toThrow() }) test("accepts one file", () => { - expect(parseArgv(["some file with spaces.xsc"], { outputAndExitOnError: false })).toEqual({ + expect(parseArgvInTestMode(["some file with spaces.xsc"])).toEqual({ inputSource: { filePath: "some file with spaces.xsc", type: "file", @@ -27,14 +27,14 @@ test("accepts one file", () => { }) test("interprets no files as stdin", () => { - expect(parseArgv([], { outputAndExitOnError: false })).toEqual({ + expect(parseArgvInTestMode([])).toEqual({ inputSource: { type: "stdin" }, outputFormat: "generic", }) }) test("interprets - as stdin", () => { - expect(parseArgv(["-"], { outputAndExitOnError: false })).toEqual({ + expect(parseArgvInTestMode(["-"])).toEqual({ inputSource: { type: "stdin" }, outputFormat: "generic", }) diff --git a/cli_arg_parsing.ts b/cli_arg_parsing.ts index 071659b..7a06552 100644 --- a/cli_arg_parsing.ts +++ b/cli_arg_parsing.ts @@ -15,6 +15,10 @@ export function parseArgv( argv: Array, options: { outputAndExitOnError: boolean } = { outputAndExitOnError: true } ) { + // yargs.reset() is needed to make multiple `yargs` calls in a single program, e.g. in tests, work independently. + // That’s why I’m calling it even though the Yargs docs say it’s deprecated. The docs don’t say what to use instead. + yargs.reset() + const yargsParser = yargs .usage("$0 [option] [file]") .example("$0 myTranscribeFile.xsc", "reading input with a file argument")