Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 46 additions & 40 deletions generators/app/templates/angularjs/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,61 @@ var http = require('http');

// Below code demonstrates using various methods of testing
describe('Testing Server', function() {
let test_server;
this.timeout(0);

before(function(done){
require(process.cwd() + '/server/server');
setTimeout(done, 5000); // Waiting 5 seconds for server to start
this.timeout(10000);
before(done => {
let app = require(process.cwd() + '/server/server');
test_server = app.listen(process.env.PORT || 3000, done);
});
it('Public endpoint returns "Hello!"', function(done){
var responseString = '';

var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/'
};
it('Public endpoint returns "Hello!"', function(done){
var responseString = '';

var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});
var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/'
};

response.on('end', function () {
expect(responseString).to.include('You need to enable JavaScript to run this app.');
done();
});
};
var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});

http.request(options, callback).end();
});
response.on('end', function () {
expect(responseString).to.include('You need to enable JavaScript to run this app.');
done();
});
};

it('Health endpoint shows status up', function(done){
var responseString = '';
http.request(options, callback).end();
});

it('Health endpoint shows status up', function(done){
var responseString = '';

var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health'
};
var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health'
};

var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});
var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});

response.on('end', function () {
expect(responseString).to.equal('{"status":"UP"}');
done();
});
};
response.on('end', function () {
expect(responseString).to.equal('{"status":"UP"}');
done();
});
};

http.request(options, callback).end();
});
http.request(options, callback).end();
});

after(done => {
test_server.close(done);
});
});
86 changes: 46 additions & 40 deletions generators/app/templates/basic/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,61 @@ var http = require('http');

// Below code demonstrates using various methods of testing
describe('Testing Server', function() {
let test_server;
this.timeout(0);

before(function(done){
require(process.cwd() + '/server/server');
setTimeout(done, 5000); // Waiting 5 seconds for server to start
this.timeout(10000);
before(done => {
let app = require(process.cwd() + '/server/server');
test_server = app.listen(process.env.PORT || 3000, done);
});
it('Public endpoint returns "Hello!"', function(done){
var responseString = '';

var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/'
};
it('Public endpoint returns "Hello!"', function(done){
var responseString = '';

var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});
var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/'
};

response.on('end', function () {
expect(responseString).to.include('You are currently running a Node.js app built for the IBM Cloud.');
done();
});
};
var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});

http.request(options, callback).end();
});
response.on('end', function () {
expect(responseString).to.include('You are currently running a Node.js app built for the IBM Cloud.');
done();
});
};

it('Health endpoint shows status up', function(done){
var responseString = '';
http.request(options, callback).end();
});

it('Health endpoint shows status up', function(done){
var responseString = '';

var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health'
};
var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health'
};

var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});
var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});

response.on('end', function () {
expect(responseString).to.equal('{"status":"UP"}');
done();
});
};
response.on('end', function () {
expect(responseString).to.equal('{"status":"UP"}');
done();
});
};

http.request(options, callback).end();
});
http.request(options, callback).end();
});

after(done => {
test_server.close(done);
});
});
86 changes: 46 additions & 40 deletions generators/app/templates/react/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,61 @@ var http = require('http');

// Below code demonstrates using various methods of testing
describe('Testing Server', function() {
let test_server;
this.timeout(0);

before(function(done){
require(process.cwd() + '/server/server');
setTimeout(done, 5000); // Waiting 5 seconds for server to start
this.timeout(10000);
before(done => {
let app = require(process.cwd() + '/server/server');
test_server = app.listen(process.env.PORT || 3000, done);
});
it('Public endpoint returns "Hello!"', function(done){
var responseString = '';

var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/'
};
it('Public endpoint returns "Hello!"', function(done){
var responseString = '';

var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});
var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/'
};

response.on('end', function () {
expect(responseString).to.include('You need to enable JavaScript to run this app.');
done();
});
};
var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});

http.request(options, callback).end();
});
response.on('end', function () {
expect(responseString).to.include('You need to enable JavaScript to run this app.');
done();
});
};

it('Health endpoint shows status up', function(done){
var responseString = '';
http.request(options, callback).end();
});

it('Health endpoint shows status up', function(done){
var responseString = '';

var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health'
};
var options = {
host: 'localhost',
port: process.env.PORT || 3000,
path: '/health'
};

var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});
var callback = function(response){
response.on('data', function (chunk) {
responseString += chunk;
});

response.on('end', function () {
expect(responseString).to.equal('{"status":"UP"}');
done();
});
};
response.on('end', function () {
expect(responseString).to.equal('{"status":"UP"}');
done();
});
};

http.request(options, callback).end();
});
http.request(options, callback).end();
});

after(done => {
test_server.close(done);
});
});