|
| 1 | +import { exec } from 'child_process'; |
| 2 | + |
| 3 | +describe('plotter script', () => { |
| 4 | + // @ts-expect-error tests |
| 5 | + const execPlotterScript = (args, callback) => { |
| 6 | + exec(`node node_modules/simple-ascii-chart/dist/cli.js ${args}`, callback); |
| 7 | + }; |
| 8 | + |
| 9 | + it('should require the --input option', (done) => { |
| 10 | + // @ts-expect-error tests |
| 11 | + execPlotterScript('', (error, stdout, stderr) => { |
| 12 | + expect(stderr).toContain('Missing required argument: input'); |
| 13 | + done(); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should output a plot when given valid input', (done) => { |
| 18 | + const validInput = JSON.stringify([ |
| 19 | + [1, 1], |
| 20 | + [2, 2], |
| 21 | + [3, 3], |
| 22 | + ]); |
| 23 | + // @ts-expect-error tests |
| 24 | + execPlotterScript(`--input '${validInput}'`, (error, stdout, stderr) => { |
| 25 | + expect(error).toBeNull(); |
| 26 | + expect(stderr).toBe(''); |
| 27 | + expect(stdout).toContain(` |
| 28 | + ▲ |
| 29 | +3┤ ┏━ |
| 30 | +2┤┏┛ |
| 31 | +1┤┛ |
| 32 | + └┬┬┬▶ |
| 33 | + 123 |
| 34 | +`); |
| 35 | + done(); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should handle invalid JSON input gracefully', (done) => { |
| 40 | + const invalidInput = '[ invalid json'; |
| 41 | + // @ts-expect-error tests |
| 42 | + execPlotterScript(`--input '${invalidInput}'`, (error, stdout, stderr) => { |
| 43 | + expect(stderr).toContain('Oops! Something went wrong!'); |
| 44 | + done(); |
| 45 | + }); |
| 46 | + }); |
| 47 | +}); |
0 commit comments