UNPKG

1.44 kBJavaScriptView Raw
1'use strict'
2const TestRunner = require('test-runner')
3const commandLineArgs = require('../')
4const a = require('assert')
5
6const runner = new TestRunner()
7
8runner.test('type-other: different values', function () {
9 const definitions = [
10 {
11 name: 'file',
12 type: function (file) {
13 return file
14 }
15 }
16 ]
17
18 a.deepStrictEqual(
19 commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] }),
20 { file: 'one.js' }
21 )
22 a.deepStrictEqual(
23 commandLineArgs(definitions, { argv: [ '--file' ] }),
24 { file: null }
25 )
26})
27
28runner.test('type-other: broken custom type function', function () {
29 const definitions = [
30 {
31 name: 'file',
32 type: function (file) {
33 lasdfjsfakn // eslint-disable-line
34 }
35 }
36 ]
37 a.throws(function () {
38 commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] })
39 })
40})
41
42runner.test('type-other-multiple: different values', function () {
43 const definitions = [
44 {
45 name: 'file',
46 multiple: true,
47 type: function (file) {
48 return file
49 }
50 }
51 ]
52
53 a.deepStrictEqual(
54 commandLineArgs(definitions, { argv: [ '--file', 'one.js' ] }),
55 { file: [ 'one.js' ] }
56 )
57 a.deepStrictEqual(
58 commandLineArgs(definitions, { argv: [ '--file', 'one.js', 'two.js' ] }),
59 { file: [ 'one.js', 'two.js' ] }
60 )
61 a.deepStrictEqual(
62 commandLineArgs(definitions, { argv: [ '--file' ] }),
63 { file: [] }
64 )
65})