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

Commit fc2abe8

Browse files
authored
Merge pull request #58 from apiaryio/honzajavorek/simplify-server
Simplify server steps
2 parents f11eed4 + 89ab293 commit fc2abe8

File tree

5 files changed

+25
-62
lines changed

5 files changed

+25
-62
lines changed

features/execution_order.feature

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ Feature: Execution order
22

33
Background:
44
Given I have Dredd installed
5-
And a file named "server.js" with:
6-
"""
7-
require('http')
8-
.createServer((req, res) => {
9-
if (req.url === '/message') {
10-
res.writeHead(200, { 'Content-Type': 'text/plain' });
11-
res.end('Hello World!\n');
12-
} else {
13-
res.writeHead(500);
14-
res.end();
15-
}
16-
})
17-
.listen(4567);
18-
"""
19-
205
And a file named "apiary.apib" with:
216
"""
227
# My Api
@@ -25,6 +10,7 @@ Feature: Execution order
2510
2611
Hello World!
2712
"""
13+
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
2814

2915
Scenario:
3016
Given a file named "hookfile.{{my-extension}}" with:

features/failing_transaction.feature

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ Feature: Failing a transaction
22

33
Background:
44
Given I have Dredd installed
5-
And a file named "server.js" with:
6-
"""
7-
require('http')
8-
.createServer((req, res) => {
9-
if (req.url === '/message') {
10-
res.writeHead(200, { 'Content-Type': 'text/plain' });
11-
res.end('Hello World!\n');
12-
} else {
13-
res.writeHead(500);
14-
res.end();
15-
}
16-
})
17-
.listen(4567);
18-
"""
19-
205
And a file named "apiary.apib" with:
216
"""
227
# My Api
@@ -25,6 +10,7 @@ Feature: Failing a transaction
2510
2611
Hello World!
2712
"""
13+
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
2814

2915
Scenario:
3016
Given a file named "hookfile.{{my-extension}}" with:

features/hook_handlers.feature

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ Feature: Hook handlers
22

33
Background:
44
Given I have Dredd installed
5-
And a file named "server.js" with:
6-
"""
7-
require('http')
8-
.createServer((req, res) => {
9-
if (req.url === '/message') {
10-
res.writeHead(200, { 'Content-Type': 'text/plain' });
11-
res.end('Hello World!\n');
12-
} else {
13-
res.writeHead(500);
14-
res.end();
15-
}
16-
})
17-
.listen(4567);
18-
"""
19-
205
And a file named "apiary.apib" with:
216
"""
227
# My Api
@@ -25,6 +10,7 @@ Feature: Hook handlers
2510
2611
Hello World!
2712
"""
13+
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
2814

2915
Scenario:
3016
Given a file named "hookfile.{{my-extension}}" with:

features/multiple_hookfiles.feature

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,6 @@ Feature: Multiple hook files with a glob
22

33
Background:
44
Given I have Dredd installed
5-
And a file named "server.js" with:
6-
"""
7-
require('http')
8-
.createServer((req, res) => {
9-
if (req.url === '/message') {
10-
res.writeHead(200, { 'Content-Type': 'text/plain' });
11-
res.end('Hello World!\n');
12-
} else {
13-
res.writeHead(500);
14-
res.end();
15-
}
16-
})
17-
.listen(4567);
18-
"""
19-
205
And a file named "apiary.apib" with:
216
"""
227
# My Api
@@ -25,6 +10,7 @@ Feature: Multiple hook files with a glob
2510
2611
Hello World!
2712
"""
13+
And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
2814

2915
Scenario:
3016
Given a file named "hookfile1.{{my-extension}}" with:

features/support/steps.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const childProcess = require('child_process');
55
const { expect } = require('chai');
66
const fs = require('fs-extra');
77
const net = require('net');
8+
const url = require('url');
89
const which = require('which');
910
const kill = require('tree-kill');
1011
const {
@@ -33,11 +34,29 @@ Given('I have Dredd installed', function step() {
3334
which.sync(this.dreddBin); // throws if not found
3435
});
3536

36-
Given(/^a file named "([^"]+)" with:$/, function step(filename, content) {
37+
Given('a file {string} with a server responding on {string} with {string}', function step(filename, fullURL, body) {
38+
const urlParts = url.parse(fullURL);
39+
const content = `
40+
require('http')
41+
.createServer((req, res) => {
42+
if (req.url === '${urlParts.path}') {
43+
res.writeHead(200, { 'Content-Type': 'text/plain' });
44+
res.end('${body}\\n');
45+
} else {
46+
res.writeHead(500);
47+
res.end();
48+
}
49+
})
50+
.listen(${urlParts.port});
51+
`;
52+
fs.writeFileSync(path.join(this.dir, filename), content);
53+
});
54+
55+
Given('a file named {string} with:', function step(filename, content) {
3756
fs.writeFileSync(path.join(this.dir, filename), content);
3857
});
3958

40-
Given(/^I set the environment variables to:$/, function step(env) {
59+
Given('I set the environment variables to:', function step(env) {
4160
this.env = { ...this.env, ...env.rowsHash() };
4261
});
4362

0 commit comments

Comments
 (0)