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