File: xdomain.js

package info (click to toggle)
node-superagent 9.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,464 kB
  • sloc: javascript: 11,641; makefile: 77
file content (49 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const assert = require('assert');
const request = require('../support/client');

describe('xdomain', function () {
  this.timeout(20_000);

  // TODO (defunctzombie) I am not certain this actually forces xdomain request
  // use localtunnel.me and tunnel127.com alias instead
  it('should support req.withCredentials()', (next) => {
    request
      .get(`//${window.location.host}/xdomain`)
      .withCredentials()
      .end((error, res) => {
        assert.equal(200, res.status);
        assert.equal('tobi', res.text);
        next();
      });
  });

  // xdomain not supported in old IE and IE11 gives weird Jetty errors (looks like a SauceLabs issue)
  const isIE11 = Boolean(/Trident.*rv[ :]*11\./.test(navigator.userAgent));
  const isIE9OrOlder = !window.atob;
  if (!isIE9OrOlder && !isIE11) {
    // Don't run on IE9 or older, or IE11
    it('should handle x-domain failure', (next) => {
      request.get('//tunne127.com').end((error, res) => {
        assert(error, 'error missing');
        assert(error.crossDomain, 'not .crossDomain');
        next();
      });
    });

    it('should handle x-domain failure after repeat attempts', (next) => {
      request
        .get('//tunne127.com')
        .retry(2)
        .end((error, res) => {
          try {
            assert(error, 'error missing');
            assert(error.crossDomain, 'not .crossDomain');
            assert.equal(2, error.retries, 'expected an error with .retries');
            next();
          } catch (err) {
            next(err);
          }
        });
    });
  }
});