|
| 1 | +const fs = require('fs'); |
| 2 | +const { assert } = require('chai'); |
| 3 | +const { exec } = require('child_process'); |
| 4 | + |
| 5 | +const cmdPrefix = ''; |
| 6 | + |
| 7 | +describe('Command line', () => { |
| 8 | + describe('parsing from standard input with --raw', () => { |
| 9 | + let stdout = ''; |
| 10 | + let stderr = ''; |
| 11 | + let exitStatus = ''; |
| 12 | + |
| 13 | + before((done) => { |
| 14 | + const cmd = 'cat ./test/fixtures/get/tracefile | ' + |
| 15 | + './bin/curl-trace-parser --raw'; |
| 16 | + |
| 17 | + const cli = exec(cmdPrefix + cmd, (error, out, err) => { |
| 18 | + stdout = out; |
| 19 | + stderr = err; |
| 20 | + if (error) { |
| 21 | + exitStatus = error.status; |
| 22 | + } |
| 23 | + done(); |
| 24 | + }); |
| 25 | + |
| 26 | + cli.on('exit', (code) => { exitStatus = code; }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should not return nothing to stderr', () => assert.equal(stderr, '')); |
| 30 | + |
| 31 | + it('should return with exit code 0', () => assert.equal(exitStatus, 0)); |
| 32 | + |
| 33 | + it('should return parsed body to standard output', (done) => { |
| 34 | + const expectedOutputPath = './test/fixtures/get/expected-output'; |
| 35 | + fs.readFile(expectedOutputPath, 'utf8', (err, expected) => { |
| 36 | + assert.equal(stdout, expected); |
| 37 | + done(); |
| 38 | + }); |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + describe('parsing from standard input with --blueprint option', () => { |
| 43 | + let stdout = ''; |
| 44 | + let stderr = ''; |
| 45 | + let exitStatus = ''; |
| 46 | + |
| 47 | + before((done) => { |
| 48 | + const cmd = 'cat ./test/fixtures/post/tracefile | ' + |
| 49 | + './bin/curl-trace-parser --blueprint'; |
| 50 | + |
| 51 | + const cli = exec(cmdPrefix + cmd, (error, out, err) => { |
| 52 | + stdout = out; |
| 53 | + stderr = err; |
| 54 | + if (error) { |
| 55 | + exitStatus = error.status; |
| 56 | + } |
| 57 | + done(); |
| 58 | + }); |
| 59 | + |
| 60 | + cli.on('exit', (code) => { exitStatus = code; }); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should not return nothing to stderr', () => assert.equal(stderr, '')); |
| 64 | + |
| 65 | + it('should return with exit code 0', () => assert.equal(exitStatus, 0)); |
| 66 | + |
| 67 | + it('should return parsed body in API Blueprint format to standard output', (done) => { |
| 68 | + const expectedOutputPath = './test/fixtures/post/expected-output.md'; |
| 69 | + fs.readFile(expectedOutputPath, 'utf8', (err, expected) => { |
| 70 | + assert.equal(stdout, expected); |
| 71 | + done(); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('no input on stdin and no options', () => { |
| 77 | + let stderr = ''; |
| 78 | + let exitStatus = ''; |
| 79 | + |
| 80 | + before((done) => { |
| 81 | + const cmd = './bin/curl-trace-parser'; |
| 82 | + const cli = exec(cmdPrefix + cmd, (error, out, err) => { |
| 83 | + stderr = err; |
| 84 | + if (error) { |
| 85 | + exitStatus = error.code; |
| 86 | + } |
| 87 | + }); |
| 88 | + |
| 89 | + |
| 90 | + cli.on('exit', (code) => { |
| 91 | + exitStatus = code; |
| 92 | + done(); |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + |
| 97 | + it('should exit with status 1', () => assert.equal(exitStatus, 1)); |
| 98 | + |
| 99 | + it('should return error message to stderr', () => assert.include(stderr, 'No input on stdin')); |
| 100 | + }); |
| 101 | +}); |
0 commit comments