44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { parseCliArguments } from '#import-recipes/cli/parseCliArguments.js'
|
|
|
|
test('defaults to out/, no limit, no dry run', () => {
|
|
assert.deepEqual(parseCliArguments(['--source', 'recettes']), {
|
|
source: 'recettes',
|
|
out: 'out',
|
|
dryRun: false,
|
|
limit: null,
|
|
problems: []
|
|
})
|
|
})
|
|
|
|
test('reads every option', () => {
|
|
const options = parseCliArguments(['--source', 'recettes', '--out', 'build', '--dry-run', '--limit', '3'])
|
|
assert.equal(options.source, 'recettes')
|
|
assert.equal(options.out, 'build')
|
|
assert.equal(options.dryRun, true)
|
|
assert.equal(options.limit, 3)
|
|
assert.deepEqual(options.problems, [])
|
|
})
|
|
|
|
test('reports a flag left without a value', () => {
|
|
assert.deepEqual(parseCliArguments(['--source']).problems, ['--source needs a value'])
|
|
assert.deepEqual(parseCliArguments(['--source', '--dry-run']).problems, ['--source needs a value'])
|
|
})
|
|
|
|
test('reports a limit that is not a positive whole number', () => {
|
|
assert.deepEqual(parseCliArguments(['--limit', 'deux']).problems, ['--limit needs a positive whole number'])
|
|
assert.deepEqual(parseCliArguments(['--limit', '0']).problems, ['--limit needs a positive whole number'])
|
|
})
|
|
|
|
// A mistyped flag that silently does nothing would cost a full run.
|
|
test('reports an argument it does not know', () => {
|
|
assert.deepEqual(parseCliArguments(['--dryrun']).problems, ['unknown argument: --dryrun'])
|
|
assert.deepEqual(parseCliArguments(['recettes']).problems, ['unknown argument: recettes'])
|
|
})
|
|
|
|
test('reads no argument at all', () => {
|
|
const options = parseCliArguments([])
|
|
assert.equal(options.source, null)
|
|
assert.deepEqual(options.problems, [])
|
|
})
|