• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yext / analytics / 8058800433

27 Feb 2024 02:33AM UTC coverage: 77.075% (-2.8%) from 79.918%
8058800433

Pull #137

github

AjayBenno
Remove hardcoded api key from test site
Pull Request #137: Support Beacon fallback for stable version

63 of 86 branches covered (73.26%)

Branch coverage included in aggregate %.

1 of 10 new or added lines in 2 files covered. (10.0%)

132 of 167 relevant lines covered (79.04%)

5.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/infra/HttpRequester.ts
1
import { HttpRequesterService } from '../services';
2
import { AnalyticsPayload, EventPayload } from '../models';
3
import fetch from 'cross-fetch';
4
import { isFirefox } from '../utils/Browser';
5

6
/**
7
 * Responsible for making web requests.
8
 *
9
 */
10
export class HttpRequester implements HttpRequesterService {
11
  post(
12
    url: string,
13
    body: AnalyticsPayload | EventPayload,
14
    headers?: Record<string, string>
15
  ): Promise<Response> {
16
    const data = JSON.stringify(body);
×
17

NEW
18
    if (isFirefox()) {
×
19
      // send via beacon if the browser is using firefox since it does not support fetch w/keepalive
NEW
20
      var enqueuedEvent = navigator.sendBeacon(url, data);
×
NEW
21
      if (enqueuedEvent) {
×
NEW
22
        return Promise.resolve(new Response(null, { status: 204 }));
×
23
      } else {
24
        // If there was a failure enqueing the event just reject
25
        // with a Response that indicates an error. 
26
        // Fetch by default does not reject promises and instead just 
27
        // handles errors with a successful promise with an error that 
28
        // indicates an error
NEW
29
        return Promise.resolve(Response.error());
×
30
      }
31
    } else {
NEW
32
      const fetchInit: RequestInit = {
×
33
        method: 'POST',
34
        headers,
35
        body: data,
36
        keepalive: true
37
      };
38

NEW
39
      if (typeof (window) !== 'undefined' && window.fetch) {
×
NEW
40
        return window.fetch(url, fetchInit);
×
41
      }
NEW
42
      return fetch(url, fetchInit);
×
43
    }
44
  }
45

46

47

48
  get(url: string): Promise<Response> {
49
    const fetchInit: RequestInit = {
×
50
      method: 'GET',
51
      mode: 'no-cors',
52
      keepalive: true,
53
    };
54

55
    if (typeof (window) !== 'undefined' && window.fetch) {
×
56
      return window.fetch(url, fetchInit);
×
57
    }
58

59
    return fetch(url, fetchInit);
×
60
  }
61

62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc