Skip to content

Commit

Permalink
Merge pull request #490 from senecajs/tests
Browse files Browse the repository at this point in the history
3.0 Test and Repo Pretidy
  • Loading branch information
mcdonnelldean committed Aug 22, 2016
2 parents 3da79d7 + 23c1df7 commit 2140c5e
Show file tree
Hide file tree
Showing 103 changed files with 239 additions and 1,192 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
@@ -1,4 +1,4 @@
node_modules
docs

test/plugin/bad-syntax-plugin.js
test/stubs/plugin/bad-syntax-plugin.js
11 changes: 5 additions & 6 deletions .gitignore
@@ -1,18 +1,17 @@
*~
.DS_Store
docs/annotated
test/db
.idea
*.old
*.bak
*.tmp
*.log
node_modules*
README.html
*.off
*-off
npm-debug.log
mem.json
out
coverage.html
.idea
tmp
test/db
node_modules
docs/annotated
docs/coverage.html
20 changes: 5 additions & 15 deletions .travis.yml
@@ -1,6 +1,5 @@
language: node_js
sudo: false
cache: false

node_js:
- '4'
Expand All @@ -9,26 +8,17 @@ node_js:

env:
global:
# get the latest seneca code from master
# get the latest seneca code from master,
# to test a specific tagged version set the version like below.
- SENECA_VER=
# to test a specific tagged version set the version like the following:
# - SENECA_VER=#v1.3.0
# - SENECA_VER=#v1.3.0

matrix:
- TEST_SUITE=senecajs/seneca

# Golden Circle plugins to test
- TEST_SUITE=senecajs/gate-executor
- TEST_SUITE=senecajs/seneca-entity
- TEST_SUITE=senecajs/seneca-user
# - TEST_SUITE=senecajs/seneca-web
# - TEST_SUITE=senecajs/seneca-repl
# - TEST_SUITE=senecajs/seneca-store-test
# - TEST_SUITE=senecajs/seneca-mem-store
# - TEST_SUITE=senecajs/seneca-redis-store
# - TEST_SUITE=rjrodger/seneca-transport-test
# - TEST_SUITE=senecajs/seneca-transport
# - TEST_SUITE=rjrodger/seneca-balance-client
# - TEST_SUITE=rjrodger/seneca-mesh
- TEST_SUITE=senecajs/seneca-transport

before_script:
- TEST_SUITE_FOLDER=$(basename $TEST_SUITE)
Expand Down
157 changes: 115 additions & 42 deletions README.md
Expand Up @@ -48,24 +48,101 @@ Seneca's source can be read in an annotated fashion by running `npm run annotate
annotated version of each file will be generated in `./docs/`.

## Install
To install, simply use npm.
To install via npm,

```
npm install seneca
```

## Test
To run tests, simply use npm:
To run tests locally,

```
npm run test
```

### Coverage
To obtain a coverage report run,
To obtain a coverage report,

```
npm run coverage; open coverage.html
npm run coverage; open docs/coverage.html
```

## Quick Example

```js
'use strict'

var Seneca = require('seneca')


// Functionality in seneca is composed into simple
// plugins that can be loaded into seneca instances.


function rejector () {
this.add('cmd:run', (msg, done) => {
return done(null, {tag: 'rejector'})
})
}

function approver () {
this.add('cmd:run', (msg, done) => {
return done(null, {tag: 'approver'})
})
}

function local () {
this.add('cmd:run', function (msg, done) {
this.prior(msg, (err, reply) => {
return done(null, {tag: reply ? reply.tag : 'local'})
})
})
}


// Services can listen for messages using a variety of
// transports. In process and http are included by default.


Seneca()
.use(approver)
.listen({type: 'http', port: '8260', pin: 'cmd:*'})

Seneca()
.use(rejector)
.listen(8270)


// Load order is important, messages can be routed
// to other services or handled locally. Pins are
// basically filters over messages


function handler (err, reply) {
console.log(err, reply)
}

Seneca()
.use(local)
.act('cmd:run', handler)

Seneca()
.client({port: 8270, pin: 'cmd:run'})
.client({port: 8260, pin: 'cmd:run'})
.use(local)
.act('cmd:run', handler)

Seneca()
.client({port: 8260, pin: 'cmd:run'})
.client({port: 8270, pin: 'cmd:run'})
.use(local)
.act('cmd:run', handler)


// Output
// null { tag: 'local' }
// null { tag: 'approver' }
// null { tag: 'rejector' }
```


Expand All @@ -85,13 +162,13 @@ Here's an example:
```javascript
var seneca = require('seneca')()

seneca.add({ cmd: 'salestax' }, function (args, callback) {
seneca.add({cmd: 'salestax'}, function (msg, done) {
var rate = 0.23
var total = args.net * (1 + rate)
callback(null, { total: total })
var total = msg.net * (1 + rate)
done(null, {total: total})
})

seneca.act({ cmd: 'salestax', net: 100 }, function (err, result) {
seneca.act({cmd: 'salestax', net: 100}, function (err, result) {
console.log(result.total)
})
```
Expand All @@ -109,23 +186,21 @@ The `seneca.act` method accepts an object, and runs the command, if any, that ma
Where does the sales tax rate come from? Let's try it again:

