Provide initial plugin test infra for plugin devs
Summary: This sets up the initial infra that is to be used by plugin devs to test plugins. There is not much yet to see, as there is no state or message sending yet. But at least the life cycle of plugins can be test, things are strongly typed and everything is in the place where it should be :) N.b. the import difference with these utils and the createFlipperMock utilities in Flipper are 1. this testing infra is entirely inside flipper-plugin package, so that plugin devs don't need flipper as a dependency 2. this testing infra doesn't provide abstractions for plugin / device / client switching; it tests plugins purely in isolation of the rest of the world (except for firing `onConnect` / `onDisconnect` which is normally the effect of switching plugins) Reviewed By: nikoant Differential Revision: D22255262 fbshipit-source-id: b94ccbab720d2b49428a646aed3c55af71a5bc80
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c902a27bce
commit
df6a8cd031
61
desktop/flipper-plugin/src/__tests__/test-utils.node.tsx
Normal file
61
desktop/flipper-plugin/src/__tests__/test-utils.node.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import * as TestUtils from '../test-utils/test-utils';
|
||||
|
||||
import * as testPlugin from './TestPlugin';
|
||||
|
||||
test('it can start a plugin and lifecycle events', () => {
|
||||
const {instance, ...p} = TestUtils.startPlugin(testPlugin);
|
||||
|
||||
// TODO T69105011 @ts-expect-error
|
||||
// p.bla;
|
||||
|
||||
// startPlugin starts connected
|
||||
expect(instance.connectStub).toBeCalledTimes(1);
|
||||
expect(instance.disconnectStub).toBeCalledTimes(0);
|
||||
expect(instance.destroyStub).toBeCalledTimes(0);
|
||||
|
||||
p.connect(); // noop
|
||||
expect(instance.connectStub).toBeCalledTimes(1);
|
||||
expect(instance.disconnectStub).toBeCalledTimes(0);
|
||||
expect(instance.destroyStub).toBeCalledTimes(0);
|
||||
|
||||
p.disconnect();
|
||||
p.connect();
|
||||
|
||||
expect(instance.connectStub).toBeCalledTimes(2);
|
||||
expect(instance.disconnectStub).toBeCalledTimes(1);
|
||||
expect(instance.destroyStub).toBeCalledTimes(0);
|
||||
|
||||
p.destroy();
|
||||
expect(instance.connectStub).toBeCalledTimes(2);
|
||||
expect(instance.disconnectStub).toBeCalledTimes(2);
|
||||
expect(instance.destroyStub).toBeCalledTimes(1);
|
||||
|
||||
// cannot interact with destroyed plugin
|
||||
expect(() => {
|
||||
p.connect();
|
||||
}).toThrowErrorMatchingInlineSnapshot(`"Plugin has been destroyed already"`);
|
||||
});
|
||||
|
||||
test('it can render a plugin', () => {
|
||||
const {renderer} = TestUtils.renderPlugin(testPlugin);
|
||||
|
||||
expect(renderer.baseElement).toMatchInlineSnapshot(`
|
||||
<body>
|
||||
<div>
|
||||
<h1>
|
||||
Hi from test plugin
|
||||
</h1>
|
||||
</div>
|
||||
</body>
|
||||
`);
|
||||
// TODO: test sending updates T68683442
|
||||
});
|
||||
Reference in New Issue
Block a user