Compare commits

..

1 commit

Author SHA1 Message Date
726d7bf116 Fix tests for windows
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
2023-09-29 14:49:54 +00:00
3 changed files with 23 additions and 20 deletions

View file

@ -42,10 +42,7 @@ 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
@ -113,7 +110,7 @@ CLI.prototype.parseOptions = function(args) {
}
}
if (!this.targets.length && this.run === 'test') {
if (!this.targets.length) {
this.targets.push('test/**')
}

View file

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

View file

@ -59,31 +59,32 @@ 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')
})
@ -99,11 +100,13 @@ 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)
})
@ -119,54 +122,57 @@ 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 setting watch if value is missing', async function() {
t.test('should fail overriding if next parameter is missing', async function() {
cli.watch = null
let err = await assert.isRejected(cli.parseOptions(['--watch']))
assert.strictEqual(cli.watch, null)
assert.match(err.message, /watch/i)
})
t.test('should fail setting watch if value is parameter', async function() {
t.test('should fail overriding if next parameter is a parameter', async function() {
cli.watch = null
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 setting npm if value is missing', async function() {
t.test('should fail overriding if next parameter is missing', async function() {
cli.run = null
let err = await assert.isRejected(cli.parseOptions(['--npm']))
assert.strictEqual(cli.run, 'test')
assert.strictEqual(cli.run, null)
assert.match(err.message, /npm/i)
})
t.test('should fail setting npm if value is parameter', async function() {
t.test('should fail overriding if next parameter is a parameter', async function() {
cli.run = null
let err = await assert.isRejected(cli.parseOptions(['-n', '--reporter', 'list']))
assert.strictEqual(cli.run, 'test')
assert.strictEqual(cli.run, null)
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'])