Add new search addon, move AddonManager to public

Because addons build on top of the API it needs to live in public, the main
reason for this is because the implementation of buffer differs on
public/Terminal and src/Terminal.
This commit is contained in:
Daniel Imms
2019-05-12 10:22:29 -07:00
parent 0c588a7333
commit eda04bcb23
8 changed files with 21 additions and 17 deletions
+54
View File
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { assert } from 'chai';
import { AddonManager, ILoadedAddon } from './AddonManager';
import { ITerminalAddon } from 'xterm';
class TestAddonManager extends AddonManager {
public get addons(): ILoadedAddon[] {
return this._addons;
}
}
describe('AddonManager', () => {
let manager: TestAddonManager;
beforeEach(() => {
manager = new TestAddonManager();
});
describe('loadAddon', () => {
it('should call addon constructor', () => {
let called = false;
class Addon implements ITerminalAddon {
activate(terminal: any): void {
assert.equal(terminal, 'foo', 'The first constructor arg should be Terminal');
called = true;
}
dispose(): void { }
}
manager.loadAddon('foo' as any, new Addon());
assert.equal(called, true);
});
});
describe('dispose', () => {
it('should dispose all loaded addons', () => {
let called = 0;
class Addon implements ITerminalAddon {
activate(): void {}
dispose(): void { called++; }
}
manager.loadAddon(null, new Addon());
manager.loadAddon(null, new Addon());
manager.loadAddon(null, new Addon());
assert.equal(manager.addons.length, 3);
manager.dispose();
assert.equal(called, 3);
assert.equal(manager.addons.length, 0);
});
});
});