diff --git a/.eslintignore b/.eslintignore index 5c0012b9..4db07bb2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,4 @@ node_modules docs -test/plugin/bad-syntax-plugin.js +test/stubs/plugin/bad-syntax-plugin.js diff --git a/.gitignore b/.gitignore index a6b72f83..013565ae 100644 --- a/.gitignore +++ b/.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 diff --git a/.travis.yml b/.travis.yml index 69fbf783..f25f97a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js sudo: false -cache: false node_js: - '4' @@ -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) diff --git a/README.md b/README.md index 77ba5f3e..236e82ce 100644 --- a/README.md +++ b/README.md @@ -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' } ``` @@ -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) }) ``` @@ -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) }) ``` @@ -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) }) ``` @@ -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() @@ -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 }) }) }) @@ -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 }) }) diff --git a/docs/create-a-release.md b/docs/create-a-release.md new file mode 100644 index 00000000..32fa89fd --- /dev/null +++ b/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 diff --git a/docs/examples/basics-transport.js b/docs/examples/basics-transport.js deleted file mode 100644 index 60f3255a..00000000 --- a/docs/examples/basics-transport.js +++ /dev/null @@ -1,106 +0,0 @@ -'use strict' - -// Using seneca's transport mechanism enables you to split -// business logic into discrete microservices. Features like -// priors work over the network as does load behaviour. See -// it in action below. - -var Seneca = require('../..') -var Assert = require('assert') - -// Some variables so we can Assert things are -//happening in the order we expect them too. -var index = 0 -var tags = [ - 'none', - 'approver', - 'rejector' -] - -// Our little reusable business logic is basically a factory -// that returns a method with the same signature as seneca.add. -// Each business logic factory echos it's tag when called. -function businessLogic (tag) { - return function (msg, done) { - return done(null, {tag: tag}) - } -} - - -// Our 'local' plugin will always handle the message first -// because we load it last. But it also uses a prior to see -// if anyone else before it handles the message. -function local (msg, done) { - this.prior(msg, (err, reply) => { - return done(null, {tag: reply ? reply.tag : 'none'}) - }) -} - - -// Our logger makes order assertions and prints -// the result of each of the 3 calls we make. -function logger (err, reply) { - Assert(!err) - Assert(reply.tag == tags[index]) - index++ - - console.log(reply) -} - - -// Our first server is set up to emit 'approver' when -// it is called. It shows how to explicitly set listener -// options. This micrservice 'listens' on http for `cmd:*`. -Seneca() - .add('cmd:run', businessLogic('approver')) - .listen({type: 'http', port: '8260', pin: 'cmd:*'}) - - -// Our sencond service is set up to emit 'rejector' when -// it is called. This service only specifies the port. It -// is provided defaults of http for type and * for pin. -Seneca() - .add('cmd:run', businessLogic('rejector')) - .listen(8270) - - -// Our first tester runs only the local plugin. The expected -// result is 'none' as it is the default for the local plugin. -Seneca() - .add('cmd:run', local) - .act('cmd:run', logger) - - -// Our second tester runs the local plugin and makes two client -// connections (defaulted to http). Clients follow load order, -// as such local is first called which then uses prior to call -// to the 'approver' service which prints 'approver'. -Seneca() - .client({port: 8270, pin: 'cmd:run'}) - .client({port: 8260, pin: 'cmd:run'}) - .add('cmd:run', local) - .act('cmd:run', logger) - -// Out last tester runs the reverse of the one appove. This -// changes the prior selected which prints 'rejector' instead. -Seneca() - .client({port: 8260, pin: 'cmd:run'}) - .client({port: 8270, pin: 'cmd:run'}) - .add('cmd:run', local) - .act('cmd:run', logger) - - -// An important point to note. Why didn't prior fire a second time -// in each instance? This is because prior only affects the first -// client. Since the second call in each instance hits a server with -// no local prior, the chain is satisfied. - - -// Auto stop our test after half a second. -setTimeout(() => {process.exit()}, 500) - - -// Prints -// { businessLogic: 'none' } -// { businessLogic: 'approver' } -// { businessLogic: 'rejector' } diff --git a/docs/examples/basics-custom-logger.js b/docs/examples/custom-logger.js similarity index 100% rename from docs/examples/basics-custom-logger.js rename to docs/examples/custom-logger.js diff --git a/docs/examples/basics-decoration.js b/docs/examples/decoration.js similarity index 100% rename from docs/examples/basics-decoration.js rename to docs/examples/decoration.js diff --git a/docs/examples/basics-load-order.js b/docs/examples/load-order.js similarity index 100% rename from docs/examples/basics-load-order.js rename to docs/examples/load-order.js diff --git a/docs/examples/quick-example.js b/docs/examples/quick-example.js new file mode 100644 index 00000000..81eb182c --- /dev/null +++ b/docs/examples/quick-example.js @@ -0,0 +1,73 @@ +'use strict' + +var Seneca = require('../../') + + +// 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' } diff --git a/docs/examples/README.txt b/docs/examples/sales-tax/README.txt similarity index 100% rename from docs/examples/README.txt rename to docs/examples/sales-tax/README.txt diff --git a/docs/examples/sales-tax-app-client.js b/docs/examples/sales-tax/sales-tax-app-client.js similarity index 100% rename from docs/examples/sales-tax-app-client.js rename to docs/examples/sales-tax/sales-tax-app-client.js diff --git a/docs/examples/sales-tax-app.js b/docs/examples/sales-tax/sales-tax-app.js similarity index 100% rename from docs/examples/sales-tax-app.js rename to docs/examples/sales-tax/sales-tax-app.js diff --git a/docs/examples/sales-tax-client.js b/docs/examples/sales-tax/sales-tax-client.js similarity index 100% rename from docs/examples/sales-tax-client.js rename to docs/examples/sales-tax/sales-tax-client.js diff --git a/docs/examples/sales-tax-complex.js b/docs/examples/sales-tax/sales-tax-complex.js similarity index 100% rename from docs/examples/sales-tax-complex.js rename to docs/examples/sales-tax/sales-tax-complex.js diff --git a/docs/examples/sales-tax-config.js b/docs/examples/sales-tax/sales-tax-config.js similarity index 100% rename from docs/examples/sales-tax-config.js rename to docs/examples/sales-tax/sales-tax-config.js diff --git a/docs/examples/sales-tax-error.js b/docs/examples/sales-tax/sales-tax-error.js similarity index 100% rename from docs/examples/sales-tax-error.js rename to docs/examples/sales-tax/sales-tax-error.js diff --git a/docs/examples/sales-tax-log-handler.js b/docs/examples/sales-tax/sales-tax-log-handler.js similarity index 100% rename from docs/examples/sales-tax-log-handler.js rename to docs/examples/sales-tax/sales-tax-log-handler.js diff --git a/docs/examples/sales-tax-log.js b/docs/examples/sales-tax/sales-tax-log.js similarity index 100% rename from docs/examples/sales-tax-log.js rename to docs/examples/sales-tax/sales-tax-log.js diff --git a/docs/examples/sales-tax-logentries.js b/docs/examples/sales-tax/sales-tax-logentries.js similarity index 100% rename from docs/examples/sales-tax-logentries.js rename to docs/examples/sales-tax/sales-tax-logentries.js diff --git a/docs/examples/sales-tax-plugin.js b/docs/examples/sales-tax/sales-tax-plugin.js similarity index 100% rename from docs/examples/sales-tax-plugin.js rename to docs/examples/sales-tax/sales-tax-plugin.js diff --git a/docs/examples/sales-tax.js b/docs/examples/sales-tax/sales-tax.js similarity index 100% rename from docs/examples/sales-tax.js rename to docs/examples/sales-tax/sales-tax.js diff --git a/docs/examples/testrun.correct b/docs/examples/sales-tax/testrun.correct similarity index 100% rename from docs/examples/testrun.correct rename to docs/examples/sales-tax/testrun.correct diff --git a/docs/examples/testrun.sh b/docs/examples/sales-tax/testrun.sh similarity index 100% rename from docs/examples/testrun.sh rename to docs/examples/sales-tax/testrun.sh diff --git a/docs/transport.md b/docs/msg-transport-protocol.md similarity index 100% rename from docs/transport.md rename to docs/msg-transport-protocol.md diff --git a/docs/release.txt b/docs/release.txt deleted file mode 100644 index 7990d234..00000000 --- a/docs/release.txt +++ /dev/null @@ -1,12 +0,0 @@ -0. Ensure all deps in node_modules installable from npm -1. Update CHANGES.md, date release -2. Review github issues -3. Make sure you have a clean branch: git checkout -b release upstream/master -3. run prerelease.sh -4. run `npm version v0.0.0 -m "version 0.0.0"` with the version number replacing 0.0.0 -5. git push upstream master -6. git push upstream --tags -7. npm publish -8. npm tag seneca@VERSION next -9. npm tag seneca@VERSION plugin -10. update and publish plugins diff --git a/lib/legacy.js b/lib/legacy.js index 5337285f..bbea9291 100644 --- a/lib/legacy.js +++ b/lib/legacy.js @@ -1,11 +1,8 @@ /* Copyright (c) 2010-2016 Richard Rodger and other contributors, MIT License */ 'use strict' -var Fs = require('fs') - var _ = require('lodash') var Eraro = require('eraro') -var Jsonic = require('jsonic') var Common = require('./common') var Errors = require('./errors') @@ -54,173 +51,3 @@ exports.fail = function make_legacy_fail (so) { return err } } - - -// handlers and parse_command_line to be removed in Seneca 3.x - -var handlers = exports.loghandler = {} - -var start_time = Date.now() - -handlers.pretty = function () { - var args = arrayify(arguments) - if (_.isString(args[2])) { - args[2] = args[2].toUpperCase() - } - - if (args[0].short$) { - args[0] = '' + (args[0].getTime() - start_time) - args[0] = ' '.substring(0, 8 - args[0].length) + args[0] - } - - var argstrs = [] - args.forEach(function (a) { - var pstr = (a === null) ? a - : typeof (a) === 'string' ? a - : _.isDate(a) ? (a.toISOString()) - : _.isObject(a) ? Jsonic.stringify(a) : a - - argstrs.push(pstr) - }) - - return argstrs -} - -handlers.silent = function silent () { - // does nothing! -} - -handlers.print = function print () { - var arr = handlers.pretty.apply(null, arrayify(arguments)) - console.log([arr.slice(0, 3).join(' ')].concat(arr.slice(3)).join('\t')) -} - -handlers.stream = function stream (outstream, opts) { - opts = opts || {} - return function () { - var args = arrayify(arguments) - outstream.write(opts.format === 'json' - ? JSON.stringify(args) + '\n' - : handlers.pretty.apply(null, args).join('\t') + '\n') - } -} - -handlers.emitter = function emitter (outemitter) { - return function () { - var args = arrayify(arguments) - outemitter.emit('log', args) - } -} - -handlers.file = function file (filepath, opts) { - opts = opts || {} - var ws = Fs.createWriteStream(filepath, {flags: opts.flags || 'a'}) - return handlers.stream(ws, opts) -} - - -function parse_command_line (spec, logspec, flags) { - flags = flags || {} - - var logmaps = logspec.map - - if (flags.shortcut) { - if (spec === 'short' || spec.short === true) { - logspec.short = true - if (!logmaps.length) { - logmaps.push({ level: 'info+', handler: 'print' }) - } - } - - var shortentries = logging_shortcut(spec) - - if (shortentries.length) { - shortentries.forEach(function (shortentry) { - logmaps.push(shortentry) - }) - return - } - } - - if (_.isArray(spec)) { - spec.forEach(function (specentry) { - parse_command_line(specentry, logspec) - }) - return - } - - // parse: level=,type=,plugin=,tag=,case=,handler= - // handler can be print,file:path - - var keys = { level: 1, type: 1, plugin: 1, tag: 1, 'case': 1, - handler: 1, regex: 1, pin: 1, act: 1 } - var entry = {} - var parts = ('' + spec).split(',') - _.each(parts, function (part) { - var kvm = part.match(/^(.*?):(.*)$/) - var kv = kvm ? [kvm[1], kvm[2]] : [''] - - if (kv[0].length) { - var key = kv[0] - if (key === 'handler') { - var handler = kv.slice(1).join(':') - var m - if (handler === 'print') { - entry[key] = handlers.print - } - else if ((m = /^file:(\/\/)?(.*)$/.exec(handler))) { - entry[key] = handlers.file(m[2]) - } - } - else if (keys[key]) { - if (entry[key]) { - entry[key] += ',' + kv[1] - } - else { - entry[key] = kv[1] - } - } - } - }) - - if (_.keys(entry).length) { - // print by default - if (entry && !entry.handler) { - entry.handler = handlers.print - } - - logmaps.push(entry) - } -} - -exports.parse_command_line = parse_command_line - - -function logging_shortcut (spec) { - if (spec && (spec.print === true || - spec.all === true || - spec === 'print' || - spec === 'all')) { - return [{ level: 'all', handler: handlers.print }] - } - else if (spec && - (spec.quiet || - spec === 'quiet' || - spec.silent || - spec === 'silent')) { - return [] - } - else if (spec === 'test') { - return [{ level: 'error+', handler: handlers.print }] - } - else if (spec === 'standard') { - return [{ level: 'info+', handler: handlers.print }] - } - else if (_.isString(spec)) { - var logspec = {map: []} - parse_command_line(spec, logspec, {shortcut: false}) - return logspec.map - } - else return [] -} - diff --git a/lib/optioner.js b/lib/optioner.js index 28de31b1..6966f0cb 100644 --- a/lib/optioner.js +++ b/lib/optioner.js @@ -48,14 +48,6 @@ module.exports = function (callmodule, defaults) { // Runtime options - if (process.env.SENECA_LOG) { - sourcemap.env.log = sourcemap.env.log || {} - sourcemap.env.log.map = sourcemap.env.log.map || [] - Legacy.parse_command_line(process.env.SENECA_LOG, - sourcemap.env.log, - {shortcut: true}) - } - if (process.env.SENECA_OPTIONS) { sourcemap.env = Common.deepextend({}, sourcemap.env, Jsonic(process.env.SENECA_OPTIONS)) diff --git a/package.json b/package.json index 852eaf40..5cb2aeb3 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "gate-executor": "1.0.0", "gex": "0.2.2", "jsonic": "0.2.2", - "lodash": "4.14.2", + "lodash": "4.15.0", "lru-cache": "4.0.1", "minimist": "1.2.0", "nid": "0.3.2", @@ -88,7 +88,7 @@ "scripts": { "test": "lab -v -P test -L -t 80", "coveralls": "lab -s -P test -r lcov | coveralls", - "coverage": "lab -v -P test -L -t 80 -r html > coverage.html", + "coverage": "lab -v -P test -L -t 80 -r html > docs/coverage.html", "annotate": "docco seneca.js lib/*.js -o docs/annotated" }, "devDependencies": { @@ -105,8 +105,6 @@ "eslint-plugin-standard": "2.x.x", "joi": "9.0.x", "lab": "11.0.x", - "no-shadow-relaxed": "1.0.x", - "seneca-echo": "0.3.x", "seneca-entity": "1.2.x", "seneca-error-test": "0.2.x" } diff --git a/prerelease.sh b/prerelease.sh deleted file mode 100755 index e5331da9..00000000 --- a/prerelease.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env bash - -PWD=$(pwd -L) - -rm -rf node_modules -npm install -npm link - -sh ./test/test-included-plugins.sh -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -npm test -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -cd doc/examples -sh ./testrun.sh -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -cd ../.. - -# setup test folder -cd .. -mkdir -p test-seneca -TEST_PWD=$(pwd -L) -cd test-seneca - -# run seneca-verify -rm -rf seneca-verify -git clone git@github.com:rjrodger/seneca-verify.git -cd seneca-verify -npm link seneca -npm install -node verify -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -# run seneca-mvp -cd .. -rm -rf seneca-mvp -git clone git@github.com:rjrodger/seneca-mvp.git -cd seneca-mvp -cp options.example.js options.mine.js -npm link seneca -npm install -npm install bower -cd public -node ../node_modules/.bin/bower install -cd .. -node mvp-app.js -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -# run seneca-examples -cd .. -rm -rf seneca-examples -git clone git@github.com:rjrodger/seneca-examples.git -cd seneca-examples/micro-services -npm link seneca -npm install -node . -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -# test level store -cd .. -rm -rf seneca-level-store -git clone git@github.com:senecajs/seneca-level-store.git -cd seneca-level-store -npm link seneca -npm install -npm test -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - - -# test mem store -cd .. -rm -rf seneca-mem-store -git clone git@github.com:senecajs/seneca-mem-store.git -cd seneca-mem-store -npm link seneca -npm install -npm test -ec=$?; if [[ $ec != 0 ]]; then exit $ec; fi - -# cleanup -rm -rf $TEST_PWD -cd $PWD diff --git a/test/actions.test.js b/test/actions.test.js index 447bd7d8..6c28d52f 100644 --- a/test/actions.test.js +++ b/test/actions.test.js @@ -10,7 +10,7 @@ var it = lab.it var expect = Code.expect -describe('list()', function () { +describe('actions', function () { it('returns a list of found actions matching a string pattern', function (done) { var seneca = { private$: { diff --git a/test/plugin/basic.test.js b/test/basic.test.js similarity index 99% rename from test/plugin/basic.test.js rename to test/basic.test.js index 259e8a40..ff3f5a2b 100644 --- a/test/plugin/basic.test.js +++ b/test/basic.test.js @@ -3,7 +3,7 @@ var Assert = require('assert') var Lab = require('lab') -var Seneca = require('../..') +var Seneca = require('..') var Async = require('async') var lab = exports.lab = Lab.script() diff --git a/test/cli.test.js b/test/cli.test.js index bb862adf..9a3e4858 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -12,8 +12,8 @@ var describe = lab.describe var it = lab.it var expect = Code.expect -describe('CLI', function () { - var launchPath = Path.join(__dirname, 'launch') +describe('cli', function () { + var launchPath = Path.join(__dirname, '/stubs/launch.js') it('won\'t display action patterns message when they aren\'t provided', function (done) { ChildProcess.exec(process.argv[0] + ' ' + launchPath, function (err, stdout, stderr) { diff --git a/test/cmdline-run.js b/test/cmdline-run.js deleted file mode 100644 index d2434fbe..00000000 --- a/test/cmdline-run.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict' - -function xy (tag) { - return function xy (args, done) { - args.y = '' + args.x + '-' + tag - done(null, this.util.clean(args)) - } -} - -function p0 () { - this.add('a:1', xy('a')) - this.add('a:1,b:2', xy('ab')) - this.add('a:1,b:2,c:3', xy('abc')) - this.add('d:4', xy('d')) - this.add('d:4,e:5', xy('de')) - this.add('f:6', xy('f')) -} - -require('../') - .use(p0) - .add('d:4,e:5', xy('de2')) - .act('a:1,x:A', console.log) diff --git a/test/fail/die-err.js b/test/fail/die-err.js deleted file mode 100644 index 2508e67d..00000000 --- a/test/fail/die-err.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.die(new Error('eek!')) diff --git a/test/fail/die-str.js b/test/fail/die-str.js deleted file mode 100644 index 5ce8ba34..00000000 --- a/test/fail/die-str.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.die('foo') diff --git a/test/fail/unknown-act.js b/test/fail/unknown-act.js deleted file mode 100644 index 57f5e0ea..00000000 --- a/test/fail/unknown-act.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.act({a: 1}, function (err) { - console.log(err) -}) diff --git a/test/plugin/options.test.js b/test/plugin-options.test.js similarity index 83% rename from test/plugin/options.test.js rename to test/plugin-options.test.js index 9c8e9c80..675ebd29 100644 --- a/test/plugin/options.test.js +++ b/test/plugin-options.test.js @@ -3,7 +3,7 @@ var Assert = require('assert') var Lab = require('lab') -var Seneca = require('../..') +var Seneca = require('..') var lab = exports.lab = Lab.script() var describe = lab.describe @@ -17,7 +17,7 @@ describe('plugin.options', function () { si.use('options', {a: 1}) assert.equal(1, si.export('options').a) - si.use('options', require('./options.file.js')) + si.use('options', require('./stubs/plugin/options.file.js')) assert.equal(2, si.export('options').b) done() }) diff --git a/test/plugin-error.test.js b/test/plugin.error.test.js similarity index 87% rename from test/plugin-error.test.js rename to test/plugin.error.test.js index 3b21ce68..18c91a3a 100644 --- a/test/plugin-error.test.js +++ b/test/plugin.error.test.js @@ -10,19 +10,19 @@ var describe = lab.describe var it = lab.it var expect = Code.expect -describe('plugin-service-error', function () { +describe('plugin.error', function () { var si lab.before(function (done) { si = Seneca({ log: 'silent' }) - .use('./plugin-error/tmp.js') + .use('./stubs/plugin-error/tmp.js') .listen({ type: 'tcp', port: '30010', pin: 'role:tmp' }) .ready(done) }) it('should return "no errors created." when passing test false', function (done) { var seneca = Seneca({ log: 'silent' }) - seneca.use('./plugin-error/tmpApi') + seneca.use('./stubs/plugin-error/tmpApi') seneca.client({ type: 'tcp', port: '30010', pin: 'role:tmp' }) seneca.act({ role: 'api', cmd: 'tmpQuery', test: 'false' }, function (err, res) { @@ -34,7 +34,7 @@ describe('plugin-service-error', function () { it('should return "error caught!" when passing test true', function (done) { var seneca = Seneca({ log: 'silent' }) - seneca.use('./plugin-error/tmpApi') + seneca.use('./stubs/plugin-error/tmpApi') seneca.client({ type: 'tcp', port: '30010', pin: 'role:tmp' }) seneca.act({ role: 'api', cmd: 'tmpQuery', test: 'true' }, function (err, res) { diff --git a/test/plugin/echo.test.js b/test/plugin/echo.test.js deleted file mode 100644 index 08b67f36..00000000 --- a/test/plugin/echo.test.js +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (c) 2010-2015 Richard Rodger, MIT License */ -'use strict' - -var Assert = require('assert') -var Events = require('events') -var Lab = require('lab') -var Seneca = require('../..') - -var lab = exports.lab = Lab.script() -var describe = lab.describe -var it = lab.it -var assert = Assert - - -describe('plugin.echo', function () { - it('happy', function (done) { - var si = Seneca({log: 'test'}) - si.options( - {log: {map: [{type: 'init', - handler: si.loghandler.stream(process.stdout)}]}}) - si.use('echo') - - si.act({role: 'echo', baz: 'bax'}, function (err, out) { - assert.isNull(err) - assert.equal('' + {baz: 'bax'}, '' + out) - }) - done() - }) - - it('options', function (done) { - var printevents = new Events.EventEmitter() - printevents.on('log', function (data) { console.log(data) }) - - var si = Seneca({log: 'test'}) - si.options( - {log: {map: [{type: 'init', - handler: si.loghandler.emitter(printevents)}]}}) - si.use('echo', {inject: {foo: 'bar'}}) - - si.act({role: 'echo', baz: 'bax'}, function (err, out) { - assert.isNull(err) - assert.equal('' + {baz: 'bax', foo: 'bar'}, '' + out) - }) - done() - }) -}) diff --git a/test/repl.js b/test/repl.js deleted file mode 100644 index 7294b6ab..00000000 --- a/test/repl.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' - -require('..')() - .add('a:1', function a (args) { this.good({x: args.x}) }) - .add('b:1', function b (args, done) { - this.act('a:1', {x: args.x}, function (err, out) { - done(err, {y: args.y, x: out.x}) - }) - }) - .add('c:1', function cz (args) { this.good({z: args.z}) }) - .add('c:1', function czz (args, done) { - this.prior(args, function (e, o) { - if (e) return done(e) - o.z++ - done(null, o) - }) - }) - .repl() diff --git a/test/repl.test.js b/test/repl.test.js deleted file mode 100644 index f733c9d0..00000000 --- a/test/repl.test.js +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (c) 2014-2015 Richard Rodger, MIT License */ -'use strict' - -var Net = require('net') -var Code = require('code') -var Lab = require('lab') -var Seneca = require('..') - -// Test shortcuts -var lab = exports.lab = Lab.script() -var describe = lab.describe -var it = lab.it -var expect = Code.expect - -var internals = {} - -internals.availablePort = function (callback) { - var server = Net.createServer() - server.listen(0, function () { - var port = server.address().port - server.close(function () { - callback(port) - }) - }) -} - -describe('repl', function () { - lab.beforeEach(function (done) { - process.removeAllListeners('SIGHUP') - process.removeAllListeners('SIGTERM') - process.removeAllListeners('SIGINT') - process.removeAllListeners('SIGBREAK') - done() - }) - - it('accepts local connections and responds to commands', function (done) { - internals.availablePort(function (port) { - var seneca = Seneca({ repl: { port: port }, log: 'silent' }) - seneca.repl() - var result = '' - - setTimeout(function () { - var sock = Net.connect(port) - var first = true - - sock.on('data', function (data) { - result += data.toString('ascii') - - expect(result).to.contain('seneca') - if (first) { - setTimeout(function () { - first = false - expect(result).to.contain('->') - sock.write('this\n') - }, 50) - } - else { - expect(result).to.contain('->') - sock.write('seneca.quit\n') - sock.destroy() - sock.removeAllListeners('data') - done() - } - }, 100) - }) - }) - }) -}) diff --git a/test/seneca.test.js b/test/seneca.test.js index be2cb315..0a56da57 100644 --- a/test/seneca.test.js +++ b/test/seneca.test.js @@ -80,16 +80,6 @@ describe('seneca', function () { }) }) - it('require-use-safetynet', function (done) { - require('..')(testopts) - .use('echo', {web: false}) - .act('role:echo,foo:1', function (err, out) { - assert.ok(!err) - assert.equal(1, out.foo) - done() - }) - }) - it('ready-complex', function (done) { var mark = {ec: 0} @@ -631,14 +621,7 @@ describe('seneca', function () { it('loading-plugins', function (done) { var si = Seneca({ - plugins: ['echo'], - log: 'silent', - plugin: {echo: {web: false}} - }) - - si.act({role: 'echo', baz: 'bax'}, function (err, out) { - assert.equal(err, null) - assert.equal('' + {baz: 'bax'}, '' + out) + log: 'silent' }) si = Seneca({plugins: ['basic'], log: 'silent'}) @@ -714,14 +697,7 @@ describe('seneca', function () { }) }) - si = Seneca({log: 'silent'}) - si.use('echo', {web: false}) - si.act({role: 'echo', cmd: 'foo', bar: 1}, function (err, out) { - assert.equal(err, null) - assert.ok(out.cmd === 'foo') - assert.ok(out.bar === 1) - done() - }) + done() }) it('pin', function (done) { diff --git a/test/seneca.util.test.js b/test/seneca.util.test.js index 7028874d..c6e36b70 100644 --- a/test/seneca.util.test.js +++ b/test/seneca.util.test.js @@ -13,7 +13,7 @@ var describe = lab.describe var it = lab.it var expect = Code.expect -describe('seneca.util', function () { +describe('util', function () { lab.beforeEach(function (done) { process.removeAllListeners('SIGHUP') process.removeAllListeners('SIGTERM') diff --git a/test/service/biz-app.js b/test/service/biz-app.js deleted file mode 100644 index c4054a5a..00000000 --- a/test/service/biz-app.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -require('../..')() - .use('biz') - .act('s:a,d:1', console.log) - .act('s:b,d:2', console.log) - .act('s:c,d:3', console.log) diff --git a/test/service/biz-queue-app.js b/test/service/biz-queue-app.js deleted file mode 100644 index 5e2c762e..00000000 --- a/test/service/biz-queue-app.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -require('../..')() - .use('transport') - .use('biz') - .act('role:transport,cmd:client', {pin: {s: 'a'}, type: 'queue'}) - .act('role:transport,cmd:client', {pin: {s: 'b'}, type: 'queue'}) - .ready(function () { - this - .act('s:a,d:1') - .act('s:b,d:2') - .act('s:c,d:3') - }) diff --git a/test/service/biz-queue-client.js b/test/service/biz-queue-client.js deleted file mode 100644 index eb000a99..00000000 --- a/test/service/biz-queue-client.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict' - -require('../..')() - .use('biz') - .client({type: 'queue'}) - .ready(function () { - this - .act('s:a,d:1') - .act('s:b,d:2') - .act('s:c,d:3') - }) diff --git a/test/service/biz-service-queue.js b/test/service/biz-service-queue.js deleted file mode 100644 index 7cbd3b00..00000000 --- a/test/service/biz-service-queue.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -require('../..')() - .use('biz') - .listen({type: 'queue'}) diff --git a/test/service/biz-service.js b/test/service/biz-service.js deleted file mode 100644 index 52422073..00000000 --- a/test/service/biz-service.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -require('../..')() - .use('biz') - .listen(parseInt(process.argv[2], 10)) diff --git a/test/service/biz-services-client.js b/test/service/biz-services-client.js deleted file mode 100644 index d79e59d5..00000000 --- a/test/service/biz-services-client.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -require('../..')() - .use('transport') - .use('biz') - - .act('role:transport,cmd:client', {pin: {s: 'a'}, port: 8200}) - .act('role:transport,cmd:client', {pin: {s: 'b'}, port: 8201}) - .act('role:transport,cmd:client', {pin: {s: 'c'}, port: 8202}) - - .ready(function () { - this - .act('s:a,d:1') - .act('s:b,d:2') - .act('s:c,d:3') - }) diff --git a/test/service/biz-services.js b/test/service/biz-services.js deleted file mode 100644 index 7d4f4da7..00000000 --- a/test/service/biz-services.js +++ /dev/null @@ -1,4 +0,0 @@ -'use strict' - -require('../..')() - .use('service', {folder: './biz-services'}) diff --git a/test/service/biz-services/biz-a.js b/test/service/biz-services/biz-a.js deleted file mode 100644 index d1d74971..00000000 --- a/test/service/biz-services/biz-a.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict' - -module.exports = function (args, done) { - done(null, {d: 'a-' + args.d}) -} -module.exports.pattern = 's:a' diff --git a/test/service/biz-services/biz-b.js b/test/service/biz-services/biz-b.js deleted file mode 100644 index e707d5e9..00000000 --- a/test/service/biz-services/biz-b.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict' - -module.exports = function (args, done) { - done(null, {d: 'b-' + args.d}) -} -module.exports.pattern = 's:b' diff --git a/test/service/biz-services/biz-c.js b/test/service/biz-services/biz-c.js deleted file mode 100644 index 1f5f9c57..00000000 --- a/test/service/biz-services/biz-c.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict' - -module.exports = function (args, done) { - done(null, {d: 'c-' + args.d}) -} -module.exports.pattern = 's:c' diff --git a/test/service/biz.js b/test/service/biz.js deleted file mode 100644 index 53d27619..00000000 --- a/test/service/biz.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -module.exports = function () { - this.add('s:a', function (args, done) { done(null, {d: 'a-' + args.d}) }) - this.add('s:b', function (args, done) { done(null, {d: 'b-' + args.d}) }) - this.add('s:c', function (args, done) { done(null, {d: 'c-' + args.d}) }) -} diff --git a/test/service/echo-client.js b/test/service/echo-client.js deleted file mode 100644 index 7c5adf9c..00000000 --- a/test/service/echo-client.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -var client = require('../..')().client() - -client.act({role: 'echo', foo: 1}, function (err, out) { console.log(err); console.dir(out) }) diff --git a/test/service/echo-service.js b/test/service/echo-service.js deleted file mode 100644 index f4cc3677..00000000 --- a/test/service/echo-service.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict' - -require('../..')() - .use('echo', {inject: {bar: 2}}) - .listen() - - // curl "http://localhost:10101/act?role=echo&foo=1" - // OR - // node echo-client.js diff --git a/test/service/pinclient/README.md b/test/service/pinclient/README.md deleted file mode 100644 index 7ef5a296..00000000 --- a/test/service/pinclient/README.md +++ /dev/null @@ -1,10 +0,0 @@ -This test suggested by https://github.com/flyzb618 - -$ node listen-pin.js -$ node client-pin.js - -OR - -$ node listen-pin.js --seneca.log.all -$ node client-pin.js --seneca.log.all - diff --git a/test/service/pinclient/client-pin.js b/test/service/pinclient/client-pin.js deleted file mode 100644 index 55e26c8b..00000000 --- a/test/service/pinclient/client-pin.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict' - -var seneca = -require('../../..')() - .use('./foo') - .client(3000) - -var shop = seneca.pin({foo: 1, cmd: '*'}) -console.log(shop) - -shop.a({ bar: 'B' }, console.log) diff --git a/test/service/pinclient/foo.js b/test/service/pinclient/foo.js deleted file mode 100644 index 2025debe..00000000 --- a/test/service/pinclient/foo.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -module.exports = function (options) { - this.add('foo:1,cmd:a', function (args, done) { - done(null, {bar: args.bar}) - }) -} diff --git a/test/service/pinclient/listen-pin.js b/test/service/pinclient/listen-pin.js deleted file mode 100644 index 2750617b..00000000 --- a/test/service/pinclient/listen-pin.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict' - -require('../../..')() - .use('./foo') - .listen(3000) - .act('foo:1,cmd:a,bar:B', console.log) diff --git a/test/service/start-end.js b/test/service/start-end.js deleted file mode 100644 index d935aa1d..00000000 --- a/test/service/start-end.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -require('../..')() - .use('biz') - - .start() - - .act('s:a,d:1') - .act('s:b,d:2') - .act('s:c,d:3') - - .end() - .close() diff --git a/test/site/README.txt b/test/site/README.txt deleted file mode 100644 index 7cc2363a..00000000 --- a/test/site/README.txt +++ /dev/null @@ -1 +0,0 @@ -Code examples on website. diff --git a/test/site/database.js b/test/site/database.js deleted file mode 100644 index 47ca386a..00000000 --- a/test/site/database.js +++ /dev/null @@ -1,45 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -function saveload (seneca) { - var product = seneca.make('product') - product.name = 'apple' - product.price = 100 - - product.save$(function (err, product) { - if (err) return console.error(err) - console.log('saved: ' + product) - - // product.id was generated for us - product.load$({id: product.id}, function (err, product) { - if (err) return console.error(err) - console.log('loaded: ' + product) - }) - }) -} - -saveload(seneca) - -seneca.ready(function (err, seneca) { - if (err) return console.error('ERROR:' + err) - - // saveload(seneca) - - var product = seneca.make('product') - product.name = 'apple' - product.price = 100 - - seneca.act({role: 'entity', cmd: 'save', ent: product}, - function (err, product) { - if (err) return console.error(err) - console.log('saved: ' + product) - - seneca.act({role: 'entity', cmd: 'load', q: {id: product.id}, qent: product}, - function (err, product) { - if (err) return console.error(err) - console.log('loaded: ' + product) - }) - }) -}) diff --git a/test/site/example.js b/test/site/example.js deleted file mode 100644 index e115911b..00000000 --- a/test/site/example.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.add({role: 'math', cmd: 'sum'}, function (args, callback) { - var sum = args.left + args.right - callback(null, {answer: sum}) -}) - -seneca.act({role: 'math', cmd: 'sum', left: 1, right: 2}, function (err, result) { - if (err) return console.error(err) - console.log(result) -}) - -seneca.add({role: 'math', cmd: 'product'}, function (args, callback) { - var product = args.left * args.right - callback(null, {answer: product}) -}) - -seneca.act({role: 'math', cmd: 'product', left: 3, right: 4}, function (err, result) { - if (err) return console.error(err) - console.log(result) -}) - -function print (err, result) { console.log(result, err) } - -var math = seneca.pin({role: 'math', cmd: '*'}) -math.sum({left: 1, right: 2}, print) -math.product({left: 3, right: 4}, print) diff --git a/test/site/id-client.js b/test/site/id-client.js deleted file mode 100644 index cb6f988b..00000000 --- a/test/site/id-client.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' - -require('../..')() - .client() - .act({ generate: 'id' }, - function (err, out) { - console.log(out, err) - }) diff --git a/test/site/id-module.js b/test/site/id-module.js deleted file mode 100644 index 193f4311..00000000 --- a/test/site/id-module.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -var Nid = require('nid') - -exports.random = function (args, done) { - var len = args.len || 8 - done(null, { id: ('' + (Math.pow(10, len) * Math.abs(Math.random()))).substring(0, len) }) -} - -exports.nid = function (args, done) { - done(null, { id: Nid(args.len || 8) }) -} diff --git a/test/site/id-service-extra.js b/test/site/id-service-extra.js deleted file mode 100644 index b0270386..00000000 --- a/test/site/id-service-extra.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict' - -var Id = require('./id-module') - -require('../..')() - .add({generate: 'id'}, Id.random) - .add({generate: 'id', type: 'nid'}, Id.nid) - .listen() diff --git a/test/site/id-service.js b/test/site/id-service.js deleted file mode 100644 index adacf33e..00000000 --- a/test/site/id-service.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict' - -require('../..')() - .add({generate: 'id'}, - function (args, done) { - done(null, - {id: '' + Math.random()}) - }) - .listen({type: 'web'}) diff --git a/test/site/plugin-client.js b/test/site/plugin-client.js deleted file mode 100644 index f62bd937..00000000 --- a/test/site/plugin-client.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.use('transport', { - pins: [{role: 'math', cmd: 'product'}] -}) - -seneca.act({role: 'math', cmd: 'product', left: 3, right: 4}, - function (err, result) { - if (err) return console.error(err) - console.log(result) - }) diff --git a/test/site/plugin.js b/test/site/plugin.js deleted file mode 100644 index 8f4d6d51..00000000 --- a/test/site/plugin.js +++ /dev/null @@ -1,34 +0,0 @@ -'use strict' - -var Connect = require('connect') -var Seneca = require('../..') - -var seneca = Seneca() - -seneca.use(function (seneca, options, callback) { - seneca.add({role: 'math', cmd: 'sum'}, function (args, callback) { - var sum = args.left + args.right - callback(null, {answer: sum}) - }) - - seneca.add({role: 'math', cmd: 'product'}, function (args, callback) { - var product = args.left * args.right - callback(null, {answer: product}) - }) - - callback(null, { - service: seneca.http({ - pin: {role: 'math', cmd: '*'}, - map: { sum: {}, product: {} }, - args: { left: parseFloat, right: parseFloat } - }) - }) -}) - -seneca.use('transport') - -Connect() - .use(Connect.query()) - .use(Connect.json()) - .use(seneca.service()) - .listen(10171) diff --git a/test/site/prior-color.js b/test/site/prior-color.js deleted file mode 100644 index 0ce313bf..00000000 --- a/test/site/prior-color.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.use(function color () { - var map_name_hex = { - black: '000000', - red: 'FF0000', - green: '00FF00', - blue: '0000FF', - white: 'FFFFFF' - } - - this - .add('role:color,cmd:convert', function (msg, respond) { - var out = {hex: map_name_hex[msg.name]} - respond(null, out) - }) -}) - -seneca.act('role:color,cmd:convert,name:red', console.log) -seneca.act('role:color,cmd:convert,name:yellow', console.log) - -seneca.add('role:color,cmd:convert,name:yellow', function (msg, respond) { - respond(null, { hex: 'FFFF00' }) -}) - -seneca.act('role:color,cmd:convert,name:yellow', console.log) - -var more_name_hex = { - cyan: '00FFFF', - fuchsia: 'FF00FF' -} - -seneca.add('role:color,cmd:convert', function (msg, respond) { - this.prior(msg, function (err, out) { - if (err) return respond(out) - - if (out.hex == null) { - out.hex = more_name_hex[msg.name] - } - - respond(null, out) - }) -}) - -seneca.act('role:color,cmd:convert,name:cyan', console.log) -seneca.act('role:color,cmd:convert,name:yellow', console.log) -seneca.act('role:color,cmd:convert,name:red', console.log) diff --git a/test/site/prior-debug.js b/test/site/prior-debug.js deleted file mode 100644 index 522f3815..00000000 --- a/test/site/prior-debug.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca - .add('a:1', function (msg, respond) { - respond(null, { a: 1 }) - }) - - .add('a:1,b:2', function (msg, respond) { - this.prior(msg, function (err, out) { - out.b = 2 - respond(err, out) - }) - }) - - .add('a:1,b:2,c:3', function (msg, respond) { - this.prior(msg, function (err, out) { - out.c = 3 - respond(err, out) - }) - }) - - .act('a:1,b:2,c:3', console.log) diff --git a/test/site/prior-entity.js b/test/site/prior-entity.js deleted file mode 100644 index 7e17385f..00000000 --- a/test/site/prior-entity.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.add('role:entity,cmd:save', function (msg, respond) { - msg.ent.last_updated = Date.now() - this.prior(msg, respond) -}) - -seneca.make$('foo').data$({bar: 1}).save$(console.log) - -seneca.add('role:entity,cmd:save,name:bar', function (msg, respond) { - msg.ent.zed = 1 - this.prior(msg, respond) -}) - -seneca.make$('foo').data$({a: 1}).save$(console.log) -seneca.make$('bar').data$({b: 1}).save$(console.log) diff --git a/test/site/product-client.js b/test/site/product-client.js deleted file mode 100644 index 2e322575..00000000 --- a/test/site/product-client.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' - -var Seneca = require('../..') -var seneca = Seneca() - -seneca.use('transport', { - pins: [{role: 'math', cmd: 'product'}] -}) - -seneca.act({role: 'math', cmd: 'product', left: 3, right: 4}, function (err, result) { - if (err) return console.error(err) - console.log(result) -}) diff --git a/test/site/product-server.js b/test/site/product-server.js deleted file mode 100644 index 037e8492..00000000 --- a/test/site/product-server.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict' - -var Connect = require('connect') -var Seneca = require('../..') -var seneca = Seneca() - -seneca.add({role: 'math', cmd: 'product'}, function (args, callback) { - var product = args.left * args.right - callback(null, {answer: product}) -}) - -seneca.use('transport') - -Connect() - .use(Connect.json()) - .use(seneca.service()) - .listen(10171) diff --git a/test/smoke.js b/test/smoke.js deleted file mode 100644 index 11e3485f..00000000 --- a/test/smoke.js +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (c) 2016 Richard Rodger, MIT License */ -'use strict' - -require('..')() - - .add('a:1', function (msg, done) { - done(null, {x: 1}) - }) - .act('a:1', console.log) - - .use(function foo () { - this.add('b:1', function (msg, done) { - done(null, {y: 1}) - }) - }) - .act('b:1', console.log) - - .ready(function () { - console.log('ready') - - this - .add('c:1', function (msg, done) { - done(null, {z: 1}) - }) - .act('c:1', console.log) - - .close() - }) - diff --git a/test/launch.js b/test/stubs/launch.js similarity index 65% rename from test/launch.js rename to test/stubs/launch.js index d7ff68f8..2c275ebe 100644 --- a/test/launch.js +++ b/test/stubs/launch.js @@ -1,14 +1,11 @@ 'use strict' -require('..')({ - // legacy:{logger:false}, - // log:{basic:{level:'debug',kind:'client'}} -}) - // .client(9001) +var Seneca = require('../..') + +Seneca() .use(function foo () { this.add('b:2', function b2 (m, d) { d(null, {y: 1}) }) }) .add('a:1', function (m, d) { d(null, {x: 1}) }) .act('a:1', console.log) .act('b:2', console.log) - diff --git a/test/options/fatal/fatal.js b/test/stubs/options/fatal/fatal.js similarity index 100% rename from test/options/fatal/fatal.js rename to test/stubs/options/fatal/fatal.js diff --git a/test/options/fatal/options.seneca.js b/test/stubs/options/fatal/options.seneca.js similarity index 100% rename from test/options/fatal/options.seneca.js rename to test/stubs/options/fatal/options.seneca.js diff --git a/test/options/options.file.json b/test/stubs/options/options.file.json similarity index 100% rename from test/options/options.file.json rename to test/stubs/options/options.file.json diff --git a/test/options/options.require.js b/test/stubs/options/options.require.js similarity index 100% rename from test/options/options.require.js rename to test/stubs/options/options.require.js diff --git a/test/options/options.test.js b/test/stubs/options/options.test.js similarity index 96% rename from test/options/options.test.js rename to test/stubs/options/options.test.js index 0fa8e302..3a52d4c9 100644 --- a/test/options/options.test.js +++ b/test/stubs/options/options.test.js @@ -3,7 +3,7 @@ var Assert = require('assert') var Lab = require('lab') -var Seneca = require('../..') +var Seneca = require('../../..') var lab = exports.lab = Lab.script() var describe = lab.describe @@ -90,7 +90,7 @@ describe('options', function () { it('options-file-js', function (done) { var si0 = Seneca({d: 4, foo: {dd: 4}, log: 'silent', module: module}) - si0.options('./options.require.js') + si0.options(__dirname + '/options.require.js') var opts = si0.options() assert.equal(1, opts.a) @@ -134,12 +134,10 @@ describe('options', function () { }) it('options-env', function (done) { - process.env.SENECA_LOG = 'silent' process.env.SENECA_OPTIONS = '{"foo":"bar","a":99}' var si = Seneca() var opts = si.options() - assert.equal(0, opts.log.map.length) assert.equal('bar', opts.foo) assert.equal(99, opts.a) si.close(done) diff --git a/test/options/seneca.options.js b/test/stubs/options/seneca.options.js similarity index 100% rename from test/options/seneca.options.js rename to test/stubs/options/seneca.options.js diff --git a/test/plugin-error/tmp.js b/test/stubs/plugin-error/tmp.js similarity index 100% rename from test/plugin-error/tmp.js rename to test/stubs/plugin-error/tmp.js diff --git a/test/plugin-error/tmpApi.js b/test/stubs/plugin-error/tmpApi.js similarity index 100% rename from test/plugin-error/tmpApi.js rename to test/stubs/plugin-error/tmpApi.js diff --git a/test/plugin/bad-depends.js b/test/stubs/plugin/bad-depends.js similarity index 65% rename from test/plugin/bad-depends.js rename to test/stubs/plugin/bad-depends.js index 63117062..d5c678cb 100644 --- a/test/plugin/bad-depends.js +++ b/test/stubs/plugin/bad-depends.js @@ -1,4 +1,4 @@ 'use strict' -require('../..')() +require('../../..')() .depends('foo', ['bar']) diff --git a/test/plugin/bad-init-error.js b/test/stubs/plugin/bad-init-error.js similarity index 87% rename from test/plugin/bad-init-error.js rename to test/stubs/plugin/bad-init-error.js index 2d89f067..5eec2446 100644 --- a/test/plugin/bad-init-error.js +++ b/test/stubs/plugin/bad-init-error.js @@ -1,6 +1,6 @@ 'use strict' -require('../..')() +require('../../..')() .use(function init_error () { this.add('init:init_error', function () { throw Error('Some init error details.') diff --git a/test/plugin/bad-init-timeout.js b/test/stubs/plugin/bad-init-timeout.js similarity index 74% rename from test/plugin/bad-init-timeout.js rename to test/stubs/plugin/bad-init-timeout.js index 716426ae..6af1a876 100644 --- a/test/plugin/bad-init-timeout.js +++ b/test/stubs/plugin/bad-init-timeout.js @@ -1,6 +1,6 @@ 'use strict' -require('../..')({timeout: 555}) +require('../../..')({timeout: 555}) .use(function init_timeout () { this.add('init:init_timeout', function () {}) }) diff --git a/test/plugin/bad-load-plugin.js b/test/stubs/plugin/bad-load-plugin.js similarity index 100% rename from test/plugin/bad-load-plugin.js rename to test/stubs/plugin/bad-load-plugin.js diff --git a/test/plugin/bad-load.js b/test/stubs/plugin/bad-load.js similarity index 64% rename from test/plugin/bad-load.js rename to test/stubs/plugin/bad-load.js index 0d5abd1c..5e64889c 100644 --- a/test/plugin/bad-load.js +++ b/test/stubs/plugin/bad-load.js @@ -1,4 +1,4 @@ 'use strict' -require('../..')() +require('../../..')() .use('bad-load-plugin') diff --git a/test/plugin/bad-missing.js b/test/stubs/plugin/bad-missing.js similarity index 63% rename from test/plugin/bad-missing.js rename to test/stubs/plugin/bad-missing.js index 88e2a256..86d4af75 100644 --- a/test/plugin/bad-missing.js +++ b/test/stubs/plugin/bad-missing.js @@ -1,4 +1,4 @@ 'use strict' -require('../..')() +require('../../..')() .use('missing-plugin') diff --git a/test/plugin/bad-require-plugin.js b/test/stubs/plugin/bad-require-plugin.js similarity index 100% rename from test/plugin/bad-require-plugin.js rename to test/stubs/plugin/bad-require-plugin.js diff --git a/test/plugin/bad-require.js b/test/stubs/plugin/bad-require.js similarity index 66% rename from test/plugin/bad-require.js rename to test/stubs/plugin/bad-require.js index d35f74d6..76a430e3 100644 --- a/test/plugin/bad-require.js +++ b/test/stubs/plugin/bad-require.js @@ -1,4 +1,4 @@ 'use strict' -require('../..')() +require('../../..')() .use('bad-require-plugin') diff --git a/test/plugin/bad-syntax-plugin.js b/test/stubs/plugin/bad-syntax-plugin.js similarity index 100% rename from test/plugin/bad-syntax-plugin.js rename to test/stubs/plugin/bad-syntax-plugin.js diff --git a/test/plugin/bad-syntax.js b/test/stubs/plugin/bad-syntax.js similarity index 65% rename from test/plugin/bad-syntax.js rename to test/stubs/plugin/bad-syntax.js index ae6c7c30..f14e0fbd 100644 --- a/test/plugin/bad-syntax.js +++ b/test/stubs/plugin/bad-syntax.js @@ -1,4 +1,4 @@ 'use strict' -require('../..')() +require('../../..')() .use('bad-syntax-plugin') diff --git a/test/plugin/bad.sh b/test/stubs/plugin/bad.sh similarity index 100% rename from test/plugin/bad.sh rename to test/stubs/plugin/bad.sh diff --git a/test/plugin/echo.server.js b/test/stubs/plugin/echo.server.js similarity index 100% rename from test/plugin/echo.server.js rename to test/stubs/plugin/echo.server.js diff --git a/test/plugin/options.file.js b/test/stubs/plugin/options.file.js similarity index 100% rename from test/plugin/options.file.js rename to test/stubs/plugin/options.file.js diff --git a/test/test-included-plugins.sh b/test/test-included-plugins.sh deleted file mode 100755 index 93b108d7..00000000 --- a/test/test-included-plugins.sh +++ /dev/null @@ -1,24 +0,0 @@ -echo ---seneca-basic--- -cd ../seneca-basic -./test.sh link - -echo ---seneca-mem-store--- -cd ../seneca-mem-store -./test.sh link - -echo ---seneca-transport--- -cd ../seneca-transport -./test.sh link - -echo ---seneca-web--- -cd ../seneca-web -./test.sh link - - -# not included, but used in tests -echo ---seneca-echo--- -cd ../seneca-echo -./test.sh link - - - diff --git a/test/transport/pin-server.js b/test/transport/pin-server.js deleted file mode 100644 index 2710e987..00000000 --- a/test/transport/pin-server.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict' - -require('../..')() - .add('a:1', function (msg, done) { - done(null, {a: 1, x: msg.x}) - }) - .add('b:2', function (msg, done) { - done(null, {b: 2, x: msg.x}) - }) - - .add('role:transport,cmd:listen', function (msg, done) { - console.log(msg.config) - this.prior(msg, done) - }) - - .listen({pin: 'a:1'}) diff --git a/test/transport/quick-client.js b/test/transport/quick-client.js deleted file mode 100644 index 2615a295..00000000 --- a/test/transport/quick-client.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict' - -require('../..')() - .client() - .act('a:1,x:1', console.log) diff --git a/test/transport/quick-server.js b/test/transport/quick-server.js deleted file mode 100644 index 50880cf1..00000000 --- a/test/transport/quick-server.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict' - -require('../..')() - .add('a:1', function (msg, done) { - done(null, {a: 1, x: msg.x}) - }) - .listen()