@flighthq/connectivity 0.3.0 → 0.3.1-next.209.43ef1bc

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/connectivity",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-next.209.43ef1bc",
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.3.0",
42
- "@flighthq/types": "0.3.0"
41
+ "@flighthq/signals": "0.3.1-next.209.43ef1bc",
42
+ "@flighthq/types": "0.3.1-next.209.43ef1bc"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.3.0"
@@ -201,16 +201,37 @@ describe('detachConnectivity', () => {
201
201
  });
202
202
 
203
203
  describe('detectConnectivityReachability', () => {
204
+ // A backend without detectReachability falls through to the web backend's own implementation, which
205
+ // calls fetch against options.url. BOTH CASES BELOW STUB fetch, because leaving it alone made this a
206
+ // real request to the public internet from a unit test: 4.1s measured here against a 5000ms default
207
+ // timeout, which full-suite load pushes it over. Egress is not what makes that a hazard — a sandboxed
208
+ // runner with no outbound network fails it every time rather than intermittently, so the current
209
+ // flakiness is a property of this machine's network rather than of the test. `unstubGlobals` restores
210
+ // the real fetch between tests.
211
+ //
212
+ // The assertion is the sentinel itself — reachable false AND latency -1 — rather than the shape of
213
+ // the value. A `typeof result.reachable === 'boolean'` check passes on a live success too, so it held
214
+ // for a test whose name promises a sentinel while checking nothing that distinguishes one.
204
215
  it('returns a sentinel when fetch is unavailable (SSR/jsdom guard)', async () => {
205
- // The web backend's detectReachability returns a sentinel in jsdom where fetch is absent or HEAD
206
- // requests fail. We install a backend without detectReachability to test the fallback path.
207
216
  setConnectivityBackend(fakeBackend());
217
+ vi.stubGlobal('fetch', undefined);
208
218
  const out: ConnectivityReachability = { latency: 0, reachable: true };
209
- // fetch is undefined in vitest/jsdom by default — expect sentinel
210
219
  const result = await detectConnectivityReachability({ url: 'https://example.com' }, out);
211
220
  expect(result).toBe(out);
212
- // In jsdom fetch may not exist or may fail; either way we get reachable=false or a live result
213
- expect(typeof result.reachable).toBe('boolean');
221
+ expect(result.reachable).toBe(false);
222
+ expect(result.latency).toBe(-1);
223
+ });
224
+
225
+ // The fallback's other sentinel path: fetch exists and the HEAD request rejects. Same contract, and
226
+ // it was unpinned — the absent-fetch branch could have returned the sentinel while this one did not.
227
+ it('returns a sentinel when the HEAD request fails', async () => {
228
+ setConnectivityBackend(fakeBackend());
229
+ vi.stubGlobal('fetch', () => Promise.reject(new Error('network unreachable')));
230
+ const out: ConnectivityReachability = { latency: 0, reachable: true };
231
+ const result = await detectConnectivityReachability({ url: 'https://example.com' }, out);
232
+ expect(result).toBe(out);
233
+ expect(result.reachable).toBe(false);
234
+ expect(result.latency).toBe(-1);
214
235
  });
215
236
 
216
237
  it('uses the backend detectReachability when available', async () => {