Commit ae0f0cf
Changed files (3)
src
src/goods.ts
@@ -73,6 +73,7 @@ export async function question(
): Promise<string> {
let completer = undefined
if (options && Array.isArray(options.choices)) {
+ /* c8 ignore next 5 */
completer = function completer(line: string) {
const completions = options.choices
const hits = completions.filter((c) => c.startsWith(line))
test/index.test.js
@@ -124,25 +124,15 @@ test('pipes are working', async () => {
}
})
-// test('question() works', async () => {
-// let p = question('foo or bar? ', { choices: ['foo', 'bar'] })
-// setImmediate(() => {
-// process.stdin.emit('data', 'fo')
-// process.stdin.emit('data', '\t')
-// process.stdin.emit('data', '\n')
-// })
-// assert.is(await p, 'foo')
-// })
-//
-// test('empty question() works', async () => {
-// let p = question(undefined, { choices: [] })
-// setImmediate(() => {
-// process.stdin.emit('data', 'xxx')
-// process.stdin.emit('data', '\t')
-// process.stdin.emit('data', '\n')
-// })
-// assert.match(await p, 'xxx')
-// })
+test('question() works', async () => {
+ let p = $`node build/cli.js --eval "
+ let answer = await question('foo or bar? ', { choices: ['foo', 'bar'] })
+ echo('Answer is', answer)
+"`
+ p.stdin.write('foo\n')
+ p.stdin.end()
+ assert.match((await p).stdout, 'Answer is foo')
+})
test('ProcessPromise', async () => {
let contents = ''
test/package.test.js
@@ -45,7 +45,7 @@ test('js project with zx', async () => {
await $`rm -rf node_modules`
await $`mkdir node_modules`
await $`mv ${pack} node_modules/zx`
- return $`npx zx script.js`
+ return $`node node_modules/zx/build/cli.js script.js`
})
assert.match(out.stderr, 'js-script')
})