jest-webextension-mock 3.8.1 → 3.8.2

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.
Files changed (2) hide show
  1. package/dist/setup.js +64 -19
  2. package/package.json +3 -2
package/dist/setup.js CHANGED
@@ -18,6 +18,7 @@ var omnibox = {
18
18
  };
19
19
 
20
20
  var onMessageListeners = [];
21
+ var onMessageExternalListeners = [];
21
22
  var runtime = {
22
23
  connect: jest.fn(function (_ref) {
23
24
  var name = _ref.name;
@@ -59,6 +60,19 @@ var runtime = {
59
60
  return onMessageListeners.includes(listener);
60
61
  })
61
62
  },
63
+ onMessageExternal: {
64
+ addListener: jest.fn(function (listener) {
65
+ onMessageExternalListeners.push(listener);
66
+ }),
67
+ removeListener: jest.fn(function (listener) {
68
+ onMessageExternalListeners = onMessageExternalListeners.filter(function (lstn) {
69
+ return lstn !== listener;
70
+ });
71
+ }),
72
+ hasListener: jest.fn(function (listener) {
73
+ return onMessageExternalListeners.includes(listener);
74
+ })
75
+ },
62
76
  onConnect: {
63
77
  addListener: jest.fn(),
64
78
  removeListener: jest.fn(),
@@ -72,13 +86,18 @@ var runtime = {
72
86
  getURL: jest.fn(function (path) {
73
87
  return path;
74
88
  }),
75
- openOptionsPage: jest.fn()
89
+ openOptionsPage: jest.fn(),
90
+ getManifest: jest.fn(function () {
91
+ return {
92
+ manifest_version: 3
93
+ };
94
+ })
76
95
  };
77
96
 
78
97
  // https://developer.chrome.com/extensions/tabs
79
98
  var tabs = {
80
99
  get: jest.fn(function () {
81
- var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { };
100
+ var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
82
101
  return cb({});
83
102
  }),
84
103
  getCurrent: jest.fn(function (cb) {
@@ -119,23 +138,23 @@ var tabs = {
119
138
  }),
120
139
  duplicate: jest.fn(function () {
121
140
  var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
122
- var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { };
141
+ var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
123
142
  return cb(Object.assign({}, {
124
143
  id: id
125
144
  }));
126
145
  }),
127
146
  query: jest.fn(function () {
128
- var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { };
147
+ var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
129
148
  return cb([{}]);
130
149
  }),
131
150
  highlight: jest.fn(function () {
132
- var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () { };
151
+ var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
133
152
  return cb();
134
153
  }),
135
154
  update: jest.fn(function () {
136
155
  var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
137
156
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
138
- var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () { };
157
+ var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
139
158
  return cb(Object.assign({}, props, {
140
159
  id: id
141
160
  }));
@@ -143,7 +162,7 @@ var tabs = {
143
162
  move: jest.fn(function () {
144
163
  var ids = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
145
164
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
146
- var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () { };
165
+ var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
147
166
  return cb(ids.map(function (id) {
148
167
  return Object.assign({}, props, {
149
168
  id: id
@@ -481,20 +500,46 @@ var extension = {
481
500
  getURL: jest.fn()
482
501
  };
483
502
 
503
+ var cbOrPromise$1 = function cbOrPromise(cb, value) {
504
+ if (cb !== undefined) {
505
+ return cb(value);
506
+ }
507
+
508
+ return Promise.resolve(value);
509
+ };
510
+
484
511
  var downloads = {
485
- acceptDanger: jest.fn((downloadId, cb) => cbOrPromise(cb)),
486
- cancel: jest.fn((downloadId, cb) => cbOrPromise(cb)),
487
- download: jest.fn((options, cb) => cbOrPromise(cb)),
488
- erase: jest.fn((query, cb) => cbOrPromise(cb)),
489
- getFileIcon: jest.fn((downloadId, cb) => cbOrPromise(cb)),
512
+ acceptDanger: jest.fn(function (downloadId, cb) {
513
+ return cbOrPromise$1(cb);
514
+ }),
515
+ cancel: jest.fn(function (downloadId, cb) {
516
+ return cbOrPromise$1(cb);
517
+ }),
518
+ download: jest.fn(function (options, cb) {
519
+ return cbOrPromise$1(cb);
520
+ }),
521
+ erase: jest.fn(function (query, cb) {
522
+ return cbOrPromise$1(cb);
523
+ }),
524
+ getFileIcon: jest.fn(function (downloadId, cb) {
525
+ return cbOrPromise$1(cb);
526
+ }),
490
527
  open: jest.fn(),
491
- pause: jest.fn((downloadId, cb) => cbOrPromise(cb)),
492
- removeFile: jest.fn((downloadId, cb) => cbOrPromise(cb)),
493
- resume: jest.fn((downloadId, cb) => cbOrPromise(cb)),
494
- search: jest.fn((query, cb) => cbOrPromise(cb)),
528
+ pause: jest.fn(function (downloadId, cb) {
529
+ return cbOrPromise$1(cb);
530
+ }),
531
+ removeFile: jest.fn(function (downloadId, cb) {
532
+ return cbOrPromise$1(cb);
533
+ }),
534
+ resume: jest.fn(function (downloadId, cb) {
535
+ return cbOrPromise$1(cb);
536
+ }),
537
+ search: jest.fn(function (query, cb) {
538
+ return cbOrPromise$1(cb);
539
+ }),
495
540
  setShelfEnabled: jest.fn(),
496
541
  show: jest.fn(),
497
- showDefaultFolder: jest.fn(),
542
+ showDefaultFolder: jest.fn()
498
543
  };
499
544
 
500
545
  var geckoProfiler = {
@@ -536,9 +581,9 @@ var chrome = {
536
581
  i18n: i18n,
537
582
  webNavigation: webNavigation,
538
583
  extension: extension,
539
- downloads: downloads,
584
+ downloads: downloads
540
585
  };
541
- // Firefox uses 'browser' but aliases it to chrome
586
+ // Firefox uses 'browser' but aliases it to chrome
542
587
 
543
588
  /**
544
589
  * This is a setup file we specify as our 'main' entry point
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jest-webextension-mock",
3
- "version": "3.8.1",
3
+ "version": "3.8.2",
4
4
  "description": "Mock the components of a WebExtension",
5
5
  "main": "dist/setup.js",
6
6
  "module": "src/setup.js",
@@ -44,5 +44,6 @@
44
44
  "setupFiles": [
45
45
  "./__setups__/chrome.js"
46
46
  ]
47
- }
47
+ },
48
+ "dependencies": {}
48
49
  }