1- import { createRequire } from 'node:module' ;
21import { describe , it } from 'node:test' ;
32import assert from 'node:assert/strict' ;
3+ import child_process from 'node:child_process' ;
4+ import { writeFileSync , unlinkSync } from 'node:fs' ;
5+ import path from 'node:path' ;
6+ import { promisify } from 'node:util' ;
47import { input } from '@inquirer/prompts' ;
58import defaultInput from '@inquirer/input' ;
69import { createPrompt } from '@inquirer/core' ;
710import inquirer , { createPromptModule } from 'inquirer' ;
811import fixturePrompt from './fixturePrompt.mjs' ;
912
10- const require = createRequire ( import . meta . url ) ;
13+ const exec = promisify ( child_process . exec ) ;
1114
1215describe ( 'ESM Integration' , ( ) => {
1316 it ( '@inquirer/prompts should be exported' , ( ) => {
@@ -24,7 +27,7 @@ describe('ESM Integration', () => {
2427
2528 it ( 'works when prompt throws an error' , async ( ) => {
2629 await assert . rejects ( ( ) => fixturePrompt ( { } ) , {
27- message : `Prompt functions must return a string.\n at file://${ require . resolve ( './fixturePrompt.mjs' ) } ` ,
30+ message : `Prompt functions must return a string.\n at file://${ path . join ( import . meta . dirname , './fixturePrompt.mjs' ) } ` ,
2831 } ) ;
2932 } ) ;
3033
@@ -33,4 +36,36 @@ describe('ESM Integration', () => {
3336 assert . ok ( typeof inquirer . createPromptModule === 'function' ) ;
3437 assert . ok ( typeof createPromptModule === 'function' ) ;
3538 } ) ;
39+
40+ it ( 'works with Unix yes command piped input' , async ( ) => {
41+ try {
42+ await exec ( 'which yes' ) ;
43+ } catch {
44+ assert . ok ( true ) ;
45+ console . warn ( 'WARN: Skipping test due to absence of `yes` in the PATH' ) ;
46+ }
47+
48+ const testScript = path . join ( import . meta. dirname , 'test-yes-pipe.js' ) ;
49+ writeFileSync (
50+ testScript ,
51+ `
52+ import { confirm } from '@inquirer/prompts';
53+
54+ const answer = await confirm({
55+ message: 'Do you want to proceed?'
56+ });
57+
58+ process.exit(answer ? 0 : 1);
59+ ` ,
60+ ) ;
61+
62+ try {
63+ await exec ( `yes | node ${ testScript } > /dev/null` ) ;
64+ assert . ok ( true ) ;
65+ } catch {
66+ assert . fail ( 'Command thew' ) ;
67+ } finally {
68+ unlinkSync ( testScript ) ;
69+ }
70+ } , 10000 ) ;
3671} ) ;
0 commit comments