Skip to content

Commit 5ba57da

Browse files
committed
fixup! refactor: test cases
1 parent 5e8a76e commit 5ba57da

File tree

2 files changed

+75
-36
lines changed

2 files changed

+75
-36
lines changed

test/parallel/test-parse-args-required-options.mjs

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/parallel/test-parse-args.mjs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,78 @@ test('tokens: strict:false with -- --', () => {
823823
const { tokens } = parseArgs({ strict: false, args, tokens: true });
824824
assert.deepStrictEqual(tokens, expectedTokens);
825825
});
826+
827+
test('strict: required option', () => {
828+
const args = ['--foo']
829+
parseArgs({
830+
args,
831+
options: {
832+
foo: {
833+
type: 'boolean',
834+
required: true
835+
}
836+
}
837+
})
838+
})
839+
840+
test('required option', () => {
841+
const args = ['--foo', '--goo']
842+
parseArgs({
843+
strict: false,
844+
args,
845+
options: {
846+
foo: {
847+
type: 'boolean',
848+
required: true
849+
}
850+
}
851+
})
852+
})
853+
854+
test('strict: false required option fail', () => {
855+
const args = []
856+
assert.throws(() => {
857+
parseArgs({
858+
strict: false,
859+
args,
860+
options: {
861+
foo: {
862+
type: 'boolean',
863+
required: true
864+
}
865+
}
866+
}, {
867+
code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE'
868+
})
869+
})
870+
})
871+
872+
test('strict: no input but has required option', () => {
873+
const args = []
874+
assert.throws(() => {
875+
parseArgs({
876+
args,
877+
options: {
878+
foo: {
879+
type: 'boolean',
880+
required: true
881+
}
882+
}
883+
}, {
884+
code: 'ERR_PARSE_ARGS_REQUIRED_OPTION_VALUE'
885+
})
886+
})
887+
})
888+
889+
test('strict: no input and no required option', () => {
890+
const args = []
891+
parseArgs({
892+
args,
893+
options: {
894+
foo: {
895+
type: 'boolean',
896+
required: false
897+
}
898+
}
899+
})
900+
})

0 commit comments

Comments
 (0)