Cli no longer throws if eltro is only being used for npm-watching and not testing

master
TheThing 2023-10-31 08:29:51 +00:00
parent b0874cfaa1
commit feac2678bd
3 changed files with 20 additions and 23 deletions

View File

@ -42,7 +42,10 @@ export function CLI(e, overrides = {}) {
this.child_process = overrides.child_process || child_process
this.process = overrides.process || process
this.importer = overrides.importer
this.loadDefaults()
}
CLI.prototype.loadDefaults = function() {
// Eltro specific options
this.reporter = 'list'
this.ignoreOnly = false
@ -110,7 +113,7 @@ CLI.prototype.parseOptions = function(args) {
}
}
if (!this.targets.length) {
if (!this.targets.length && this.run === 'test') {
this.targets.push('test/**')
}

View File

@ -1,6 +1,6 @@
{
"name": "eltro",
"version": "1.4.0",
"version": "1.4.1",
"description": "Eltro is a tiny no-dependancy test framework for node",
"main": "index.mjs",
"scripts": {

View File

@ -59,32 +59,31 @@ t.describe('CLI', function() {
*****************************************/
t.describe('#parseOptions()', function() {
t.beforeEach(function() {
cli.loadDefaults()
})
t.test('should not do anything if no options', async function() {
cli.reporter = 'list'
await cli.parseOptions([])
assert.strictEqual(cli.reporter, 'list')
})
t.test('should support overriding reporter with shorthand option', async function() {
cli.reporter = 'list'
await cli.parseOptions(['-r', 'dot'])
assert.strictEqual(cli.reporter, 'dot')
})
t.test('should support overriding reporter with long option', async function() {
cli.reporter = 'list'
await cli.parseOptions(['--reporter', 'dot'])
assert.strictEqual(cli.reporter, 'dot')
})
t.test('should support enabling ignore-only long option', async function() {
cli.ignoreOnly = false
await cli.parseOptions(['--ignore-only', '-r', 'dot'])
assert.strictEqual(cli.ignoreOnly, true)
})
t.test('should support reporter list', async function() {
cli.reporter = 'list'
await cli.parseOptions(['-r', 'list'])
assert.strictEqual(cli.reporter, 'list')
})
@ -100,13 +99,11 @@ t.describe('CLI', function() {
})
t.test('should support overriding timeout with shorthand option', async function() {
cli.timeout = 2000
await cli.parseOptions(['-t', '1000'])
assert.strictEqual(cli.timeout, 1000)
})
t.test('should support overriding timeout with long option', async function() {
cli.timeout = 2000
await cli.parseOptions(['--timeout', '250'])
assert.strictEqual(cli.timeout, 250)
})
@ -122,57 +119,54 @@ t.describe('CLI', function() {
})
t.test('should support overriding watch', async function() {
cli.watch = null
await cli.parseOptions(['-w', 'unittest_test1'])
assert.strictEqual(cli.watch, 'unittest_test1')
})
t.test('should support overriding watch with long option', async function() {
cli.watch = null
await cli.parseOptions(['--watch', 'unittest_test1'])
assert.strictEqual(cli.watch, 'unittest_test1')
})
t.test('should fail overriding if next parameter is missing', async function() {
cli.watch = null
t.test('should fail setting watch if value is missing', async function() {
let err = await assert.isRejected(cli.parseOptions(['--watch']))
assert.strictEqual(cli.watch, null)
assert.match(err.message, /watch/i)
})
t.test('should fail overriding if next parameter is a parameter', async function() {
cli.watch = null
t.test('should fail setting watch if value is parameter', async function() {
let err = await assert.isRejected(cli.parseOptions(['-w', '--reporter', 'list']))
assert.strictEqual(cli.watch, null)
assert.match(err.message, /watch/i)
})
t.test('should support overriding run', async function() {
cli.run = null
await cli.parseOptions(['-n', 'unittest_run1'])
assert.strictEqual(cli.run, 'unittest_run1')
})
t.test('should support overriding run with long option', async function() {
cli.run = null
await cli.parseOptions(['--npm', 'unittest_run1'])
assert.strictEqual(cli.run, 'unittest_run1')
})
t.test('should fail overriding if next parameter is missing', async function() {
cli.run = null
t.test('should fail setting npm if value is missing', async function() {
let err = await assert.isRejected(cli.parseOptions(['--npm']))
assert.strictEqual(cli.run, null)
assert.strictEqual(cli.run, 'test')
assert.match(err.message, /npm/i)
})
t.test('should fail overriding if next parameter is a parameter', async function() {
cli.run = null
t.test('should fail setting npm if value is parameter', async function() {
let err = await assert.isRejected(cli.parseOptions(['-n', '--reporter', 'list']))
assert.strictEqual(cli.run, null)
assert.strictEqual(cli.run, 'test')
assert.match(err.message, /npm/i)
})
t.test('when using run and no target, leave target empty', async function() {
await cli.parseOptions(['--npm', 'unittest_run1'])
assert.strictEqual(cli.targets.length, 0)
})
t.test('should add file to targets', async function() {
await cli.parseOptions(['test'])
assert.deepEqual(cli.targets, ['test'])