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

Commit 407d6f4

Browse files
authored
Merge pull request #52 from apiaryio/honzajavorek/lint
Add ESLint
2 parents 4e710d5 + 2f2e844 commit 407d6f4

File tree

8 files changed

+663
-39
lines changed

8 files changed

+663
-39
lines changed

.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
extends: 'airbnb-base',
3+
env: {
4+
'mocha': true,
5+
'node': true
6+
},
7+
rules: {
8+
// Using 'console' is perfectly okay for a Node.js CLI tool and avoiding
9+
// it only brings unnecessary complexity
10+
'no-console': 'off',
11+
}
12+
};

cli/copyFeatures.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ module.exports = function copyFeatures(srcDir, dstDir, transformBasename = basen
1515
const featurePath = path.join(dstDir, transformBasename(featureBasename));
1616
fs.writeFileSync(featurePath, featureContent, { encoding: 'utf-8' });
1717
});
18-
}
18+
};

cli/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ const run = require('./run');
77
const copyFeatures = require('./copyFeatures');
88

99

10-
PROJECT_DIR = process.cwd();
11-
NODE_MODULES_DIR = path.join(PROJECT_DIR, 'node_modules');
10+
const PROJECT_DIR = process.cwd();
11+
const NODE_MODULES_DIR = path.join(PROJECT_DIR, 'node_modules');
1212

13-
FEATURES_SRC_DIR = path.join(NODE_MODULES_DIR, 'dredd-hooks-template', 'features');
14-
FEATURES_DIR = path.join(PROJECT_DIR, 'features');
15-
STEPS_DIR = path.join(FEATURES_SRC_DIR, 'support');
13+
const FEATURES_SRC_DIR = path.join(NODE_MODULES_DIR, 'dredd-hooks-template', 'features');
14+
const FEATURES_DIR = path.join(PROJECT_DIR, 'features');
15+
const STEPS_DIR = path.join(FEATURES_SRC_DIR, 'support');
1616

17-
NODE_BIN = process.execPath;
18-
CUCUMBER_BIN = path.join(NODE_MODULES_DIR, '.bin', 'cucumber-js');
17+
const NODE_BIN = process.execPath;
18+
const CUCUMBER_BIN = path.join(NODE_MODULES_DIR, '.bin', 'cucumber-js');
1919

2020

2121
function init() {
@@ -49,13 +49,13 @@ function upgrade() {
4949

5050
// halt in case the project already depends on the latest version
5151
if (currentVersion === version) {
52-
console.log(`The test suite template is up to date!`);
52+
console.log('The test suite template is up to date!');
5353
return;
5454
}
5555

5656
// upgrade the package
57-
const package = `dredd-hooks-template@${version}`;
58-
run('npm', ['install', package, '--save-dev'], { cwd: PROJECT_DIR });
57+
const pkg = `dredd-hooks-template@${version}`;
58+
run('npm', ['install', pkg, '--save-dev'], { cwd: PROJECT_DIR });
5959

6060
// copy '*.feature' files from the upgraded 'dredd-hooks-template' package
6161
// to the project, but don't overwrite the existing feature files, add these
@@ -80,6 +80,6 @@ if (process.argv.length > 3) {
8080
} else {
8181
process.exitCode = 1;
8282
console.error('Available commands: init, test, upgrade');
83-
console.error('See https://github.com/apiaryio/dredd-hooks-template README')
83+
console.error('See https://github.com/apiaryio/dredd-hooks-template README');
8484
}
8585
}

cli/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { spawnSync } = require('child_process');
77
*/
88
module.exports = function run(command, args, options) {
99
const proc = spawnSync(command, args, { ...options, stdio: 'inherit' });
10-
if (proc.error) throw error;
10+
if (proc.error) throw proc.error;
1111
if (proc.status) throw new Error(`'${[command].concat(args).join(' ')}' failed`);
1212
return proc;
1313
};

features/support/steps.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,48 @@ const fs = require('fs-extra');
77
const net = require('net');
88
const which = require('which');
99
const kill = require('tree-kill');
10-
const { Given, When, Then, Before, After } = require('cucumber');
10+
const {
11+
Given,
12+
When,
13+
Then,
14+
Before,
15+
After,
16+
} = require('cucumber');
1117

12-
DREDD_BIN = path.join(process.cwd(), 'node_modules', '.bin', 'dredd');
1318

19+
const DREDD_BIN = path.join(process.cwd(), 'node_modules', '.bin', 'dredd');
1420

15-
Before(function () {
21+
22+
Before(function hook() {
1623
this.dir = fs.mkdtempSync(path.join(os.tmpdir(), 'dredd-hooks-template-'));
1724
this.env = { ...process.env };
1825
this.commands = [];
1926
this.dataSent = '';
2027
});
2128

22-
After(async function () {
29+
After(async function hook() {
2330
fs.remove(this.dir);
2431
await util.promisify(kill)(this.proc.pid);
2532
});
2633

2734

28-
Given(/^I have "([^"]+)" command installed$/, function (match) {
35+
Given(/^I have "([^"]+)" command installed$/, (match) => {
2936
const command = match === 'dredd'
3037
? DREDD_BIN
3138
: match;
3239
which.sync(command); // throws if the command is not found
3340
});
3441

35-
Given(/^a file named "([^"]+)" with:$/, function (filename, content) {
42+
Given(/^a file named "([^"]+)" with:$/, function step(filename, content) {
3643
fs.writeFileSync(path.join(this.dir, filename), content);
3744
});
3845