```js
seneca.add({ cmd: 'config' }, function (args, callback) {
var config = {
rate: 0.23
}
var value = config[args.prop]
callback(null, { value: value })
seneca.add({cmd: 'config'}, function (msg, done) {
var config = {rate: 0.23}
var value = config[msg.prop]
done(null, {value: value})
})

seneca.add({ cmd: 'salestax' }, function (args, callback) {
seneca.act({ cmd: 'config', prop: 'rate' }, function (err, result) {
seneca.add({cmd: 'salestax'}, function (msg, done) {
seneca.act({cmd: 'config', prop: 'rate'}, function (err, result) {
var rate = parseFloat(result.value)
var total = args.net * (1 + rate)
callback(null, { total: total })
var total = msg.net * (1 + rate)
done(null, {total: total})
})
})

seneca.act({ cmd: 'salestax', net: 100 }, function (err, result) {
seneca.act({cmd: 'salestax', net: 100}, function (err, result) {
console.log(result.total)
})
```
Expand All @@ -145,11 +220,11 @@ seneca.act('cmd:salestax,net:100', function (err, result) {
```

Instead of providing an object, you can provide a string using an
[abbreviated form] of JSON[Jsonic]. In fact, you
[abbreviated form][Jsonic] of JSON. In fact, you
can provide both:

```javascript
seneca.act('cmd:salestax', { net: 100 }, function (err, result) {
seneca.act('cmd:salestax', {net: 100}, function (err, result) {
console.log(result.total)
})
```
Expand All @@ -166,12 +241,10 @@ Seneca makes this really easy. Let's put configuration out on the
network into its own process:

```javascript
seneca.add({ cmd: 'config' }, function (args, callback) {
var config = {
rate: 0.23
}
var value = config[args.prop]
callback(null, { value: value })
seneca.add({cmd: 'config'}, function (msg, done) {
var config = {rate: 0.23}
var value = config[msg.prop]
done(null, { value: value })
})

seneca.listen()
Expand All @@ -189,11 +262,11 @@ The client code looks like this:


```javascript
seneca.add({ cmd: 'salestax' }, function (args, callback) {
seneca.add({cmd: 'salestax'}, function (msg, done) {
seneca.act({cmd: 'config', prop: 'rate' }, function (err, result) {
var rate = parseFloat(result.value)
var total = args.net * (1 + rate)
callback(null, { total: total })
var total = msg.net * (1 + rate)
done(null, { total: total })
})
})

Expand Down Expand Up @@ -227,36 +300,36 @@ Here's the code. We'll rip out the configuration code for this example.

```javascript
// fixed rate
seneca.add({ cmd: 'salestax' }, function (args, callback) {
seneca.add({cmd: 'salestax'}, function (msg, done) {
var rate = 0.23
var total = args.net * (1 + rate)
callback(null, { total: total })
var total = msg.net * (1 + rate)
done(null, { total: total })
})


// local rates
seneca.add({ cmd: 'salestax', country: 'US' }, function (args, callback) {
seneca.add({cmd: 'salestax', country: 'US'}, function (msg, done) {
var state = {
'NY': 0.04,
'CA': 0.0625
// ...
}
var rate = state[args.state]
var total = args.net * (1 + rate)
callback(null, { total: total })
var rate = state[msg.state]
var total = msg.net * (1 + rate)
done(null, {total: total})
})


// categories
seneca.add({ cmd: 'salestax', country: 'IE' }, function (args, callback) {
seneca.add({ cmd: 'salestax', country: 'IE' }, function (msg, done) {
var category = {
'top': 0.23,
'reduced': 0.135
// ...
}
var rate = category[args.category]
var total = args.net * (1 + rate)
callback(null, { total: total })
var rate = category[msg.category]
var total = msg.net * (1 + rate)
done(null, { total: total })
})


Expand Down
13 changes: 13 additions & 0 deletions docs/create-a-release.md
@@ -0,0 +1,13 @@
# Creating a release

1. Ensure all deps in node_modules installable from npm.
2. Update CHANGES.md, with date release, notes, and version.
3. Review github issues, close and triage issues related to the release.
4. Make sure you have a clean branch: git checkout -b release upstream/master
5. Run `npm version v0.0.0 -m "version 0.0.0"` with the version number replacing 0.0.0
6. Run `git push upstream master`
7. Run `git push upstream --tags`
8. Run `npm publish`
9. Run `npm tag seneca@VERSION next`
10. Run `npm tag seneca@VERSION plugin`
11. Update and publish plugins

0 comments on commit 2140c5e

Please sign in to comment.