Cli no longer throws if eltro is only being used for npm-watching and not testing
This commit is contained in:
parent
b0874cfaa1
commit
feac2678bd
3 changed files with 20 additions and 23 deletions
|
@ -42,7 +42,10 @@ export function CLI(e, overrides = {}) {
|
||||||
this.child_process = overrides.child_process || child_process
|
this.child_process = overrides.child_process || child_process
|
||||||
this.process = overrides.process || process
|
this.process = overrides.process || process
|
||||||
this.importer = overrides.importer
|
this.importer = overrides.importer
|
||||||
|
this.loadDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
CLI.prototype.loadDefaults = function() {
|
||||||
// Eltro specific options
|
// Eltro specific options
|
||||||
this.reporter = 'list'
|
this.reporter = 'list'
|
||||||
this.ignoreOnly = false
|
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/**')
|
this.targets.push('test/**')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "eltro",
|
"name": "eltro",
|
||||||
"version": "1.4.0",
|
"version": "1.4.1",
|
||||||
"description": "Eltro is a tiny no-dependancy test framework for node",
|
"description": "Eltro is a tiny no-dependancy test framework for node",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -59,32 +59,31 @@ t.describe('CLI', function() {
|
||||||
*****************************************/
|
*****************************************/
|
||||||
|
|
||||||
t.describe('#parseOptions()', function() {
|
t.describe('#parseOptions()', function() {
|
||||||
|
t.beforeEach(function() {
|
||||||
|
cli.loadDefaults()
|
||||||
|
})
|
||||||
|
|
||||||
t.test('should not do anything if no options', async function() {
|
t.test('should not do anything if no options', async function() {
|
||||||
cli.reporter = 'list'
|
|
||||||
await cli.parseOptions([])
|
await cli.parseOptions([])
|
||||||
assert.strictEqual(cli.reporter, 'list')
|
assert.strictEqual(cli.reporter, 'list')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding reporter with shorthand option', async function() {
|
t.test('should support overriding reporter with shorthand option', async function() {
|
||||||
cli.reporter = 'list'
|
|
||||||
await cli.parseOptions(['-r', 'dot'])
|
await cli.parseOptions(['-r', 'dot'])
|
||||||
assert.strictEqual(cli.reporter, 'dot')
|
assert.strictEqual(cli.reporter, 'dot')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding reporter with long option', async function() {
|
t.test('should support overriding reporter with long option', async function() {
|
||||||
cli.reporter = 'list'
|
|
||||||
await cli.parseOptions(['--reporter', 'dot'])
|
await cli.parseOptions(['--reporter', 'dot'])
|
||||||
assert.strictEqual(cli.reporter, 'dot')
|
assert.strictEqual(cli.reporter, 'dot')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support enabling ignore-only long option', async function() {
|
t.test('should support enabling ignore-only long option', async function() {
|
||||||
cli.ignoreOnly = false
|
|
||||||
await cli.parseOptions(['--ignore-only', '-r', 'dot'])
|
await cli.parseOptions(['--ignore-only', '-r', 'dot'])
|
||||||
assert.strictEqual(cli.ignoreOnly, true)
|
assert.strictEqual(cli.ignoreOnly, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support reporter list', async function() {
|
t.test('should support reporter list', async function() {
|
||||||
cli.reporter = 'list'
|
|
||||||
await cli.parseOptions(['-r', 'list'])
|
await cli.parseOptions(['-r', 'list'])
|
||||||
assert.strictEqual(cli.reporter, '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() {
|
t.test('should support overriding timeout with shorthand option', async function() {
|
||||||
cli.timeout = 2000
|
|
||||||
await cli.parseOptions(['-t', '1000'])
|
await cli.parseOptions(['-t', '1000'])
|
||||||
assert.strictEqual(cli.timeout, 1000)
|
assert.strictEqual(cli.timeout, 1000)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding timeout with long option', async function() {
|
t.test('should support overriding timeout with long option', async function() {
|
||||||
cli.timeout = 2000
|
|
||||||
await cli.parseOptions(['--timeout', '250'])
|
await cli.parseOptions(['--timeout', '250'])
|
||||||
assert.strictEqual(cli.timeout, 250)
|
assert.strictEqual(cli.timeout, 250)
|
||||||
})
|
})
|
||||||
|
@ -122,57 +119,54 @@ t.describe('CLI', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding watch', async function() {
|
t.test('should support overriding watch', async function() {
|
||||||
cli.watch = null
|
|
||||||
await cli.parseOptions(['-w', 'unittest_test1'])
|
await cli.parseOptions(['-w', 'unittest_test1'])
|
||||||
assert.strictEqual(cli.watch, 'unittest_test1')
|
assert.strictEqual(cli.watch, 'unittest_test1')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding watch with long option', async function() {
|
t.test('should support overriding watch with long option', async function() {
|
||||||
cli.watch = null
|
|
||||||
await cli.parseOptions(['--watch', 'unittest_test1'])
|
await cli.parseOptions(['--watch', 'unittest_test1'])
|
||||||
assert.strictEqual(cli.watch, 'unittest_test1')
|
assert.strictEqual(cli.watch, 'unittest_test1')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail overriding if next parameter is missing', async function() {
|
t.test('should fail setting watch if value is missing', async function() {
|
||||||
cli.watch = null
|
|
||||||
let err = await assert.isRejected(cli.parseOptions(['--watch']))
|
let err = await assert.isRejected(cli.parseOptions(['--watch']))
|
||||||
assert.strictEqual(cli.watch, null)
|
assert.strictEqual(cli.watch, null)
|
||||||
assert.match(err.message, /watch/i)
|
assert.match(err.message, /watch/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail overriding if next parameter is a parameter', async function() {
|
t.test('should fail setting watch if value is parameter', async function() {
|
||||||
cli.watch = null
|
|
||||||
let err = await assert.isRejected(cli.parseOptions(['-w', '--reporter', 'list']))
|
let err = await assert.isRejected(cli.parseOptions(['-w', '--reporter', 'list']))
|
||||||
assert.strictEqual(cli.watch, null)
|
assert.strictEqual(cli.watch, null)
|
||||||
assert.match(err.message, /watch/i)
|
assert.match(err.message, /watch/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding run', async function() {
|
t.test('should support overriding run', async function() {
|
||||||
cli.run = null
|
|
||||||
await cli.parseOptions(['-n', 'unittest_run1'])
|
await cli.parseOptions(['-n', 'unittest_run1'])
|
||||||
assert.strictEqual(cli.run, 'unittest_run1')
|
assert.strictEqual(cli.run, 'unittest_run1')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should support overriding run with long option', async function() {
|
t.test('should support overriding run with long option', async function() {
|
||||||
cli.run = null
|
|
||||||
await cli.parseOptions(['--npm', 'unittest_run1'])
|
await cli.parseOptions(['--npm', 'unittest_run1'])
|
||||||
assert.strictEqual(cli.run, 'unittest_run1')
|
assert.strictEqual(cli.run, 'unittest_run1')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail overriding if next parameter is missing', async function() {
|
t.test('should fail setting npm if value is missing', async function() {
|
||||||
cli.run = null
|
|
||||||
let err = await assert.isRejected(cli.parseOptions(['--npm']))
|
let err = await assert.isRejected(cli.parseOptions(['--npm']))
|
||||||
assert.strictEqual(cli.run, null)
|
assert.strictEqual(cli.run, 'test')
|
||||||
assert.match(err.message, /npm/i)
|
assert.match(err.message, /npm/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail overriding if next parameter is a parameter', async function() {
|
t.test('should fail setting npm if value is parameter', async function() {
|
||||||
cli.run = null
|
|
||||||
let err = await assert.isRejected(cli.parseOptions(['-n', '--reporter', 'list']))
|
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)
|
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() {
|
t.test('should add file to targets', async function() {
|
||||||
await cli.parseOptions(['test'])
|
await cli.parseOptions(['test'])
|
||||||
assert.deepEqual(cli.targets, ['test'])
|
assert.deepEqual(cli.targets, ['test'])
|
||||||
|
|
Loading…
Reference in a new issue