You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/test/pubsub.js

36 lines
946 B
JavaScript

'use strict';
var assert = require('assert');
var nconf = require('nconf');
var db = require('./mocks/databasemock');
var pubsub = require('../src/pubsub');
describe('pubsub', function () {
6 years ago
it('should use the plain event emitter', function (done) {
nconf.set('isCluster', 'false');
pubsub.reset();
pubsub.on('testEvent', function (message) {
assert.equal(message.foo, 1);
6 years ago
nconf.set('isCluster', 'true');
pubsub.removeAllListeners('testEvent');
6 years ago
pubsub.reset();
done();
});
pubsub.publish('testEvent', { foo: 1 });
});
6 years ago
it('should use singleHostCluster', function (done) {
var oldValue = nconf.get('singleHostCluster');
6 years ago
nconf.set('singleHostCluster', true);
pubsub.on('testEvent', function (message) {
6 years ago
assert.equal(message.foo, 2);
nconf.set('singleHostCluster', oldValue);
pubsub.removeAllListeners('testEvent');
6 years ago
pubsub.reset();
done();
});
6 years ago
pubsub.publish('testEvent', { foo: 2 });
});
});