@flighthq/connectivity 0.4.0-next.1903.50bfa67 → 0.4.0-next.1908.751021c
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 +3 -3
- package/src/connectivity.test.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/connectivity",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.1908.751021c",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@flighthq/signals": "0.4.0-next.
|
|
42
|
-
"@flighthq/types": "0.4.0-next.
|
|
41
|
+
"@flighthq/signals": "0.4.0-next.1908.751021c",
|
|
42
|
+
"@flighthq/types": "0.4.0-next.1908.751021c"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
package/src/connectivity.test.ts
CHANGED
|
@@ -16,6 +16,10 @@ import {
|
|
|
16
16
|
isConnectivityOnline,
|
|
17
17
|
isConnectivitySaveDataEnabled,
|
|
18
18
|
setConnectivityBackend,
|
|
19
|
+
explainConnectivityBackend,
|
|
20
|
+
installConnectivityHostBackend,
|
|
21
|
+
observeConnectivityHostResult,
|
|
22
|
+
resetConnectivityBackendForTest,
|
|
19
23
|
} from './connectivity';
|
|
20
24
|
|
|
21
25
|
function fakeBackend(
|
|
@@ -266,6 +270,34 @@ describe('disposeConnectivity', () => {
|
|
|
266
270
|
});
|
|
267
271
|
});
|
|
268
272
|
|
|
273
|
+
describe('explainConnectivityBackend', () => {
|
|
274
|
+
afterEach(() => resetConnectivityBackendForTest());
|
|
275
|
+
|
|
276
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
277
|
+
resetConnectivityBackendForTest();
|
|
278
|
+
const explanation = explainConnectivityBackend();
|
|
279
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
280
|
+
expect(explanation.conflict).toBe(false);
|
|
281
|
+
expect(explanation.viability).toBe('unobserved');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
285
|
+
setConnectivityBackend(fakeBackend());
|
|
286
|
+
expect(explainConnectivityBackend().layer).toBe('custom');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('reports host layer when a host backend is installed', () => {
|
|
290
|
+
installConnectivityHostBackend(fakeBackend());
|
|
291
|
+
expect(explainConnectivityBackend().layer).toBe('host');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
295
|
+
installConnectivityHostBackend(fakeBackend());
|
|
296
|
+
installConnectivityHostBackend(fakeBackend());
|
|
297
|
+
expect(explainConnectivityBackend().conflict).toBe(true);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
|
|
269
301
|
describe('getConnectivityBackend', () => {
|
|
270
302
|
it('falls back to a web backend', () => {
|
|
271
303
|
expect(getConnectivityBackend()).not.toBeNull();
|
|
@@ -326,6 +358,25 @@ describe('hasConnectivityStatusChanged', () => {
|
|
|
326
358
|
});
|
|
327
359
|
});
|
|
328
360
|
|
|
361
|
+
describe('installConnectivityHostBackend', () => {
|
|
362
|
+
afterEach(() => resetConnectivityBackendForTest());
|
|
363
|
+
|
|
364
|
+
it('installs a host backend that getConnectivityBackend returns', () => {
|
|
365
|
+
const backend = fakeBackend();
|
|
366
|
+
installConnectivityHostBackend(backend);
|
|
367
|
+
expect(getConnectivityBackend()).toBe(backend);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
371
|
+
const first = fakeBackend();
|
|
372
|
+
const second = fakeBackend();
|
|
373
|
+
installConnectivityHostBackend(first);
|
|
374
|
+
installConnectivityHostBackend(second);
|
|
375
|
+
expect(getConnectivityBackend()).toBe(first);
|
|
376
|
+
expect(explainConnectivityBackend().conflict).toBe(true);
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
|
|
329
380
|
describe('isConnectivityMetered', () => {
|
|
330
381
|
it('returns false for a non-metered connection', () => {
|
|
331
382
|
setConnectivityBackend(fakeBackend({ metered: false }));
|
|
@@ -363,6 +414,36 @@ describe('isConnectivitySaveDataEnabled', () => {
|
|
|
363
414
|
});
|
|
364
415
|
});
|
|
365
416
|
|
|
417
|
+
describe('observeConnectivityHostResult', () => {
|
|
418
|
+
afterEach(() => resetConnectivityBackendForTest());
|
|
419
|
+
|
|
420
|
+
it('records a successful observation', () => {
|
|
421
|
+
installConnectivityHostBackend(fakeBackend());
|
|
422
|
+
observeConnectivityHostResult('getStatus', true);
|
|
423
|
+
const explanation = explainConnectivityBackend();
|
|
424
|
+
expect(explanation.operation).toBe('getStatus');
|
|
425
|
+
expect(explanation.viability).toBe('available');
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('records a failed observation', () => {
|
|
429
|
+
installConnectivityHostBackend(fakeBackend());
|
|
430
|
+
observeConnectivityHostResult('getStatus', false);
|
|
431
|
+
expect(explainConnectivityBackend().viability).toBe('runtime-api-unavailable');
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
describe('resetConnectivityBackendForTest', () => {
|
|
436
|
+
it('clears all backend slots', () => {
|
|
437
|
+
setConnectivityBackend(fakeBackend());
|
|
438
|
+
installConnectivityHostBackend(fakeBackend());
|
|
439
|
+
observeConnectivityHostResult('getStatus', true);
|
|
440
|
+
resetConnectivityBackendForTest();
|
|
441
|
+
expect(explainConnectivityBackend().layer).toBe('host-not-enabled');
|
|
442
|
+
expect(explainConnectivityBackend().conflict).toBe(false);
|
|
443
|
+
expect(explainConnectivityBackend().viability).toBe('unobserved');
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
366
447
|
describe('setConnectivityBackend', () => {
|
|
367
448
|
it('clears back to the web fallback when passed null', () => {
|
|
368
449
|
setConnectivityBackend(fakeBackend());
|