Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unittests.js « test - github.com/openpgpjs/openpgpjs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 13871f381e7552263d39ee73ee9544b0db7adbe4 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('..');

(typeof window !== 'undefined' ? window : global).globalThis = (typeof window !== 'undefined' ? window : global);

(typeof window !== 'undefined' ? window : global).resolves = function(val) {
  return new Promise(function(res) { res(val); });
};

(typeof window !== 'undefined' ? window : global).rejects = function(val) {
  return new Promise(function(res, rej) { rej(val); });
};

(typeof window !== 'undefined' ? window : global).tryTests = function(name, tests, options) {
  if (options.if) {
    describe(name, function() {
      if (options.before) { before(options.before); }
      if (options.beforeEach) { beforeEach(options.beforeEach); }

      tests();

      if (options.afterEach) { afterEach(options.afterEach); }
      if (options.after) { after(options.after); }
    });
  } else {
    describe.skip(name + ' (no support --> skipping tests)', tests);
  }
};

describe('Unit Tests', function () {

  openpgp.config.s2kIterationCountByte = 0;

  if (typeof window !== 'undefined') {
    // Safari 14.1.* seem to have issues handling rejections when their native TransformStream implementation is involved,
    // so for now we ignore unhandled rejections for those browser versions.
    if (!window.navigator.userAgent.match(/Version\/14\.1(\.\d)* Safari/)) {
      window.addEventListener('unhandledrejection', function (event) {
        throw event.reason;
      });
    }

    window.location.search.substr(1).split('&').forEach(param => {
      const [key, value] = param.split('=');
      if (key && key !== 'grep') {
        openpgp.config[key] = decodeURIComponent(value);
        try {
          openpgp.config[key] = window.eval(openpgp.config[key]); // eslint-disable-line no-eval
        } catch (e) {}
      }
    });
  } else {
    process.on('unhandledRejection', error => {
      console.error(error); // eslint-disable-line no-console
      process.exit(1); // eslint-disable-line no-process-exit
    });
  }

  require('./crypto')();
  require('./general')();
  require('./worker')();
  require('./security')();
});