diff --git a/test/parallel/test-parse-args-required-options.mjs b/test/parallel/test-parse-args-required-options.mjs deleted file mode 100644 index 05929615025531..00000000000000 --- a/test/parallel/test-parse-args-required-options.mjs +++ /dev/null @@ -1,36 +0,0 @@ -import '../common/index.mjs'; -import assert from 'node:assert'; -import { test } from 'node:test'; -import { parseArgs } from 'node:util'; - -test('required option', () => { - const args = ['--foo'] - parseArgs({ - strict: true, - args, - options: { - foo: { - type: 'boolean', - required: true - } - } - }) -}) - -test('required option fail', () => { - const args = [] - assert.throws(() => { - parseArgs({ - strict: true, - args, - options: { - foo: { - type: 'boolean', - required: true - } - } - }, { - code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE' - }) - }) -}) diff --git a/test/parallel/test-parse-args.mjs b/test/parallel/test-parse-args.mjs index 98cf9403743a41..6bd67dca8743bd 100644 --- a/test/parallel/test-parse-args.mjs +++ b/test/parallel/test-parse-args.mjs @@ -823,3 +823,78 @@ test('tokens: strict:false with -- --', () => { const { tokens } = parseArgs({ strict: false, args, tokens: true }); assert.deepStrictEqual(tokens, expectedTokens); }); + +test('strict: required option', () => { + const args = ['--foo'] + parseArgs({ + args, + options: { + foo: { + type: 'boolean', + required: true + } + } + }) +}) + +test('required option', () => { + const args = ['--foo', '--goo'] + parseArgs({ + strict: false, + args, + options: { + foo: { + type: 'boolean', + required: true + } + } + }) +}) + +test('strict: false required option fail', () => { + const args = [] + assert.throws(() => { + parseArgs({ + strict: false, + args, + options: { + foo: { + type: 'boolean', + required: true + } + } + }, { + code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE' + }) + }) +}) + +test('strict: no input but has required option', () => { + const args = [] + assert.throws(() => { + parseArgs({ + args, + options: { + foo: { + type: 'boolean', + required: true + } + } + }, { + code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE' + }) + }) +}) + +test('strict: no input and no required option', () => { + const args = [] + parseArgs({ + args, + options: { + foo: { + type: 'boolean', + required: false + } + } + }) +})