it('should alert when <next> is used and cursor is at EOS', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress(null, { name: 'tab' }); }); prompt.run(); });
describe('child_process', function() { it('should works in child_process', cb => { let cmd = fork(path.resolve(__dirname, './support/child_process.js'), [], { silent: true, }); let stdout = ''; let stderr = ''; cmd.stdout.on('data', buf => { let data = buf.toString(); stdout += data; if (data.includes('color')) cmd.stdin.write('orange\n'); }); cmd.stderr.on('data', buf => { stderr += buf.toString(); }); cmd.on('close', () => { assert(!stderr); assert(stdout.includes('color: \'orange\'')); cb(); }); }); });
describe('inheritance', () => { it('should support inheritance', cb => { class Custom extends Enquirer {} const { prompt } = Custom; prompt.on('prompt', p => { p.value = 'orange'; p.submit(); }); prompt({ type: 'input', name: 'color', message: 'Favorite color?', show: false }) .then(answers => { assert.equal(answers.color, 'orange'); cb(); }); }); });
assert(!/[*]{6}/.test(prompt.state.buffer)); assert.equal(prompt.value, 'foobar'); cb(); });
]); assert.equal(prompt.initial, 0); cb(); });
it('should alert when <deleteForward> is used and cursor is at BOS', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress(null, { name: 'delete', fn: true }); }); prompt.run(); });
it('should alert when <cutForward> is used at EOS', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress('k', { ctrl: true }); }); prompt.run(); });
it('should alert when <paste> is used and is empty', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress('v', { ctrl: true }); }); prompt.run(); });
it('should alert when <cutLeft> is used at BOS', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress('w', { ctrl: true }); }); prompt.run(); });
it('should alert when <prev> is used and cursor is at EOS', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress(null, { name: 'tab', shift: true }); }); prompt.run(); });
it('should alert when <backspace> is used and cursor is at BOS', cb => { prompt = new Prompt({ message: 'Favorite color?', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress(null, { name: 'backspace' }); }); prompt.run(); });
it('should alert when <right> is used and cursor is at EOS', cb => { prompt = new Prompt({ message: 'Favorite color?', initial: 'green', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress(null, { name: 'right' }); }); prompt.run(); });
it('should alert when <left> is used and cursor is zero', cb => { prompt = new Prompt({ message: 'Favorite color?', initial: 'green', show: false }); prompt.once('alert', async () => { await prompt.submit(); cb(); }); prompt.once('run', async() => { await prompt.keypress(null, { name: `left` }); }); prompt.run(); });