Skip to content

Commit

Permalink
Merge c819f29 into 035cfc9
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Nov 17, 2017
2 parents 035cfc9 + c819f29 commit f35cc67
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 186 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
coverage
package-lock.json
node_modules
build
dist
out
*.log
*.dump
.DS_Store
Expand Down
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
coverage
node_modules
build
tests
Expand Down
2 changes: 1 addition & 1 deletion doc/README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
[![bithound](https://www.bithound.io/github/Kronos-Integration/kronos-service-koa/badges/score.svg)](https://www.bithound.io/github/Kronos-Integration/kronos-service-koa)
[![codecov.io](http://codecov.io/github/Kronos-Integration/kronos-service-koa/coverage.svg?branch=master)](http://codecov.io/github/Kronos-Integration/kronos-service-koa?branch=master)
[![Coverage Status](https://coveralls.io/repos/Kronos-Integration/kronos-service-koa/badge.svg)](https://coveralls.io/r/Kronos-Integration/kronos-service-koa)
[![Code Climate](https://codeclimate.com/github/Kronos-Integration/kronos-service-koa/badges/gpa.svg)](https://codeclimate.com/github/Kronos-Integration/kronos-service-koa)
[![Known Vulnerabilities](https://snyk.io/test/github/Kronos-Integration/kronos-service-koa/badge.svg)](https://snyk.io/test/github/Kronos-Integration/kronos-service-koa)
[![GitHub Issues](https://img.shields.io/github/issues/Kronos-Integration/kronos-service-koa.svg?style=flat-square)](https://github.com/Kronos-Integration/kronos-service-koa/issues)
[![Stories in Ready](https://badge.waffle.io/Kronos-Integration/kronos-service-koa.svg?label=ready&title=Ready)](http://waffle.io/Kronos-Integration/kronos-service-koa)
[![Dependency Status](https://david-dm.org/Kronos-Integration/kronos-service-koa.svg)](https://david-dm.org/Kronos-Integration/kronos-service-koa)
[![devDependency Status](https://david-dm.org/Kronos-Integration/kronos-service-koa/dev-status.svg)](https://david-dm.org/Kronos-Integration/kronos-service-koa#info=devDependencies)
[![docs](http://inch-ci.org/github/Kronos-Integration/kronos-service-koa.svg?branch=master)](http://inch-ci.org/github/Kronos-Integration/kronos-service-koa)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![downloads](http://img.shields.io/npm/dm/kronos-service-koa.svg?style=flat-square)](https://npmjs.org/package/kronos-service-koa)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

Expand Down
10 changes: 10 additions & 0 deletions doc/jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
"node_modules/jsdoc-babel"
],
"babel": {
"presets": [
"env"
]
}
}
52 changes: 28 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
"name": "kronos-service-koa",
"version": "0.0.0-semantic-release",
"description": "koa backed http server",
"keywords": [
"kronos-service"
],
"main": "dist/module.js",
"module": "src/ServiceKOA.js",
"keywords": ["kronos-service"],
"main": "dist/service-koa.js",
"module": "src/service-koa.js",
"scripts": {
"cover": "nyc --temp-directory build/nyc npm test",
"test": "mocha tests/*-test.js",
"cover": "nyc --temp-directory build/nyc ava",
"test": "ava",
"semantic-release": "semantic-release",
"docs": "jsdoc2md -l off -t doc/README.hbs -f src/*.js >README.md",
"pretest": "rollup -c",
"posttest": "markdown-doctest",
"precover": "rollup -c",
"docs":
"jsdoc2md --configure doc/jsdoc.json -l off -t doc/README.hbs -f src/*.js >README.md",
"pretest": "rollup -c tests/rollup.config.js",
"posttest": "npm run prepare && markdown-doctest",
"precover": "rollup -c tests/rollup.config.js",
"prepare": "rollup -c"
},
"repository": {
Expand All @@ -35,17 +34,21 @@
"ws": "^3.1.0"
},
"devDependencies": {
"chai": "^4.1.2",
"koa-route": "^3.2.0",
"mocha": "^3.5.3",
"network-address": "^1.1.2",
"semantic-release": "^9.1.1",
"supertest": "^3.0.0",
"supertest-as-promised": "^4.0.2",
"jsdoc-to-markdown": "^3.0.1",
"jsdoc-to-markdown": "^3.0.2",
"markdown-doctest": "^0.9.1",
"rollup": "^0.51.5",
"nyc": "^11.3.0"
"rollup": "^0.51.7",
"nyc": "^11.3.0",
"jsdoc-babel": "^0.3.0",
"ava": "^0.23.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-multi-entry": "^2.0.2",
"babel-preset-env": "^1.6.1",
"xo": "^0.19.0"
},
"contributors": [
{
Expand All @@ -62,20 +65,21 @@
"node": ">=8.9.1"
},
"nyc": {
"include": [
"dist/**/*.js"
],
"reporter": [
"lcov"
],
"report-dir": "./coverage"
"include": ["build/*-test.js", "src/**/*.js"],
"reporter": ["lcov"],
"report-dir": "./build/coverage"
},
"template": {
"repository": {
"url": "https://github.com/Kronos-Tools/npm-package-template.git"
"url": "https://github.com/arlac77/npm-package-template.git"
}
},
"xo": {
"space": true
},
"ava": {
"files": ["build/*-test.js"],
"presets": ["env"],
"require": ["babel-register"]
}
}
13 changes: 4 additions & 9 deletions src/ServiceKOA.js → src/service-koa.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* jslint node: true, esnext: true */
'use strict';

const http = require('http'),
https = require('https'),
url = require('url'),
Expand All @@ -16,7 +13,7 @@ import { mergeAttributes, createAttributes } from 'model-attributes';
/**
* HTTP server with koa
*/
class ServiceKOA extends Service {
export class ServiceKOA extends Service {
static get name() {
return 'koa';
}
Expand Down Expand Up @@ -315,7 +312,7 @@ function decode(val) {
/**
* Endpoint to link against a koa route
*/
class RouteSendEndpoint extends SendEndpoint {
export class RouteSendEndpoint extends SendEndpoint {
/**
* @param name {String} endpoint name
* @param owner {Step} the owner of the endpoint
Expand Down Expand Up @@ -410,7 +407,7 @@ class RouteSendEndpoint extends SendEndpoint {
}
}

class SocketEndpoint extends SendEndpoint {
export class SocketEndpoint extends SendEndpoint {
constructor(name, owner, path) {
super(name, owner, {
createOpposite: true
Expand Down Expand Up @@ -475,8 +472,6 @@ class SocketEndpoint extends SendEndpoint {
}
}

function registerWithManager(manager) {
export function registerWithManager(manager) {
return manager.registerServiceFactory(ServiceKOA);
}

export { registerWithManager, ServiceKOA, RouteSendEndpoint, SocketEndpoint };
59 changes: 28 additions & 31 deletions tests/failure-test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
/* global describe, it, xit, before, beforeEach, after, afterEach */
/* jslint node: true, esnext: true */

'use strict';

const chai = require('chai'),
assert = chai.assert,
expect = chai.expect,
should = chai.should(),
{
ServiceProviderMixin, Service
} = require('kronos-service'),
{
ServiceKOA
} = require('../dist/module');
import { ServiceProviderMixin, Service } from 'kronos-service';
import { ServiceKOA } from '../src/service-koa';
import test from 'ava';

class ServiceProvider extends ServiceProviderMixin(Service) {}

const sp = new ServiceProvider();

describe('service-koa failures', () => {
describe('with already in use port', () => {
const ks1 = new ServiceKOA({
test('service-koa failures with already in use port', async t => {
const ks1 = new ServiceKOA(
{
name: 'my-name1',
listen: { 
listen: {
port: 1235
}
}, sp);
},
sp
);

const ks2 = new ServiceKOA({
const ks2 = new ServiceKOA(
{
name: 'my-name2',
listen: { 
listen: {
port: 1235
}
}, sp);

it('can start', () => {
ks1.start().then(() => ks2.start().then(() => {
assert.equal(ks1.state, 'running');
assert.equal(ks2.state, 'running');
}));
});
});
},
sp
);

await ks1.start();
t.is(ks1.state, 'running');

try {
await ks2.start();
} catch (e) {}

t.is(ks2.state, 'failed');

ks1.stop();
ks2.stop();
});
12 changes: 12 additions & 0 deletions tests/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import multiEntry from 'rollup-plugin-multi-entry';

export default {
input: 'tests/**/*-test.js',
output: {
file: 'build/bundle-test.js',
format: 'cjs',
sourcemap: true
},
external: ['ava', 'model-attributes', 'kronos-service', 'kronos-endpoint'],
plugins: [multiEntry()]
};
101 changes: 55 additions & 46 deletions tests/simple-test.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,72 @@
/* global describe, it, xit, before, beforeEach, after, afterEach */
/* jslint node: true, esnext: true */

'use strict';

const chai = require('chai'),
assert = chai.assert,
expect = chai.expect,
should = chai.should(),
fs = require('fs'),
path = require('path'),
address = require('network-address'),
request = require('supertest-as-promised')(Promise),
route = require('koa-route'),
{
ServiceProviderMixin, Service
} = require('kronos-service'),
{
ServiceKOA
} = require('../dist/module');
const fs = require('fs');
const path = require('path');
const address = require('network-address');
const request = require('supertest-as-promised')(Promise);
const route = require('koa-route');

class ServiceProvider extends ServiceProviderMixin(Service) {}
import { ServiceProviderMixin, Service } from 'kronos-service';
import { ServiceKOA } from '../src/service-koa';
import test from 'ava';

const sp = new ServiceProvider();
class ServiceProvider extends ServiceProviderMixin(Service) {}

describe('service-koa', () => {
describe('plain http', () => {
const ks = new ServiceKOA({
test('service-koa plain http', t => {
const sp = new ServiceProvider();
const ks = new ServiceKOA(
{
type: 'xxx',
name: 'my-name',
listen: {
port: 1234,
address: address()
}
}, sp);
},
sp
);

it('has name', () => assert.equal(ks.name, 'my-name'));
it('is not secure', () => assert.equal(ks.isSecure, false));
t.is(ks.name, 'my-name');
t.is(ks.isSecure, false);

it('has port', () => assert.equal(ks.port, 1234));
t.is(ks.port, 1234);

it('has address', () => assert.equal(ks.address, address()));
it('has url', () => assert.equal(ks.url, `http://${address()}:1234`));
t.is(ks.address, address());
t.is(ks.url, `http://${address()}:1234`);

it('has server timeout', () => assert.equal(ks.timeout.server, 120));
t.is(ks.timeout.server, 120);
});

describe('configure', () => {
it('can change port', () =>
ks.configure({
listen: {
port: 1235
}
}).then(() => assert.equal(ks.listen.port, 1235)));
test('service-koa plain http change port', async t => {
const sp = new ServiceProvider();
const ks = new ServiceKOA(
{
type: 'xxx',
name: 'my-name',
listen: {
port: 1234,
address: address()
}
},
sp
);

it('can change timeout', () =>
ks.configure({
timeout: {
server: 123.45
}
}).then(() => assert.equal(ks.timeout.server, 123.45)));
});
await ks.configure({
listen: {
port: 1235
}
});

t.is(ks.listen.port, 1235);

await ks.configure({
timeout: {
server: 123.45
}
});

t.is(ks.timeout.server, 123.45);
});

/*
it('GET /', () =>
ks.start().then(() => {
ks.koa.use(route.get('/', ctx => ctx.body = 'OK'));
Expand Down Expand Up @@ -121,3 +128,5 @@ describe('service-koa', () => {
}));
});
});
*/
Loading

0 comments on commit f35cc67

Please sign in to comment.