jest-webextension-mock 3.8.1 → 3.8.3

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.
@@ -7,26 +7,16 @@ name: Publish
7
7
 
8
8
  jobs:
9
9
  all:
10
- name: Publish
10
+ name: Merge-Release
11
11
  runs-on: ubuntu-latest
12
12
  steps:
13
- - uses: actions/checkout@v2
14
- - name: Get yarn cache directory path
15
- id: yarn-cache-dir-path
16
- run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
17
- - uses: actions/cache@v2
18
- id: yarn-cache
19
- with:
20
- path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
21
- key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
22
- restore-keys: ${{ runner.os }}-yarn-
23
- - name: Yarn Install
24
- run: yarn install
25
- - name: Yarn Test
26
- run: yarn test
27
- - name: Publish
13
+ - uses: actions/checkout@v3
14
+ - run: npm ci
15
+ - run: npm test
16
+ - run: npm run build --if-present
17
+ - run: git status --porcelain dist/setup.js
18
+ - uses: mikeal/merge-release@master
28
19
  if: github.ref == 'refs/heads/main'
29
- uses: mikeal/merge-release@master
30
20
  env:
31
21
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32
22
  NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
@@ -15,20 +15,15 @@ jobs:
15
15
  node-version: [14.x, 16.x, 18.x]
16
16
 
17
17
  steps:
18
- - uses: actions/checkout@v2
19
- - name: Get yarn cache directory path
20
- id: yarn-cache-dir-path
21
- run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
22
- - uses: actions/cache@v2
23
- id: yarn-cache
18
+ - uses: actions/checkout@v3
24
19
  with:
25
- path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
26
- key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
27
- restore-keys: ${{ runner.os }}-yarn-
28
- - name: Use Node.js ${{ matrix.node-version }}
29
- uses: actions/setup-node@v1
20
+ fetch-depth: 2
21
+ - name: node.js ${{ matrix.node-version }}
22
+ uses: actions/setup-node@v3
30
23
  with:
31
24
  node-version: ${{ matrix.node-version }}
32
- - run: yarn install
33
- - run: yarn test
34
- - uses: codecov/codecov-action@v1
25
+ - run: npm ci
26
+ - run: npm test
27
+ - run: npm run build --if-present
28
+ - run: git status --porcelain dist/setup.js
29
+ - uses: codecov/codecov-action@v3
package/README.md CHANGED
@@ -2,17 +2,16 @@
2
2
 
3
3
  ## Install
4
4
 
5
-
6
- For yarn:
5
+ For npm:
7
6
 
8
7
  ```bash
9
- yarn add --dev jest-webextension-mock
8
+ npm i --save-dev jest-webextension-mock
10
9
  ```
11
10
 
12
- For npm:
11
+ For yarn:
13
12
 
14
13
  ```bash
15
- npm i --save-dev jest-webextension-mock
14
+ yarn add --dev jest-webextension-mock
16
15
  ```
17
16
 
18
17
  ## Setup
@@ -98,8 +97,8 @@ it('should toggle the profiler on from stopped', () => {
98
97
  ## Development
99
98
 
100
99
  ```
101
- yarn install
102
- yarn test
100
+ npm install
101
+ npm test
103
102
  ```
104
103
 
105
104
  ## Publish
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
@@ -174,17 +193,11 @@ var tabs = {
174
193
  function _typeof(obj) {
175
194
  "@babel/helpers - typeof";
176
195
 
177
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
178
- _typeof = function (obj) {
179
- return typeof obj;
180
- };
181
- } else {
182
- _typeof = function (obj) {
183
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
184
- };
185
- }
186
-
187
- return _typeof(obj);
196
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
197
+ return typeof obj;
198
+ } : function (obj) {
199
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
200
+ }, _typeof(obj);
188
201
  }
189
202
 
190
203
  var store = {};
@@ -406,7 +419,7 @@ var commands = {
406
419
  }
407
420
  };
408
421
 
409
- var cbOrPromise = function cbOrPromise(cb, value) {
422
+ var cbOrPromise$1 = function cbOrPromise(cb, value) {
410
423
  if (cb !== undefined) {
411
424
  return cb(value);
412
425
  }
@@ -423,22 +436,22 @@ var create = function create(notificationId, options, cb) {
423
436
  cb = options;
424
437
  }
425
438
 
426
- return cbOrPromise(cb, notificationId);
439
+ return cbOrPromise$1(cb, notificationId);
427
440
  };
428
441
 
429
442
  var notifications = {
430
443
  create: jest.fn(create),
431
444
  update: jest.fn(function (notificationId, options, cb) {
432
- return cbOrPromise(cb, true);
445
+ return cbOrPromise$1(cb, true);
433
446
  }),
434
447
  clear: jest.fn(function (notificationId, cb) {
435
- return cbOrPromise(cb, true);
448
+ return cbOrPromise$1(cb, true);
436
449
  }),
437
450
  getAll: jest.fn(function (cb) {
438
- return cbOrPromise(cb, []);
451
+ return cbOrPromise$1(cb, []);
439
452
  }),
440
453
  getPermissionLevel: jest.fn(function (cb) {
441
- return cbOrPromise(cb, 'granted');
454
+ return cbOrPromise$1(cb, 'granted');
442
455
  }),
443
456
  onClosed: {
444
457
  addListener: jest.fn()
@@ -481,20 +494,46 @@ var extension = {
481
494
  getURL: jest.fn()
482
495
  };
483
496
 
497
+ var cbOrPromise = function cbOrPromise(cb, value) {
498
+ if (cb !== undefined) {
499
+ return cb(value);
500
+ }
501
+
502
+ return Promise.resolve(value);
503
+ };
504
+
484
505
  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)),
506
+ acceptDanger: jest.fn(function (downloadId, cb) {
507
+ return cbOrPromise(cb);
508
+ }),
509
+ cancel: jest.fn(function (downloadId, cb) {
510
+ return cbOrPromise(cb);
511
+ }),
512
+ download: jest.fn(function (options, cb) {
513
+ return cbOrPromise(cb);
514
+ }),
515
+ erase: jest.fn(function (query, cb) {
516
+ return cbOrPromise(cb);
517
+ }),
518
+ getFileIcon: jest.fn(function (downloadId, cb) {
519
+ return cbOrPromise(cb);
520
+ }),
490
521
  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)),
522
+ pause: jest.fn(function (downloadId, cb) {
523
+ return cbOrPromise(cb);
524
+ }),
525
+ removeFile: jest.fn(function (downloadId, cb) {
526
+ return cbOrPromise(cb);
527
+ }),
528
+ resume: jest.fn(function (downloadId, cb) {
529
+ return cbOrPromise(cb);
530
+ }),
531
+ search: jest.fn(function (query, cb) {
532
+ return cbOrPromise(cb);
533
+ }),
495
534
  setShelfEnabled: jest.fn(),
496
535
  show: jest.fn(),
497
- showDefaultFolder: jest.fn(),
536
+ showDefaultFolder: jest.fn()
498
537
  };
499
538
 
500
539
  var geckoProfiler = {
@@ -536,9 +575,9 @@ var chrome = {
536
575
  i18n: i18n,
537
576
  webNavigation: webNavigation,
538
577
  extension: extension,
539
- downloads: downloads,
578
+ downloads: downloads
540
579
  };
541
- // Firefox uses 'browser' but aliases it to chrome
580
+ // Firefox uses 'browser' but aliases it to chrome
542
581
 
543
582
  /**
544
583
  * 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.3",
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
  }