39-
Given(/^I set the environment variables to:$/, function (env) {
46+
Given(/^I set the environment variables to:$/, function step(env) {
4047
this.env = { ...this.env, ...env.rowsHash() };
4148
});
4249

4350

44-
When(/^I run `([^`]+)`$/, function (match) {
51+
When(/^I run `([^`]+)`$/, function step(match) {
4552
const command = match.replace(/^dredd(?= )/, DREDD_BIN);
4653
this.proc = childProcess.spawnSync(command, [], {
4754
shell: true,
@@ -50,16 +57,16 @@ When(/^I run `([^`]+)`$/, function (match) {
5057
});
5158
});
5259

53-
When(/^I run `([^`]+)` interactively$/, function (command) {
60+
When(/^I run `([^`]+)` interactively$/, function step(command) {
5461
this.proc = childProcess.spawn(command, [], {
5562
shell: true,
5663
cwd: this.dir,
5764
env: this.env,
5865
});
5966
});
6067

61-
When('I wait for output to contain {string}', function (output, callback) {
62-
const proc = this.proc;
68+
When('I wait for output to contain {string}', function step(output, callback) {
69+
const { proc } = this;
6370

6471
function read(data) {
6572
if (data.toString().includes(output)) {
@@ -73,38 +80,38 @@ When('I wait for output to contain {string}', function (output, callback) {
7380
proc.stderr.on('data', read);
7481
});
7582

76-
When('I connect to the server', async function () {
83+
When('I connect to the server', async function step() {
7784
this.socket = new net.Socket();
7885
const connect = util.promisify(this.socket.connect.bind(this.socket));
7986
await connect(61321, '127.0.0.1');
8087
});
8188

82-
When('I send a JSON message to the socket:', function (message) {
89+
When('I send a JSON message to the socket:', function step(message) {
8390
this.socket.write(message);
8491
this.dataSent += message;
8592
});
8693

87-
When('I send a newline character as a message delimiter to the socket', function () {
94+
When('I send a newline character as a message delimiter to the socket', function step() {
8895
this.socket.write('\n');
8996
});
9097

9198

92-
Then('the exit status should be {int}', function (status) {
99+
Then('the exit status should be {int}', function step(status) {
93100
expect(this.proc.status).to.equal(status);
94101
});
95102

96-
Then('the output should contain:', function (output) {
103+
Then('the output should contain:', function step(output) {
97104
expect(this.proc.stdout.toString() + this.proc.stderr.toString()).to.contain(output);
98105
});
99106

100-
Then('it should start listening on localhost port {int}', async function (port) {
107+
Then('it should start listening on localhost port {int}', async function step(port) {
101108
this.socket = new net.Socket();
102109
const connect = util.promisify(this.socket.connect.bind(this.socket));
103110
await connect(port, '127.0.0.1'); // throws if there's an issue
104111
this.socket.end();
105112
});
106113

107-
Then('I should receive the same response', function (callback) {
114+
Then('I should receive the same response', function step(callback) {
108115
this.socket.on('data', (data) => {
109116
const dataReceived = JSON.parse(data.toString());
110117
const dataSent = JSON.parse(this.dataSent);
@@ -113,6 +120,6 @@ Then('I should receive the same response', function (callback) {
113120
});
114121
});
115122

116-
Then('I should be able to gracefully disconnect', function () {
123+
Then('I should be able to gracefully disconnect', function step() {
117124
this.socket.end();
118125
});

0 commit comments

Comments
 (0)