Skip to content

Commit ccd9824

Browse files
committed
Starting the HC API during cucumber setup
1 parent 0413973 commit ccd9824

File tree

6 files changed

+353
-8
lines changed

6 files changed

+353
-8
lines changed

features/env/hooks.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const {AfterAll, BeforeAll} = require('cucumber');
2+
const { spawn } = require('child_process');
3+
const waitOn = require('wait-on');
4+
5+
let hcApi;
6+
7+
// Asynchronous Callback
8+
BeforeAll({timeout: 30*1000}, function (callback) {
9+
hcApi = spawn('node', ['server/'], {
10+
cwd: './human-connection-api/',
11+
env: {
12+
'NODE_ENV': 'test'
13+
}
14+
});
15+
16+
hcApi.stdout.on('data', (data) => {
17+
console.log(`stdout: ${data}`);
18+
});
19+
20+
hcApi.stderr.on('data', (data) => {
21+
console.log(`stderr: ${data}`);
22+
});
23+
24+
waitOn({ resources: ['tcp:3030'], timeout: 30000 }, function (err) {
25+
if (err) { return handleError(err); }
26+
callback();
27+
});
28+
});
29+
30+
// Asynchronous Promise
31+
AfterAll(function () {
32+
// perform some shared teardown
33+
hcApi.kill();
34+
return Promise.resolve()
35+
});

features/importPost.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Feature: Import a post from an organization and publish it in Human Connection
55

66

77
Background:
8-
Given there is an organization in Human Connection with these credentials:
8+
Given the Human Connection API is up and running
9+
And there is a 3rd party application running, e.g. 'Democracy'
10+
And there is an organization in Human Connection with these credentials:
911
| Email | Password |
1012
| organization@example.com | 1234 |
1113

features/step_definitions/steps.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const { Given, When, Then } = require('cucumber');
22

3+
Given('the Human Connection API is up and running', function () {
4+
// Write code here that turns the phrase above into concrete actions
5+
console.log('skipping over starting the Human Connection API');
6+
});
7+
8+
Given("there is a 3rd party application running, e.g. 'Democracy'", function () {
9+
// Write code here that turns the phrase above into concrete actions
10+
console.log('skipping over starting the 3rd party API');
11+
// return 'pending';
12+
});
13+
314
Given('there is an organization in Human Connection with these credentials:', function (dataTable) {
415
// Write code here that turns the phrase above into concrete actions
516
return 'pending';

index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async function main() {
7676

7777
main().catch((err) => {
7878
console.log(err);
79-
if (err.code === 'ECONNREFUSED'){
79+
if (err.code === 'ECONNREFUSED') {
8080
console.log('\nProbably a service is not running?\n');
8181
}
8282
process.exit(-100);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"cucumber": "^4.2.1",
44
"eslint-plugin-you-dont-need-lodash-underscore": "^6.3.1",
55
"lodash": "^4.17.5",
6-
"node-fetch": "^2.1.2"
6+
"node-fetch": "^2.1.2",
7+
"wait-on": "^2.1.0"
78
},
89
"name": "human-connection-api-nodejs-client",
910
"version": "1.0.0",

0 commit comments

Comments
 (0)