Skip to content

Commit

Permalink
update tests for jest
Browse files Browse the repository at this point in the history
  • Loading branch information
zanerock committed Jul 3, 2024
1 parent ae5f0d3 commit 741f39c
Show file tree
Hide file tree
Showing 33 changed files with 352 additions and 482 deletions.
417 changes: 176 additions & 241 deletions dist/tests.js

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions test/alias-cluster.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('alias-cluster: two flags, one option', function () {
test('alias-cluster: two flags, one option', function () {
const optionDefinitions = [
{ name: 'flagA', alias: 'a', type: Boolean },
{ name: 'flagB', alias: 'b', type: Boolean },
Expand All @@ -19,7 +16,7 @@ runner.test('alias-cluster: two flags, one option', function () {
})
})

runner.test('alias-cluster: two flags, one option 2', function () {
test('alias-cluster: two flags, one option 2', function () {
const optionDefinitions = [
{ name: 'flagA', alias: 'a', type: Boolean },
{ name: 'flagB', alias: 'b', type: Boolean },
Expand All @@ -34,7 +31,7 @@ runner.test('alias-cluster: two flags, one option 2', function () {
})
})

runner.test('alias-cluster: three string options', function () {
test('alias-cluster: three string options', function () {
const optionDefinitions = [
{ name: 'flagA', alias: 'a' },
{ name: 'flagB', alias: 'b' },
Expand Down
8 changes: 3 additions & 5 deletions test/alias.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('alias: one string alias', function () {
test('alias: one string alias', function () {
const optionDefinitions = [
{ name: 'verbose', alias: 'v' }
]
Expand All @@ -14,7 +12,7 @@ runner.test('alias: one string alias', function () {
})
})

runner.test('alias: one boolean alias', function () {
test('alias: one boolean alias', function () {
const optionDefinitions = [
{ name: 'dry-run', alias: 'd', type: Boolean }
]
Expand All @@ -24,7 +22,7 @@ runner.test('alias: one boolean alias', function () {
})
})

runner.test('alias: one boolean, one string', function () {
test('alias: one boolean, one string', function () {
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'colour', alias: 'c' }
Expand Down
10 changes: 4 additions & 6 deletions test/ambiguous-input.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('ambiguous input: value looks like an option 1', function () {
test('ambiguous input: value looks like an option 1', function () {
const optionDefinitions = [
{ name: 'colour', type: String, alias: 'c' }
]
Expand All @@ -13,7 +11,7 @@ runner.test('ambiguous input: value looks like an option 1', function () {
})
})

runner.test('ambiguous input: value looks like an option 2', function () {
test('ambiguous input: value looks like an option 2', function () {
const optionDefinitions = [
{ name: 'colour', type: String, alias: 'c' }
]
Expand All @@ -24,7 +22,7 @@ runner.test('ambiguous input: value looks like an option 2', function () {
)
})

runner.test('ambiguous input: value looks like an option 3', function () {
test('ambiguous input: value looks like an option 3', function () {
const optionDefinitions = [
{ name: 'colour', type: String, alias: 'c' }
]
Expand All @@ -33,7 +31,7 @@ runner.test('ambiguous input: value looks like an option 3', function () {
})
})

runner.test('ambiguous input: value looks like an option 4', function () {
test('ambiguous input: value looks like an option 4', function () {
const optionDefinitions = [
{ name: 'colour', type: String, alias: 'c' }
]
Expand Down
10 changes: 4 additions & 6 deletions test/bad-input.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('bad-input: missing option value should be null', function () {
test('bad-input: missing option value should be null', function () {
const optionDefinitions = [
{ name: 'colour', type: String },
{ name: 'files' }
Expand All @@ -18,7 +16,7 @@ runner.test('bad-input: missing option value should be null', function () {
})
})

runner.test('bad-input: handles arrays with relative paths', function () {
test('bad-input: handles arrays with relative paths', function () {
const optionDefinitions = [
{ name: 'colours', type: String, multiple: true }
]
Expand All @@ -28,7 +26,7 @@ runner.test('bad-input: handles arrays with relative paths', function () {
})
})

runner.test('bad-input: empty string added to unknown values', function () {
test('bad-input: empty string added to unknown values', function () {
const optionDefinitions = [
{ name: 'one', type: String },
{ name: 'two', type: Number },
Expand All @@ -50,7 +48,7 @@ runner.test('bad-input: empty string added to unknown values', function () {
})
})

runner.test('bad-input: non-strings in argv', function () {
test('bad-input: non-strings in argv', function () {
const optionDefinitions = [
{ name: 'one', type: Number }
]
Expand Down
8 changes: 3 additions & 5 deletions test/camel-case.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('camel-case: regular', function () {
test('camel-case: regular', function () {
const optionDefinitions = [
{ name: 'one-two' },
{ name: 'three', type: Boolean }
Expand All @@ -17,7 +15,7 @@ runner.test('camel-case: regular', function () {
})
})

runner.test('camel-case: grouped', function () {
test('camel-case: grouped', function () {
const optionDefinitions = [
{ name: 'one-one', group: 'a' },
{ name: 'two-two', group: 'a' },
Expand Down Expand Up @@ -46,7 +44,7 @@ runner.test('camel-case: grouped', function () {
})
})

runner.test('camel-case: grouped with unknowns', function () {
test('camel-case: grouped with unknowns', function () {
const optionDefinitions = [
{ name: 'one-one', group: 'a' },
{ name: 'two-two', group: 'a' },
Expand Down
14 changes: 6 additions & 8 deletions test/case-insensitive.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('case-insensitive: disabled', function () {
test('case-insensitive: disabled', function () {
const optionDefinitions = [
{ name: 'dryRun', type: Boolean, alias: 'd' }]

Expand All @@ -18,7 +16,7 @@ runner.test('case-insensitive: disabled', function () {
)
})

runner.test('case-insensitive: option no value', function () {
test('case-insensitive: option no value', function () {
const optionDefinitions = [
{ name: 'dryRun', type: Boolean }]
const argv = ['--DRYrun']
Expand All @@ -28,7 +26,7 @@ runner.test('case-insensitive: option no value', function () {
})
})

runner.test('case-insensitive: option with value', function () {
test('case-insensitive: option with value', function () {
const optionDefinitions = [
{ name: 'colour', type: String }
]
Expand All @@ -39,7 +37,7 @@ runner.test('case-insensitive: option with value', function () {
})
})

runner.test('case-insensitive: alias', function () {
test('case-insensitive: alias', function () {
const optionDefinitions = [
{ name: 'dryRun', type: Boolean, alias: 'd' }]
const argv = ['-D']
Expand All @@ -49,7 +47,7 @@ runner.test('case-insensitive: alias', function () {
})
})

runner.test('case-insensitive: multiple', function () {
test('case-insensitive: multiple', function () {
const optionDefinitions = [
{ name: 'colour', type: String, multiple: true }
]
Expand All @@ -60,7 +58,7 @@ runner.test('case-insensitive: multiple', function () {
})
})

runner.test('case-insensitive: camelCase', function () {
test('case-insensitive: camelCase', function () {
const optionDefinitions = [
{ name: 'dry-run', type: Boolean }
]
Expand Down
12 changes: 5 additions & 7 deletions test/default-option.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('defaultOption: multiple string', function () {
test('defaultOption: multiple string', function () {
const optionDefinitions = [
{ name: 'files', defaultOption: true, multiple: true }
]
Expand All @@ -14,7 +12,7 @@ runner.test('defaultOption: multiple string', function () {
})
})

runner.test('defaultOption: after a boolean', function () {
test('defaultOption: after a boolean', function () {
const definitions = [
{ name: 'one', type: Boolean },
{ name: 'two', defaultOption: true }
Expand All @@ -25,7 +23,7 @@ runner.test('defaultOption: after a boolean', function () {
)
})

runner.test('defaultOption: multiple-defaultOption values spread out', function () {
test('defaultOption: multiple-defaultOption values spread out', function () {
const optionDefinitions = [
{ name: 'one' },
{ name: 'two' },
Expand All @@ -39,7 +37,7 @@ runner.test('defaultOption: multiple-defaultOption values spread out', function
})
})

runner.test('defaultOption: can be false', function () {
test('defaultOption: can be false', function () {
const optionDefinitions = [
{ name: 'one', defaultOption: false },
{ name: 'two', defaultOption: false },
Expand All @@ -53,7 +51,7 @@ runner.test('defaultOption: can be false', function () {
})
})

runner.test('defaultOption: multiple-defaultOption values spread out 2', function () {
test('defaultOption: multiple-defaultOption values spread out 2', function () {
const optionDefinitions = [
{ name: 'one', type: Boolean },
{ name: 'two' },
Expand Down
24 changes: 11 additions & 13 deletions test/default-value.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('default value', function () {
test('default value', function () {
const defs = [
{ name: 'one' },
{ name: 'two', defaultValue: 'two' }
Expand All @@ -16,25 +14,25 @@ runner.test('default value', function () {
})
})

runner.test('default value 2', function () {
test('default value 2', function () {
const defs = [{ name: 'two', defaultValue: 'two' }]
const argv = []
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'two' })
})

runner.test('default value 3', function () {
test('default value 3', function () {
const defs = [{ name: 'two', defaultValue: 'two' }]
const argv = ['--two', 'zwei']
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: 'zwei' })
})

runner.test('default value 4', function () {
test('default value 4', function () {
const defs = [{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'] }]
const argv = ['--two', 'duo']
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: ['duo'] })
})

runner.test('default value 5', function () {
test('default value 5', function () {
const defs = [
{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'] }
]
Expand All @@ -43,15 +41,15 @@ runner.test('default value 5', function () {
a.deepStrictEqual(result, { two: ['two', 'zwei'] })
})

runner.test('default value: array as defaultOption', function () {
test('default value: array as defaultOption', function () {
const defs = [
{ name: 'two', multiple: true, defaultValue: ['two', 'zwei'], defaultOption: true }
]
const argv = ['duo']
a.deepStrictEqual(commandLineArgs(defs, { argv }), { two: ['duo'] })
})

runner.test('default value: falsy default values', function () {
test('default value: falsy default values', function () {
const defs = [
{ name: 'one', defaultValue: 0 },
{ name: 'two', defaultValue: false }
Expand All @@ -64,7 +62,7 @@ runner.test('default value: falsy default values', function () {
})
})

runner.test('default value: is arrayifed if multiple set', function () {
test('default value: is arrayifed if multiple set', function () {
const defs = [
{ name: 'one', defaultValue: 0, multiple: true }
]
Expand All @@ -79,7 +77,7 @@ runner.test('default value: is arrayifed if multiple set', function () {
})
})

runner.test('default value: combined with defaultOption', function () {
test('default value: combined with defaultOption', function () {
const defs = [
{ name: 'path', defaultOption: true, defaultValue: './' }
]
Expand All @@ -98,7 +96,7 @@ runner.test('default value: combined with defaultOption', function () {
})
})

runner.test('default value: combined with multiple and defaultOption', function () {
test('default value: combined with multiple and defaultOption', function () {
const defs = [
{ name: 'path', multiple: true, defaultOption: true, defaultValue: './' }
]
Expand All @@ -125,7 +123,7 @@ runner.test('default value: combined with multiple and defaultOption', function
})
})

runner.test('default value: array default combined with multiple and defaultOption', function () {
test('default value: array default combined with multiple and defaultOption', function () {
const defs = [
{ name: 'path', multiple: true, defaultOption: true, defaultValue: ['./'] }
]
Expand Down
8 changes: 3 additions & 5 deletions test/detect-process-argv.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import TestRunner from 'test-runner'
import commandLineArgs from '../index.mjs'
import a from 'assert'

const runner = new TestRunner()

runner.test('detect process.argv: should automatically remove first two argv items', function () {
test('detect process.argv: should automatically remove first two argv items', function () {
process.argv = ['node', 'filename', '--one', 'eins']
a.deepStrictEqual(commandLineArgs({ name: 'one' }), {
one: 'eins'
})
})

runner.test('detect process.argv: should automatically remove first two argv items 2', function () {
test('detect process.argv: should automatically remove first two argv items 2', function () {
process.argv = ['node', 'filename', '--one', 'eins']
a.deepStrictEqual(commandLineArgs({ name: 'one' }, { argv: process.argv }), {
one: 'eins'
})
})

runner.test('process.argv is left untouched', function () {
test('process.argv is left untouched', function () {
process.argv = ['node', 'filename', '--one', 'eins']
a.deepStrictEqual(commandLineArgs({ name: 'one' }), {
one: 'eins'
Expand Down
Loading

0 comments on commit 741f39c

Please sign in to comment.