@flighthq/platform 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/platform.test.ts +81 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/platform",
|
|
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/types": "0.4.0-next.
|
|
42
|
-
"@flighthq/useragent": "0.4.0-next.
|
|
41
|
+
"@flighthq/types": "0.4.0-next.1908.751021c",
|
|
42
|
+
"@flighthq/useragent": "0.4.0-next.1908.751021c"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.3.0"
|
package/src/platform.test.ts
CHANGED
|
@@ -17,6 +17,10 @@ import {
|
|
|
17
17
|
isPlatformVersionAtLeast,
|
|
18
18
|
isPlatformWeb,
|
|
19
19
|
setPlatformBackend,
|
|
20
|
+
explainPlatformBackend,
|
|
21
|
+
installPlatformHostBackend,
|
|
22
|
+
observePlatformHostResult,
|
|
23
|
+
resetPlatformBackendForTest,
|
|
20
24
|
} from './platform';
|
|
21
25
|
|
|
22
26
|
function fakeBackend(info: Partial<PlatformInfo>): PlatformBackend {
|
|
@@ -141,6 +145,34 @@ describe('createWebPlatformBackend', () => {
|
|
|
141
145
|
});
|
|
142
146
|
});
|
|
143
147
|
|
|
148
|
+
describe('explainPlatformBackend', () => {
|
|
149
|
+
afterEach(() => resetPlatformBackendForTest());
|
|
150
|
+
|
|
151
|
+
it('reports host-not-enabled when no backend is installed', () => {
|
|
152
|
+
resetPlatformBackendForTest();
|
|
153
|
+
const explanation = explainPlatformBackend();
|
|
154
|
+
expect(explanation.layer).toBe('host-not-enabled');
|
|
155
|
+
expect(explanation.conflict).toBe(false);
|
|
156
|
+
expect(explanation.viability).toBe('unobserved');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('reports custom layer when a custom backend is set', () => {
|
|
160
|
+
setPlatformBackend(fakeBackend({}));
|
|
161
|
+
expect(explainPlatformBackend().layer).toBe('custom');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('reports host layer when a host backend is installed', () => {
|
|
165
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
166
|
+
expect(explainPlatformBackend().layer).toBe('host');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('reports conflict when two different host backends are installed', () => {
|
|
170
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
171
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
172
|
+
expect(explainPlatformBackend().conflict).toBe(true);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
144
176
|
describe('getPlatformBackend', () => {
|
|
145
177
|
it('falls back to a web backend when none is registered', () => {
|
|
146
178
|
expect(getPlatformBackend()).not.toBeNull();
|
|
@@ -226,6 +258,25 @@ describe('getPlatformRuntime', () => {
|
|
|
226
258
|
});
|
|
227
259
|
});
|
|
228
260
|
|
|
261
|
+
describe('installPlatformHostBackend', () => {
|
|
262
|
+
afterEach(() => resetPlatformBackendForTest());
|
|
263
|
+
|
|
264
|
+
it('installs a host backend that getPlatformBackend returns', () => {
|
|
265
|
+
const backend = fakeBackend({});
|
|
266
|
+
installPlatformHostBackend(backend);
|
|
267
|
+
expect(getPlatformBackend()).toBe(backend);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('is first-host-wins: a second different backend sets conflict', () => {
|
|
271
|
+
const first = fakeBackend({});
|
|
272
|
+
const second = fakeBackend({});
|
|
273
|
+
installPlatformHostBackend(first);
|
|
274
|
+
installPlatformHostBackend(second);
|
|
275
|
+
expect(getPlatformBackend()).toBe(first);
|
|
276
|
+
expect(explainPlatformBackend().conflict).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
229
280
|
describe('isPlatformDesktop', () => {
|
|
230
281
|
it('is true only for desktop kind', () => {
|
|
231
282
|
setPlatformBackend(fakeBackend({ kind: 'desktop' }));
|
|
@@ -317,6 +368,36 @@ describe('isPlatformWeb', () => {
|
|
|
317
368
|
});
|
|
318
369
|
});
|
|
319
370
|
|
|
371
|
+
describe('observePlatformHostResult', () => {
|
|
372
|
+
afterEach(() => resetPlatformBackendForTest());
|
|
373
|
+
|
|
374
|
+
it('records a successful observation', () => {
|
|
375
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
376
|
+
observePlatformHostResult('getInfo', true);
|
|
377
|
+
const explanation = explainPlatformBackend();
|
|
378
|
+
expect(explanation.operation).toBe('getInfo');
|
|
379
|
+
expect(explanation.viability).toBe('available');
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it('records a failed observation', () => {
|
|
383
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
384
|
+
observePlatformHostResult('getInfo', false);
|
|
385
|
+
expect(explainPlatformBackend().viability).toBe('runtime-api-unavailable');
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
describe('resetPlatformBackendForTest', () => {
|
|
390
|
+
it('clears all backend slots', () => {
|
|
391
|
+
setPlatformBackend(fakeBackend({}));
|
|
392
|
+
installPlatformHostBackend(fakeBackend({}));
|
|
393
|
+
observePlatformHostResult('getInfo', true);
|
|
394
|
+
resetPlatformBackendForTest();
|
|
395
|
+
expect(explainPlatformBackend().layer).toBe('host-not-enabled');
|
|
396
|
+
expect(explainPlatformBackend().conflict).toBe(false);
|
|
397
|
+
expect(explainPlatformBackend().viability).toBe('unobserved');
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
320
401
|
describe('setPlatformBackend', () => {
|
|
321
402
|
it('clears back to the web fallback when passed null', () => {
|
|
322
403
|
setPlatformBackend(fakeBackend({ name: 'linux' }));
|