Skip to content

Commit

Permalink
runner test for --only
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored and isaacs committed Jun 25, 2017
1 parent 7550694 commit 0d0ac05
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/fixtures/only.js
@@ -0,0 +1,25 @@
var test = require('../..').test

test('root test without {only: true}', function (t) {
t.pass('test will not run without --only')
t.end()
})

test('root test with {only: true}', {only: true}, function (t) {
t.pass('test will log an error when run without --only')
t.end()
})

test('group', function (group) {
group.test('subtest without {only: true}', function (t) {
t.pass('subtest will not run without --only')
t.end()
})

group.test('subtest with {only: true}', {only: true}, function (t) {
t.pass('test will log an error when run without --only')
t.end()
})

group.end()
})
43 changes: 43 additions & 0 deletions test/runner-only.js
@@ -0,0 +1,43 @@
var t = require('../')
var execFile = require('child_process').execFile
var node = process.execPath
var run = require.resolve('../bin/run.js')

t.test('--only flag', function (t) {
var file = require.resolve('./fixtures/only.js')
var args = [
run,
'--only',
file
]

execFile(node, args, function (err, stdout, stderr) {
if (err) {
throw err
}

t.equal(stderr, '')

t.match(stdout, /^ok 1 - .*[\\\/]only.js/m)
t.end()
})
})

t.test('{only: true} without --only flag', function (t) {
var file = require.resolve('./fixtures/only.js')
var args = [
run,
file
]

execFile(node, args, function (err, stdout, stderr) {
if (err) {
throw err
}

t.equal(stderr.trim(), '# Warning: "only" has {only: true} set but all tests are run')

t.match(stdout, /^ok 1 - .*[\\\/]only.js/m)
t.end()
})
})

0 comments on commit 0d0ac05

Please sign in to comment.