Skip to content

Commit

Permalink
Merge pull request #1 from PlayNetwork/tests
Browse files Browse the repository at this point in the history
Adding Tests
  • Loading branch information
brozeph committed Aug 15, 2017
2 parents 1817e25 + 3fdf5d1 commit 8c6d531
Show file tree
Hide file tree
Showing 20 changed files with 1,753 additions and 404 deletions.
11 changes: 4 additions & 7 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"presets": [
"es2015",
"stage-0"
],
"plugins": [
"babel-plugin-istanbul"
]
"presets": [
"es2015",
"stage-0"
]
}
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
- 2
- "single"
radix: 2
semi: 2
sort-keys: 2
sort-imports: 2
sort-vars: 2
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DS_Store
/.nyc_output/
/coverage/
/dist/
/node_modules/
/reports/
/npm-debug.log
/.nyc_output/

3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.git/
.nyc_output/
coverage/
examples/
src/
test/
.babelrc
Expand Down
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "4"
- "6"
- "8"
after_success:
- "npm run test:coveralls"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('babel-polyfill');

require('source-map-support/register');

var _dist = require('../../dist');
var _dist = require('../dist');

var ipc = _interopRequireWildcard(_dist);

Expand Down Expand Up @@ -76,7 +76,17 @@ _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
return console.error('error when passing no arguments to client.call: %s', ex.message, ex);
});

case 13:
/**
* call an asynchronous method and wait
* using a Promise
**/
client.call('services.helloDelayed', 'testing').then(function (response) {
return console.log('result when calling asynchronous server method via client.call: %s', response);
}).catch(function (ex) {
return console.error('error when calling asynchronous server method via client.call: %s', ex.message, ex);
});

case 14:
case 'end':
return _context.stop();
}
Expand Down
16 changes: 15 additions & 1 deletion test/examples/client.js → examples/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import 'babel-polyfill';
import 'source-map-support/register';

import * as ipc from '../../dist';
import * as ipc from '../dist';

(async () => {
// create a client for server.js
Expand Down Expand Up @@ -64,4 +64,18 @@ import * as ipc from '../../dist';
'error when passing no arguments to client.call: %s',
ex.message,
ex));

/**
* call an asynchronous method and wait
* using a Promise
**/
client
.call('services.helloDelayed', 'testing')
.then((response) => console.log(
'result when calling asynchronous server method via client.call: %s',
response))
.catch((ex) => console.error(
'error when calling asynchronous server method via client.call: %s',
ex.message,
ex));
})();
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('babel-polyfill');

require('source-map-support/register');

var _dist = require('../../dist');
var _dist = require('../dist');

var ipc = _interopRequireWildcard(_dist);

Expand All @@ -16,10 +16,19 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
* the server. This object can have multiple children
* and unlimited hiearchy.
**/
var services = {
var DELAY = 1000,
services = {
hello: function hello() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'olleh';
return value;
},
helloDelayed: function helloDelayed() {
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'olleh';
return new Promise(function (resolve) {
return setTimeout(function () {
return resolve(value);
}, DELAY);
});
}
};

Expand Down
12 changes: 8 additions & 4 deletions test/examples/server.js → examples/server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import 'babel-polyfill';
import 'source-map-support/register';

import * as ipc from '../../dist';
import * as ipc from '../dist';

/**
* The name of this object will act as a namespace for
* the method argument that is provided when consuming
* the server. This object can have multiple children
* and unlimited hiearchy.
**/
const services = {
hello : (value = 'olleh') => value
};
const
DELAY = 1000,
services = {
hello : (value = 'olleh') => value,
helloDelayed : (value = 'olleh') =>
new Promise((resolve) => setTimeout(() => resolve(value), DELAY))
};

const server = new ipc.Server(
'/tmp/example-ipc-server.sock',
Expand Down
5 changes: 0 additions & 5 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import del from 'del';
import eslint from 'gulp-eslint';
import gulp from 'gulp';
import sourcemaps from 'gulp-sourcemaps';
import util from 'gulp-util';

module.exports = (() => {
'use strict';

gulp.task('build', ['clean-build'], () => {
return gulp
.src('src/**/*.js')
Expand All @@ -21,8 +18,6 @@ module.exports = (() => {

gulp.task('clean-build', () => del('dist'));

gulp.task('clean-reports', () => del('reports'));

gulp.task('lint', () => {
return gulp
.src(['src/**/*.js', 'test/**/*.js', '!node_modules/**', '!reports/**', '!test/examples/*transpiled.js'])
Expand Down
Loading

0 comments on commit 8c6d531

Please sign in to comment.