Skip to content
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '0.11'
- '0.10'
- '4'
- '6'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个去掉了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 要加么?

script: "npm run test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ If a process is not child process, this will just call `process.emit('message',
sendmessage(process, {hello: 'this is a message to master'});
```

You can switch to `process.emit('message', message)` using `process.env.SENDMESSAGE_ONE_PROCESS`

## Test

```bash
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function send(child, message) {
return setImmediate(child.emit.bind(child, 'message', message));
}

if (IS_NODE_DEV_RUNNER) {
if (IS_NODE_DEV_RUNNER || process.env.SENDMESSAGE_ONE_PROCESS) {
// run with node-dev, only one process
// https://github.com/node-modules/sendmessage/issues/1
return setImmediate(child.emit.bind(child, 'message', message));
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
"cnpm": "npm install --registry=https://registry.npm.taobao.org",
"contributors": "contributors -f plain -o AUTHORS"
},
"dependencies": {

},
"dependencies": {},
"devDependencies": {
"autod": "*",
"contributors": "*",
"should": "*",
"jshint": "*",
"istanbul": "*",
"mocha": "*"
"jshint": "*",
"mm": "^1.5.1",
"mocha": "*",
"should": "*"
},
"homepage": "https://github.com/node-modules/sendmessage",
"repository": {
Expand All @@ -37,7 +36,11 @@
"email": "fengmk2@gmail.com"
},
"keywords": [
"sendmessage", "send", "cluster", "message", "channel closed"
"sendmessage",
"send",
"cluster",
"message",
"channel closed"
],
"engines": {
"node": ">= 0.10.0"
Expand Down
29 changes: 29 additions & 0 deletions test/sendmessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ var path = require('path');
var should = require('should');
var childprocess = require('child_process');
var cluster = require('cluster');
var mm = require('mm');
var sendmessage = require('../');

describe('sendmessage.test.js', function () {
afterEach(mm.restore);

describe('single process', function () {
it('should emit message when process is not child process', function (done) {
process.once('message', function (message) {
Expand Down Expand Up @@ -146,4 +149,30 @@ describe('sendmessage.test.js', function () {
});
});
});

it('should emit when SENDMESSAGE_ONE_PROCESS = true', function(done) {
var childfile = path.join(__dirname, 'child.js');
var child = childprocess.fork(childfile);
mm(process.env, 'SENDMESSAGE_ONE_PROCESS', 'true');
var msg;
child.once('message', function (message) {
message.should.eql({
from: 'child',
hi: 'this is a message send to master'
});

sendmessage(child, {
from: 'master',
reply: 'this is a reply message send to child'
});

child.once('message', function(msg) {
msg.should.eql({
from: 'master',
reply: 'this is a reply message send to child',
});
done();
});
});
})
});