@player-devtools/client-flipper 0.16.1-next.3 → 1.0.0--canary.38.1480

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -6,10 +6,10 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-devtools/client-flipper",
9
- "version": "0.16.1-next.3",
9
+ "version": "1.0.0--canary.38.1480",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "dependencies": {
12
- "@player-devtools/types": "0.16.1-next.3",
12
+ "@player-devtools/types": "1.0.0--canary.38.1480",
13
13
  "@types/ws": "^8.0.0",
14
14
  "flipper-common": "^0.273.0",
15
15
  "flipper-server": "^0.273.0",
@@ -11,21 +11,22 @@ const INSTALLED = {
11
11
  version: "1.2.3",
12
12
  };
13
13
 
14
+ type ExecFn = (method: string, ...args: Array<unknown>) => Promise<unknown>;
15
+
16
+ /**
17
+ * `plugins-get-installed-plugins` resolves to `INSTALLED` (as if the plugin is
18
+ * already present) so tests unrelated to installation don't have to stub it.
19
+ */
20
+ const defaultExec: ExecFn = async (method) => {
21
+ if (method === "plugins-get-installed-plugins") return [INSTALLED];
22
+ return undefined;
23
+ };
24
+
14
25
  /**
15
- * A fake `FlipperServer` whose `exec` outcomes the test controls.
16
- *
17
- * `plugins-get-installed-plugins` resolves to `INSTALLED` by default (as if
18
- * the plugin is already present) so tests unrelated to installation don't
19
- * have to stub it; pass a custom `exec` to override that.
26
+ * A fake `FlipperServer` whose `exec` outcomes the test controls; pass a
27
+ * custom `exec` to override `defaultExec`.
20
28
  */
21
- function fakeFlipperServer(
22
- exec: (method: string, ...args: Array<unknown>) => Promise<unknown> = async (
23
- method,
24
- ) => {
25
- if (method === "plugins-get-installed-plugins") return [INSTALLED];
26
- return undefined;
27
- },
28
- ): FlipperServer {
29
+ function fakeFlipperServer(exec: ExecFn = defaultExec): FlipperServer {
29
30
  return { exec } as unknown as FlipperServer;
30
31
  }
31
32
 
@@ -33,7 +34,11 @@ function fakeFlipperServer(
33
34
  * while exercising the connection-state and plugin-activation surfaces. */
34
35
  type TransportInternals = {
35
36
  server: unknown;
36
- refcount: { peek: () => { pid: number; refs: number } | null };
37
+ refcount: {
38
+ peek: () => { pid: number; refs: number } | null;
39
+ release?: () => number | null;
40
+ acquire?: () => { shouldStart: boolean; commit: (pid: number) => void };
41
+ };
37
42
  owns: boolean;
38
43
  host: string;
39
44
  port: number;
@@ -137,13 +142,13 @@ describe("FlipperServerTransport", () => {
137
142
  (call) => call[0] === "client-request-response",
138
143
  );
139
144
  expect(installCallOrder).toBeLessThan(
140
- exec.mock.invocationCallOrder[initCall],
145
+ exec.mock.invocationCallOrder[initCall]!,
141
146
  );
142
147
  expect(exec).toHaveBeenCalledWith("plugins-get-installed-plugins");
143
148
  });
144
149
 
145
150
  it("sends init to a single client id when one is given", async () => {
146
- const exec = vi.fn(fakeFlipperServer().exec);
151
+ const exec = vi.fn(defaultExec);
147
152
  const transport = new FlipperServerTransport();
148
153
  attach(transport, fakeFlipperServer(exec), {
149
154
  connectedClientIds: ["a", "b"],
@@ -163,7 +168,7 @@ describe("FlipperServerTransport", () => {
163
168
  });
164
169
 
165
170
  it("sends init to every connected client that isn't already active when no id is given", async () => {
166
- const exec = vi.fn(fakeFlipperServer().exec);
171
+ const exec = vi.fn(defaultExec);
167
172
  const transport = new FlipperServerTransport();
168
173
  attach(transport, fakeFlipperServer(exec), {
169
174
  connectedClientIds: ["a", "b", "c"],
@@ -190,7 +195,7 @@ describe("FlipperServerTransport", () => {
190
195
  });
191
196
 
192
197
  it("still sends init to an explicit client id even if already active", async () => {
193
- const exec = vi.fn(fakeFlipperServer().exec);
198
+ const exec = vi.fn(defaultExec);
194
199
  const transport = new FlipperServerTransport();
195
200
  attach(transport, fakeFlipperServer(exec), {
196
201
  connectedClientIds: ["a"],
@@ -208,7 +213,7 @@ describe("FlipperServerTransport", () => {
208
213
 
209
214
  it("swallows a per-client failure instead of rejecting the whole call", async () => {
210
215
  vi.spyOn(console, "warn").mockImplementation(() => {});
211
- const exec = vi.fn(async (method: string, id?: string) => {
216
+ const exec = vi.fn<ExecFn>(async (method, id) => {
212
217
  if (method === "plugins-get-installed-plugins") return [INSTALLED];
213
218
  if (id === "bad") throw new Error("boom");
214
219
  return undefined;
@@ -239,7 +244,7 @@ describe("FlipperServerTransport", () => {
239
244
 
240
245
  describe("disablePlugin", () => {
241
246
  it("sends deinit to a single client id when one is given", async () => {
242
- const exec = vi.fn(fakeFlipperServer().exec);
247
+ const exec = vi.fn(defaultExec);
243
248
  const transport = new FlipperServerTransport();
244
249
  attach(transport, fakeFlipperServer(exec), { activeClientIds: ["a"] });
245
250
 
@@ -253,7 +258,7 @@ describe("FlipperServerTransport", () => {
253
258
  });
254
259
 
255
260
  it("sends deinit only to clients currently believed active when no id is given", async () => {
256
- const exec = vi.fn(fakeFlipperServer().exec);
261
+ const exec = vi.fn(defaultExec);
257
262
  const transport = new FlipperServerTransport();
258
263
  attach(transport, fakeFlipperServer(exec), {
259
264
  connectedClientIds: ["a", "b"],
@@ -543,15 +548,10 @@ describe("FlipperServerTransport", () => {
543
548
  vi.useFakeTimers();
544
549
  try {
545
550
  const transport = new FlipperServerTransport();
546
- const state = internals(transport);
547
- state.refcount = {
551
+ internals(transport).refcount = {
548
552
  peek: () => null,
549
- } as unknown as TransportInternals["refcount"];
550
- (
551
- transport as unknown as {
552
- refcount: { release: () => number | null };
553
- }
554
- ).refcount.release = () => 4242;
553
+ release: () => 4242,
554
+ };
555
555
 
556
556
  let alive = true;
557
557
  const killSpy = vi.spyOn(process, "kill").mockImplementation(((
@@ -591,17 +591,13 @@ describe("FlipperServerTransport", () => {
591
591
  const transport = new FlipperServerTransport();
592
592
 
593
593
  let releaseCalls = 0;
594
- (
595
- transport as unknown as {
596
- refcount: { release: () => number | null };
597
- }
598
- ).refcount = {
594
+ internals(transport).refcount = {
599
595
  peek: () => null,
600
596
  release: () => {
601
597
  releaseCalls += 1;
602
598
  return null;
603
599
  },
604
- } as unknown as TransportInternals["refcount"];
600
+ };
605
601
 
606
602
  const first = transport.close();
607
603
  const second = transport.close();
@@ -649,23 +645,13 @@ describe("FlipperServerTransport", () => {
649
645
  // or locally, so real net.connect attempts genuinely fail fast.
650
646
  port: 1,
651
647
  });
652
- const state = internals(transport);
653
- state.refcount = {
648
+ internals(transport).refcount = {
654
649
  peek: () => null,
655
- } as unknown as TransportInternals["refcount"];
656
- (
657
- transport as unknown as {
658
- refcount: {
659
- acquire: () => {
660
- shouldStart: boolean;
661
- commit: (pid: number) => void;
662
- };
663
- };
664
- }
665
- ).refcount.acquire = () => ({
666
- shouldStart: true,
667
- commit: vi.fn(),
668
- });
650
+ acquire: () => ({
651
+ shouldStart: true,
652
+ commit: vi.fn(),
653
+ }),
654
+ };
669
655
 
670
656
  const connectPromise = transport.connect().catch((err) => err as Error);
671
657