Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit e80989e

Browse files
authored
Merge pull request #15 from realityking/decaffinate-tests
Decaffinate tests
2 parents 4a8abce + 86a9e71 commit e80989e

File tree

9 files changed

+283
-275
lines changed

9 files changed

+283
-275
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
},
2121
"devDependencies": {
2222
"chai": "4.1.2",
23-
"coffeescript": "1.12.7",
2423
"mocha": "5.0.4"
2524
},
2625
"keywords": [

scripts/bdd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
./node_modules/mocha/bin/mocha -w --reporter spec --compilers=coffee:coffeescript/register ./test/**/*-test.coffee
2+
./node_modules/mocha/bin/mocha -w --reporter spec ./test/**/*-test.js

scripts/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/sh
2-
./node_modules/mocha/bin/mocha --reporter spec --compilers=coffee:coffeescript/register ./test/**/*-test.coffee
2+
./node_modules/mocha/bin/mocha --reporter spec ./test/**/*-test.js

test/integration/cli-test.coffee

Lines changed: 0 additions & 93 deletions
This file was deleted.

test/integration/cli-test.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
});

test/integration/js-api-test.coffee

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/integration/js-api-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs');
2+
3+
const { assert } = require('chai');
4+
const parser = require('../../lib/parser');
5+
6+
describe('Javascript API', () =>
7+
describe('parsing from file', () =>
8+
9+
it('should return expected raw HTTP in format described in Readme', (done) => {
10+
const traceFilePath = './test/fixtures/get/tracefile';
11+
const expectedOutputPath = './test/fixtures/get/expected-output';
12+
13+
fs.readFile(traceFilePath, 'utf8', (err, trace) => {
14+
const parsed = parser.parseToString(trace);
15+
fs.readFile(expectedOutputPath, 'utf8', (error, expected) => {
16+
assert.equal(parsed, expected);
17+
done();
18+
});
19+
});
20+
})));

0 commit comments

Comments
 (0)