Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mqemitter

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mqemitter - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

abstractTest.js

15

package.json
{
"name": "mqemitter",
"version": "0.2.0",
"version": "0.2.1",
"description": "An Opinionated Message Queue with an emitter-style API",
"main": "index.js",
"main": "mqemitter.js",
"scripts": {
"test": "tap test.js"
"test": "tape test.js | faucet"
},
"pre-commit": ["test"],
"pre-commit": [
"test"
],
"website": "https://github.com/mcollina/mqemitter",

@@ -31,4 +33,5 @@ "repository": {

"devDependencies": {
"tap": "~0.4.8",
"pre-commit": "0.0.4"
"faucet": "0.0.1",
"pre-commit": "0.0.9",
"tape": "^2.14.0"
},

@@ -35,0 +38,0 @@ "dependencies": {

10

README.md

@@ -10,3 +10,3 @@ mqemitter  [![Build Status](https://travis-ci.org/mcollina/mqemitter.png)](https://travis-ci.org/mcollina/mqemitter)

* <a href="#api">API</a>
* <a href="#contributing">Contributing</a>
* <a href="#wildcards">Wildcards</a>
* <a href="#licence">Licence &amp; copyright</a>

@@ -48,2 +48,4 @@

* <a href="#removeListener"><code>emitter#<b>removeListener()</b></code></a>
* <a href="#close"><code>emitter#<b>close()</b></code></a>
* <a href="#closed"><code>emitter#<b>closed</b></code></a>

@@ -93,2 +95,8 @@ -------------------------------------------------------

-------------------------------------------------------
<a name="close"></a>
### emitter.close(callback())
Close the given emitter. After, all writes will return an error.
<a name="wildcards"></a>

@@ -95,0 +103,0 @@ ## Wildcards

var test = require('tap').test
, mq = require('./')
var abstractTest = require('./abstractTest')
, test = require('tape').test
, mq = require('./')
test('support on and emit', function(t) {
t.plan(3)
var e = mq()
, expected = {
topic: 'hello world'
, payload: { my: 'message' }
}
e.on('hello world', function(message, cb) {
t.equal(e.current, 1, 'number of current messages')
t.equal(message, expected)
t.equal(this, e)
cb()
})
e.emit(expected, function() {
t.end()
})
abstractTest({
builder: mq
, test: require('tape').test
})
test('support multiple subscribers', function(t) {
test('queue concurrency', function(t) {
t.plan(2)
var e = mq()
, expected = {
topic: 'hello world'
, payload: { my: 'message' }
}
e.on('hello world', function(message, cb) {
t.ok(true)
cb()
})
e.on('hello world', function(message, cb) {
t.ok(true)
cb()
})
e.emit(expected, function() {
t.end()
})
})
test('queue concurrency', function(t) {
t.plan(4)
var e = mq({ concurrency: 1 })
, expected = {
topic: 'hello world'
, payload: { my: 'message' }
}
, start
, intermediate
, finish
topic: 'hello world'
, payload: { my: 'message' }
}
, completed1 = false

@@ -65,3 +24,3 @@ t.equal(e.concurrency, 1)

e.on('hello 1', function(message, cb) {
setTimeout(cb, 5)
setTimeout(cb, 10)
})

@@ -75,66 +34,10 @@

e.emit({ topic: 'hello 1' }, function() {
intermediate = Date.now()
t.ok(intermediate - start >= 5, 'min 5 ms between start and intermediate')
t.equal(e.length, 1)
completed1 = true
})
e.emit({ topic: 'hello 2' }, function() {
finish = Date.now()
t.ok(finish - intermediate < 5, 'max 5 ms between intermediate and finish')
t.end()
t.ok(completed1, 'the first message must be completed')
})
})
test('removeListener', function(t) {
var e = mq()
, expected = {
topic: 'hello world'
, payload: { my: 'message' }
}
e.on('hello world', function(message, cb) {
cb()
})
function toRemove(message, cb) {
t.ok(false, 'the toRemove function must not be called')
t.end()
}
e.on('hello world', toRemove)
e.removeListener('hello world', toRemove)
e.emit(expected, function() {
t.end()
})
})
test('without a callback on emit', function(t) {
var e = mq()
, expected = {
topic: 'hello world'
, payload: { my: 'message' }
}
e.on('hello world', function(message, cb) {
cb()
t.end()
})
e.emit(expected)
})
test('without any listeners', function(t) {
var e = mq()
, expected = {
topic: 'hello world'
, payload: { my: 'message' }
}
e.emit(expected)
t.equal(e.current, 0, 'reset the current messages trackers')
t.end()
})
test('without any listeners and a callback', function(t) {

@@ -149,97 +52,6 @@ var e = mq()

t.equal(e.current, 1, 'there 1 message that is being processed')
t.end()
e.close(function() {
t.end()
})
})
})
test('support one level wildcard', function(t) {
t.plan(1)
var e = mq()
, expected = {
topic: 'hello/world'
, payload: { my: 'message' }
}
e.on('hello/+', function(message, cb) {
t.equal(message.topic, 'hello/world')
cb()
})
// this will not be catched
e.emit({ topic: 'hello/my/world' })
// this will be catched
e.emit(expected)
})
test('support changing one level wildcard', function(t) {
t.plan(1)
var e = mq({ wildcardOne: '~' })
, expected = {
topic: 'hello/world'
, payload: { my: 'message' }
}
e.on('hello/~', function(message, cb) {
t.equal(message.topic, 'hello/world')
cb()
})
e.emit(expected, function() {
t.end()
})
})
test('support deep wildcard', function(t) {
t.plan(1)
var e = mq()
, expected = {
topic: 'hello/my/world'
, payload: { my: 'message' }
}
e.on('hello/#', function(message, cb) {
t.equal(message.topic, 'hello/my/world')
cb()
})
e.emit(expected)
})
test('support changing deep wildcard', function(t) {
t.plan(1)
var e = mq({ wildcardSome: '*' })
, expected = {
topic: 'hello/my/world'
, payload: { my: 'message' }
}
e.on('hello/*', function(message, cb) {
t.equal(message.topic, 'hello/my/world')
cb()
})
e.emit(expected)
})
test('support changing the level separator', function(t) {
t.plan(1)
var e = mq({ separator: '~' })
, expected = {
topic: 'hello~world'
, payload: { my: 'message' }
}
e.on('hello~+', function(message, cb) {
t.equal(message.topic, 'hello~world')
cb()
})
e.emit(expected, function() {
t.end()
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc