1'use strict'; 2const { test } = require('tap'); 3 4const startCLI = require('./start-cli'); 5 6test('examples/alive.js', (t) => { 7 const cli = startCLI(['examples/alive.js']); 8 9 function onFatal(error) { 10 cli.quit(); 11 throw error; 12 } 13 14 return cli.waitForInitialBreak() 15 .then(() => cli.waitForPrompt()) 16 .then(() => cli.command('exec [typeof heartbeat, typeof process.exit]')) 17 .then(() => { 18 t.match(cli.output, '[ \'function\', \'function\' ]', 'works w/o paren'); 19 }) 20 .then(() => cli.command('repl')) 21 .then(() => { 22 t.match( 23 cli.output, 24 'Press Ctrl + C to leave debug repl\n> ', 25 'shows hint for how to leave repl'); 26 t.notMatch(cli.output, 'debug>', 'changes the repl style'); 27 }) 28 .then(() => cli.command('[typeof heartbeat, typeof process.exit]')) 29 .then(() => cli.waitFor(/function/)) 30 .then(() => cli.waitForPrompt()) 31 .then(() => { 32 t.match( 33 cli.output, 34 '[ \'function\', \'function\' ]', 'can evaluate in the repl'); 35 t.match(cli.output, /> $/); 36 }) 37 .then(() => cli.ctrlC()) 38 .then(() => cli.waitFor(/debug> $/)) 39 .then(() => cli.command('exec("[typeof heartbeat, typeof process.exit]")')) 40 .then(() => { 41 t.match(cli.output, '[ \'function\', \'function\' ]', 'works w/ paren'); 42 }) 43 .then(() => cli.command('cont')) 44 .then(() => cli.command('exec [typeof heartbeat, typeof process.exit]')) 45 .then(() => { 46 t.match( 47 cli.output, 48 '[ \'undefined\', \'function\' ]', 49 'non-paused exec can see global but not module-scope values'); 50 }) 51 .then(() => cli.quit()) 52 .then(null, onFatal); 53}); 54 55test('exec .scope', (t) => { 56 const cli = startCLI(['examples/backtrace.js']); 57 58 function onFatal(error) { 59 cli.quit(); 60 throw error; 61 } 62 63 return cli.waitForInitialBreak() 64 .then(() => cli.waitForPrompt()) 65 .then(() => cli.stepCommand('c')) 66 .then(() => cli.command('exec .scope')) 67 .then(() => { 68 t.match( 69 cli.output, 70 '\'moduleScoped\'', 'displays closure from module body'); 71 t.match(cli.output, '\'a\'', 'displays local / function arg'); 72 t.match(cli.output, '\'l1\'', 'displays local scope'); 73 t.notMatch(cli.output, '\'encodeURIComponent\'', 'omits global scope'); 74 }) 75 .then(() => cli.quit()) 76 .then(null, onFatal); 77}); 78