Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Commit

Permalink
Merge branch 'v2' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MomoCow committed Apr 17, 2019
2 parents a950ef9 + e8727fe commit e86c6a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
37 changes: 37 additions & 0 deletions performance/leakage/on-off.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const test = require('tape')
const { iterate } = require('leakage')
const { EventEmitter } = require('events')

const { CQWebSocket } = require('../../')

test('EventEmitter#on(), EventEmitter#removeAllListener()', function (t) {
const bot = new EventEmitter()
iterate(() => {
let a = 0
bot.on('message', function (arg) {
// zero side effect
arg++
})
bot.emit('message', a)
bot.removeAllListeners('message')
})
t.same(bot.listeners('message').length, 0)
t.end()
})

test('CQWebSocket#on(), CQWebSocket#off()', function (t) {
const bot = new CQWebSocket()
iterate.async(async () => {
let a = 0
bot.on('message', function (arg) {
// zero side effect
arg++
})
await bot._eventBus.emit('message', a)
bot.off('message')
})
.then(function () {
t.same(bot._eventBus._EventMap.message[''].length, 0)
t.end()
})
})
35 changes: 35 additions & 0 deletions performance/leakage/once.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const test = require('tape')
const { iterate } = require('leakage')
const { EventEmitter } = require('events')

const { CQWebSocket } = require('../../')

test('EventEmitter#once()', function (t) {
const bot = new EventEmitter()
iterate(() => {
let a = 0
bot.once('message', function (arg) {
// zero side effect
arg++
})
bot.emit('message', a)
})
t.same(bot.listeners('message').length, 0)
t.end()
})

test('CQWebSocket#once()', function (t) {
const bot = new CQWebSocket()
iterate.async(() => {
let a = 0
bot.once('message', function (arg) {
// zero side effect
arg++
})
return bot._eventBus.emit('message', a)
})
.then(function () {
t.same(bot._eventBus._EventMap.message[''].length, 0)
t.end()
})
})

0 comments on commit e86c6a5

Please sign in to comment.