diff --git a/index.js b/index.js index 320026d7..096a36c7 100644 --- a/index.js +++ b/index.js @@ -78,10 +78,14 @@ function Primus(server, options) { this.Spark.prototype = Object.create(Spark.prototype, { constructor: { + configurable: true, value: this.Spark, - writable: true, - enumerable: false, - configurable: true + writable: true + }, + __initialise: { + value: Spark.prototype.__initialise.slice(), + configurable: true, + writable: true } }); diff --git a/test/plugin.test.js b/test/plugin.test.js index fe8ce809..d217e7ac 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -35,9 +35,7 @@ describe('Plugin', function () { primus.on('connection', function (spark) { spark.on('custom event', function (data) { expect(data).to.equal('custom data'); - - spark.end(); - server.close(done); + primus.destroy(done); }); }); @@ -64,13 +62,11 @@ describe('Plugin', function () { primus.on('connection', function (spark) { expect(spark.query.foo).to.equal('bar'); - spark.end(); - server.close(done); + primus.destroy(done); }); server.listen(port, function () { - var Socket = primus.Socket - , socket = new Socket('http://localhost:'+ port); + new primus.Socket('http://localhost:'+ port); }); }); @@ -90,14 +86,26 @@ describe('Plugin', function () { primus.on('connection', function (spark) { expect(spark.join).to.be.a('function'); - spark.end(); - server.close(done); + primus.destroy(done); }); server.listen(port, function () { - var Socket = primus.Socket - , socket = new Socket('http://localhost:'+ port); + new primus.Socket('http://localhost:'+ port); + }); + }); + + it('doesn\'t mutate the Spark prototype', function () { + var expected = Primus.Spark.prototype.__initialise.slice() + , server = http.createServer() + , primus = new Primus(server); + + primus.use('dummy', { + server: function (primus) { + primus.Spark.prototype.initialise = function init() {}; + } }); + + expect(Primus.Spark.prototype.__initialise).to.eql(expected); }); it('can instantly modify the prototype', function () { @@ -117,8 +125,7 @@ describe('Plugin', function () { it('emits an `plugin` event when a new plugin is added', function (next) { var server = http.createServer() - , primus = new Primus(server) - , port = common.port; + , primus = new Primus(server); primus.on('plugin', function (name, obj) { expect(name).to.equal('foo'); @@ -135,8 +142,7 @@ describe('Plugin', function () { describe('#plugout', function () { it('emits a `plugout` event when removing a plugin', function (next) { var server = http.createServer() - , primus = new Primus(server) - , port = common.port; + , primus = new Primus(server); primus.on('plugout', function (name, obj) { expect(name).to.equal('foo'); @@ -159,7 +165,7 @@ describe('Plugin', function () { , primus = new Primus(server); var plugin = { - server: function (primus) {} + server: function () {} }; primus.use('spark', plugin);