Skip to content

Commit

Permalink
Remove execa
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 1, 2020
1 parent 57b20d5 commit c2e75cd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 53 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
},
"devDependencies": {
"browserify": "^16.0.0",
"execa": "^2.0.0",
"nyc": "^15.0.0",
"prettier": "^1.0.0",
"remark-cli": "^7.0.0",
Expand Down
93 changes: 41 additions & 52 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

var Stream = require('stream').PassThrough
var exec = require('child_process').exec
var PassThrough = require('stream').PassThrough
var test = require('tape')
var execa = require('execa')
var pack = require('../package.json')
var version = require('../package.json').version
var fixtures = require('./fixture.json')
var syllable = require('..')

Expand Down Expand Up @@ -70,65 +70,54 @@ test('api', function(t) {
})

test('cli', function(t) {
var help = ['-h', '--help']
var version = ['-v', '--version']
var stream

t.plan(10)

execa('./cli.js', ['syllables']).then(function(result) {
t.equal(result.stdout, '3', 'Should accept an argument')
}, t.ifErr)

execa('./cli.js', ['syllables', 'unicorns']).then(function(result) {
t.equal(result.stdout, '6', 'Should accept arguments')
}, t.ifErr)

execa('./cli.js', ['syllables unicorns']).then(function(result) {
t.equal(result.stdout, '6', 'Should accept values')
}, t.ifErr)

execa('./cli.js', [' ']).then(
function() {},
function(error) {
t.equal(error.exitCode, 1, 'should exit with `1` without input')
t.ok(
/\s*Usage: syllable \[options] <words...>/.test(error.stderr),
'Should emit the help message'
)
}
)
var input = new PassThrough()
var helps = ['-h', '--help']
var versions = ['-v', '--version']

help.forEach(function(flag) {
execa('./cli.js', [flag]).then(function(result) {
t.ok(
/\s*Usage: syllable \[options] <words...>/.test(result.stdout),
'Should accept `' + flag + '`'
)
}, t.ifErr)
t.plan(8)

exec('./cli.js syllables', function(err, stdout, stderr) {
t.deepEqual([err, stdout, stderr], [null, '3\n', ''], 'one')
})

version.forEach(function(flag) {
execa('./cli.js', [flag]).then(function(result) {
t.equal(result.stdout, pack.version, 'Should accept `' + flag + '`')
}, t.ifErr)
exec('./cli.js syllables unicorns', function(err, stdout, stderr) {
t.deepEqual([err, stdout, stderr], [null, '6\n', ''], 'two')
})

stream = new Stream()
exec('./cli.js ""', function(err, stdout, stderr) {
t.deepEqual(
[Boolean(err), stdout, /Usage: syllable/.test(stderr)],
[true, '', true],
'no arguments'
)
})

execa('./cli.js', {input: stream}).then(function(result) {
t.equal(result.stdout, '6', 'Should accept stdin')
}, t.ifErr)
var subprocess = exec('./cli.js', function(err, stdout, stderr) {
t.deepEqual([err, stdout, stderr], [null, '6\n', ''], 'stdin')
})

input.pipe(subprocess.stdin)
input.write('syllab')
setImmediate(function() {
stream.write('syllab')

input.write('les uni')
setImmediate(function() {
stream.write('les uni')
input.end('corns')
})
})

helps.forEach(function(flag) {
exec('./cli.js ' + flag, function(err, stdout, stderr) {
t.deepEqual(
[err, /\sUsage: syllable/.test(stdout), stderr],
[null, true, ''],
flag
)
})
})

setImmediate(function() {
stream.end('corns')
})
versions.forEach(function(flag) {
exec('./cli.js ' + flag, function(err, stdout, stderr) {
t.deepEqual([err, stdout, stderr], [null, version + '\n', ''], flag)
})
})
})
Expand Down

0 comments on commit c2e75cd

Please sign in to comment.