UNPKG

kara

Version:

A third generation EX-400 android

103 lines (84 loc) 3.02 kB
var assert = require("chai").assert, path = require("path"), Kara = require("../kara"); describe("Kara plugins", function(){ var k; beforeEach(function() { k = new Kara({plugins: {loadPath: "./test/fixtures/plugins"}}); }); it("can load a plugin", function() { var plugin = k.loadPlugin("hello-world"); assert.strictEqual(k.plugins["hello-world"].enabled, false); assert.strictEqual(k.plugins["hello-world"].filename, "./test/fixtures/plugins/hello-world.js"); assert.strictEqual(typeof(plugin), "object"); assert.strictEqual(plugin.constructor.name, "HelloWorld"); }); it("cannot load an unknown plugin", function() { assert.throws(function() { k.loadPlugin("unknown"); }); }); it("cannot load an already loaded plugin", function() { assert.throws(function() { k.loadPlugin("hello-world"); k.loadPlugin("hello-world"); }); }); it("can unload a plugin", function() { k.loadPlugin("hello-world"); assert.ok("hello-world" in k.plugins); k.unloadPlugin("hello-world"); assert.notOk("hello-world" in k.plugins); }); it(".unload should remove plugin from require.cache", function() { var absolutePath = path.resolve(__dirname, "./fixtures/plugins/hello-world.js"); delete require.cache[absolutePath]; assert.notOk(absolutePath in require.cache); k.loadPlugin("hello-world"); assert.ok(absolutePath in require.cache); k.unloadPlugin("hello-world"); assert.notOk(absolutePath in require.cache); }); it("cannot .unload an unknown plugin", function() { assert.throws(function() { k.unloadPlugin("unknown"); }); }); it(".enable should attach listeners", function() { k.loadPlugin("hello-world"); assert.strictEqual(k.listeners("msg:direct").length, 0); k.enablePlugin("hello-world"); assert.strictEqual(k.listeners("msg:direct").length, 1); }); it("cannot .enable an enabled plugin", function() { k.loadPlugin("hello-world"); k.enablePlugin("hello-world"); assert.strictEqual(k.listeners("msg:direct").length, 1); k.enablePlugin("hello-world"); assert.strictEqual(k.listeners("msg:direct").length, 1); }); it("cannot .enable an unknown plugin", function() { assert.throws(function() { k.enablePlugin("unknown"); }); }); it(".disable should remove listeners", function() { k.loadPlugin("hello-world"); k.enablePlugin("hello-world"); assert.strictEqual(k.listeners("msg:direct").length, 1); k.disablePlugin("hello-world"); assert.strictEqual(k.listeners("msg:direct").length, 0); }); it("cannot .disable a disabled plugin", function() { k.loadPlugin("hello-world"); assert.doesNotThrow(function() { k.disablePlugin("hello-world"); k.disablePlugin("hello-world"); }); }); it("cannot .disable an unknown plugin", function() { assert.throws(function() { k.disablePlugin("unknown"); }); }); });