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

Commit

Permalink
feat: simplify creating server files
Browse files Browse the repository at this point in the history
Close #54
  • Loading branch information
honzajavorek committed May 29, 2019
1 parent f11eed4 commit 53b55c8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 62 deletions.
16 changes: 1 addition & 15 deletions features/execution_order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ Feature: Execution order

Background:
Given I have Dredd installed
And a file named "server.js" with:
"""
require('http')
.createServer((req, res) => {
if (req.url === '/message') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
} else {
res.writeHead(500);
res.end();
}
})
.listen(4567);
"""

And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
And a file named "apiary.apib" with:
"""
# My Api
Expand Down
16 changes: 1 addition & 15 deletions features/failing_transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ Feature: Failing a transaction

Background:
Given I have Dredd installed
And a file named "server.js" with:
"""
require('http')
.createServer((req, res) => {
if (req.url === '/message') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
} else {
res.writeHead(500);
res.end();
}
})
.listen(4567);
"""

And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
And a file named "apiary.apib" with:
"""
# My Api
Expand Down
16 changes: 1 addition & 15 deletions features/hook_handlers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ Feature: Hook handlers

Background:
Given I have Dredd installed
And a file named "server.js" with:
"""
require('http')
.createServer((req, res) => {
if (req.url === '/message') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
} else {
res.writeHead(500);
res.end();
}
})
.listen(4567);
"""

And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
And a file named "apiary.apib" with:
"""
# My Api
Expand Down
16 changes: 1 addition & 15 deletions features/multiple_hookfiles.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ Feature: Multiple hook files with a glob

Background:
Given I have Dredd installed
And a file named "server.js" with:
"""
require('http')
.createServer((req, res) => {
if (req.url === '/message') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World!\n');
} else {
res.writeHead(500);
res.end();
}
})
.listen(4567);
"""

And a file "server.js" with a server responding on "http://localhost:4567/message" with "Hello World!"
And a file named "apiary.apib" with:
"""
# My Api
Expand Down
23 changes: 21 additions & 2 deletions features/support/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const childProcess = require('child_process');
const { expect } = require('chai');
const fs = require('fs-extra');
const net = require('net');
const url = require('url');
const which = require('which');
const kill = require('tree-kill');
const {
Expand Down Expand Up @@ -33,11 +34,29 @@ Given('I have Dredd installed', function step() {
which.sync(this.dreddBin); // throws if not found
});

Given(/^a file named "([^"]+)" with:$/, function step(filename, content) {
Given('a file {string} with a server responding on {string} with {string}', function step(filename, fullURL, body) {
const urlParts = url.parse(fullURL);
const content = `
require('http')
.createServer((req, res) => {
if (req.url === '${urlParts.path}') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('${body}\\n');
} else {
res.writeHead(500);
res.end();
}
})
.listen(${urlParts.port});
`;
fs.writeFileSync(path.join(this.dir, filename), content);
});

Given('a file named {string} with:', function step(filename, content) {
fs.writeFileSync(path.join(this.dir, filename), content);
});

Given(/^I set the environment variables to:$/, function step(env) {
Given('I set the environment variables to:', function step(env) {
this.env = { ...this.env, ...env.rowsHash() };
});

Expand Down

0 comments on commit 53b55c8

Please # to comment.