|
| 1 | +import '../common/index.mjs'; |
| 2 | +import { startNewREPLServer } from '../common/repl.js'; |
| 3 | +import assert from 'node:assert'; |
| 4 | + |
| 5 | +const { replServer, output, run } = startNewREPLServer({ |
| 6 | + prompt: '> ', |
| 7 | + terminal: true, |
| 8 | +}); |
| 9 | + |
| 10 | +replServer.defineCommand('say1', { |
| 11 | + help: 'help for say1', |
| 12 | + action: function (thing) { |
| 13 | + this.output.accumulator = ''; |
| 14 | + this.output.write(`hello ${thing}\n`); |
| 15 | + this.displayPrompt(); |
| 16 | + }, |
| 17 | +}); |
| 18 | + |
| 19 | +replServer.defineCommand('say2', function () { |
| 20 | + this.output.accumulator = ''; |
| 21 | + this.output.write('hello from say2\n'); |
| 22 | + this.displayPrompt(); |
| 23 | +}); |
| 24 | + |
| 25 | +await run(['.help\n']); |
| 26 | +assert.match(output.accumulator, /\n\.say1 {5}help for say1\n/); |
| 27 | +assert.match(output.accumulator, /\n\.say2\n/); |
| 28 | + |
| 29 | +await run(['.say1 node developer\n']); |
| 30 | +assert.ok( |
| 31 | + output.accumulator.startsWith('hello node developer\n'), |
| 32 | + `say1 output starts incorrectly: "${output.accumulator}"`, |
| 33 | +); |
| 34 | +assert.ok( |
| 35 | + output.accumulator.includes('> '), |
| 36 | + `say1 output does not include prompt: "${output.accumulator}"`, |
| 37 | +); |
| 38 | + |
| 39 | +await run(['.say2 node developer\n']); |
| 40 | +assert.ok( |
| 41 | + output.accumulator.startsWith('hello from say2\n'), |
| 42 | + `say2 output starts incorrectly: "${output.accumulator}"`, |
| 43 | +); |
| 44 | +assert.ok( |
| 45 | + output.accumulator.includes('> '), |
| 46 | + `say2 output does not include prompt: "${output.accumulator}"`, |
| 47 | +); |
| 48 | + |
| 49 | +replServer.close(); |
0 commit comments