Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 415a963

Browse files
committedDec 15, 2021
feat: support web worker env
1 parent 1bb6936 commit 415a963

24 files changed

+317
-39
lines changed
 

‎Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ clean:
3535

3636
test: build
3737
@$(KARMA) start karma.conf.js
38+
@$(KARMA) start karma-web-worker.conf.js
3839

3940
test-sauce: build
4041
@$(KARMA) start karma.conf.js --browsers sauce_chrome_windows

‎karma-web-worker.conf.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = config => {
2+
config.set({
3+
frameworks: ['mocha-webworker'],
4+
files: [
5+
{
6+
pattern: 'test/web-worker.js',
7+
included: false,
8+
},
9+
{
10+
pattern: 'amplitude.js',
11+
included: false,
12+
},
13+
{
14+
pattern: 'node_modules/chai/chai.js',
15+
included: false,
16+
},
17+
],
18+
browsers: ['ChromeHeadless'],
19+
autoWatch: false,
20+
singleRun: true,
21+
reporters: ['mocha'],
22+
client: {
23+
mochaWebWorker: {
24+
pattern: ['test/web-worker.js', 'amplitude.js', 'node_modules/chai/chai.js'],
25+
worker: 'Worker',
26+
mocha: {
27+
ui: 'bdd'
28+
}
29+
}
30+
}
31+
});
32+
};

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"karma-firefox-launcher": "^1.0.1",
4949
"karma-mocha": "^1.3.0",
5050
"karma-mocha-reporter": "^2.2.5",
51+
"karma-mocha-webworker": "^1.3.0",
5152
"karma-sauce-launcher": "^2.0.2",
5253
"karma-sinon": "^1.0.5",
5354
"karma-sourcemap-loader": "^0.3.7",

‎src/amplitude-client.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import getHost from './get-host';
1919
import baseCookie from './base-cookie';
2020
import { AmplitudeServerZone, getEventLogApi } from './server-zone';
2121
import ConfigManager from './config-manager';
22+
import GlobalScope from './global-scope';
2223

2324
/**
2425
* AmplitudeClient SDK API - instance constructor.
@@ -28,7 +29,7 @@ import ConfigManager from './config-manager';
2829
* @example var amplitudeClient = new AmplitudeClient();
2930
*/
3031
var AmplitudeClient = function AmplitudeClient(instanceName) {
31-
if (!isBrowserEnv()) {
32+
if (!isBrowserEnv() && !utils.isWebWorkerEnvironment()) {
3233
utils.log.warn(
3334
'amplitude-js will not work in a non-browser environment. If you are planning to add Amplitude to a node environment, please use @amplitude/node',
3435
);
@@ -80,7 +81,11 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
8081

8182
try {
8283
_parseConfig(this.options, opt_config);
83-
if (isBrowserEnv() && window.Prototype !== undefined && Array.prototype.toJSON) {
84+
if (
85+
(isBrowserEnv() || utils.isWebWorkerEnvironment()) &&
86+
GlobalScope.Prototype !== undefined &&
87+
Array.prototype.toJSON
88+
) {
8489
prototypeJsFix();
8590
utils.log.warn(
8691
'Prototype.js injected Array.prototype.toJSON. Deleting Array.prototype.toJSON to prevent double-stringify',
@@ -243,7 +248,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
243248
// Monitoring just page exits because that is the most requested feature for now
244249
// "If you're specifically trying to detect page unload events, the pagehide event is the best option."
245250
// https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
246-
window.addEventListener(
251+
GlobalScope.addEventListener(
247252
'pagehide',
248253
() => {
249254
handleVisibilityChange();
@@ -254,7 +259,7 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
254259
}
255260
} catch (err) {
256261
utils.log.error(err);
257-
if (type(opt_config.onError) === 'function') {
262+
if (opt_config && type(opt_config.onError) === 'function') {
258263
opt_config.onError(err);
259264
}
260265
}
@@ -272,7 +277,7 @@ AmplitudeClient.prototype.deleteLowerLevelDomainCookies = function () {
272277
const cookieHost =
273278
this.options.domain && this.options.domain[0] === '.' ? this.options.domain.slice(1) : this.options.domain;
274279

275-
if (!cookieHost) {
280+
if (!cookieHost || !utils.isWebWorkerEnvironment()) {
276281
return;
277282
}
278283

@@ -751,14 +756,14 @@ var _sendParamsReferrerUserProperties = function _sendParamsReferrerUserProperti
751756
* @private
752757
*/
753758
AmplitudeClient.prototype._getReferrer = function _getReferrer() {
754-
return document.referrer;
759+
return typeof document !== 'undefined' ? document.referrer : '';
755760
};
756761

757762
/**
758763
* @private
759764
*/
760765
AmplitudeClient.prototype._getUrlParams = function _getUrlParams() {
761-
return location.search;
766+
return GlobalScope.location.search;
762767
};
763768

764769
/**
@@ -1779,7 +1784,7 @@ AmplitudeClient.prototype.sendEvents = function sendEvents() {
17791784
}
17801785
this._sending = true;
17811786
}
1782-
var protocol = this.options.forceHttps ? 'https' : 'https:' === window.location.protocol ? 'https' : 'http';
1787+
var protocol = this.options.forceHttps ? 'https' : 'https:' === GlobalScope.location.protocol ? 'https' : 'http';
17831788
var url = protocol + '://' + this.options.apiEndpoint;
17841789

17851790
// fetch events to send

‎src/base-cookie.js

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ const sortByEventTime = (cookies) => {
9595
// test that cookies are enabled - navigator.cookiesEnabled yields false positives in IE, need to test directly
9696
const areCookiesEnabled = (opts = {}) => {
9797
const cookieName = Constants.COOKIE_TEST_PREFIX + base64Id();
98+
if (typeof document === 'undefined') {
99+
return false;
100+
}
98101
let _areCookiesEnabled = false;
99102
try {
100103
const uid = String(new Date());

‎src/base64.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import UTF8 from './utf8';
2+
import GlobalScope from './global-scope';
23

34
/*
45
* Base64 encoder/decoder
@@ -9,8 +10,8 @@ var Base64 = {
910

1011
encode: function (input) {
1112
try {
12-
if (window.btoa && window.atob) {
13-
return window.btoa(unescape(encodeURIComponent(input)));
13+
if (GlobalScope.btoa && GlobalScope.atob) {
14+
return GlobalScope.btoa(unescape(encodeURIComponent(input)));
1415
}
1516
} catch (e) {
1617
//log(e);
@@ -53,8 +54,8 @@ var Base64 = {
5354

5455
decode: function (input) {
5556
try {
56-
if (window.btoa && window.atob) {
57-
return decodeURIComponent(escape(window.atob(input)));
57+
if (GlobalScope.btoa && GlobalScope.atob) {
58+
return decodeURIComponent(escape(GlobalScope.atob(input)));
5859
}
5960
} catch (e) {
6061
//log(e);

‎src/config-manager.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Constants from './constants';
22
import { getDynamicConfigApi } from './server-zone';
3+
import GlobalScope from './global-scope';
34
/**
45
* Dynamic Configuration
56
* Find the best server url automatically based on app users' geo location.
@@ -15,14 +16,14 @@ class ConfigManager {
1516

1617
refresh(serverZone, forceHttps, callback) {
1718
let protocol = 'https';
18-
if (!forceHttps && 'https:' !== window.location.protocol) {
19+
if (!forceHttps && 'https:' !== GlobalScope.location.protocol) {
1920
protocol = 'http';
2021
}
2122
const dynamicConfigUrl = protocol + '://' + getDynamicConfigApi(serverZone);
2223
const self = this;
23-
const isIE = window.XDomainRequest ? true : false;
24+
const isIE = GlobalScope.XDomainRequest ? true : false;
2425
if (isIE) {
25-
const xdr = new window.XDomainRequest();
26+
const xdr = new GlobalScope.XDomainRequest();
2627
xdr.open('GET', dynamicConfigUrl, true);
2728
xdr.onload = function () {
2829
const response = JSON.parse(xdr.responseText);

‎src/cookiestorage.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Cookie from './cookie';
77
import localStorage from './localstorage';
88
import baseCookie from './base-cookie';
9+
import GlobalScope from './global-scope';
910

1011
var cookieStorage = function () {
1112
this.storage = null;
@@ -43,7 +44,7 @@ cookieStorage.prototype.getStorage = function () {
4344
this._options.expirationDays = opts.expirationDays || this._options.expirationDays;
4445
// localStorage is specific to subdomains
4546
this._options.domain =
46-
opts.domain || this._options.domain || (window && window.location && window.location.hostname);
47+
opts.domain || this._options.domain || (GlobalScope && GlobalScope.location && GlobalScope.location.hostname);
4748
return (this._options.secure = opts.secure || false);
4849
},
4950
get: function (name) {

‎src/get-host.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
import GlobalScope from './global-scope';
2+
13
const getHost = (url) => {
2-
const a = document.createElement('a');
3-
a.href = url;
4-
return a.hostname || location.hostname;
4+
if (url) {
5+
if (typeof document !== 'undefined') {
6+
const a = document.createElement('a');
7+
a.href = url;
8+
return a.hostname || GlobalScope.location.hostname;
9+
}
10+
if (typeof URL === 'function') {
11+
const u = new URL(url);
12+
return u.hostname || GlobalScope.location.hostname;
13+
}
14+
}
15+
return GlobalScope.location.hostname;
516
};
617

718
export default getHost;

‎src/get-location.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import GlobalScope from './global-scope';
2+
13
const getLocation = () => {
2-
return window.location;
4+
return GlobalScope.location;
35
};
46

57
export default getLocation;

‎src/global-scope.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const GlobalScope = typeof window !== 'undefined' ? window : self;
2+
export default GlobalScope;

‎src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Entry point
22
import Amplitude from './amplitude';
3+
import GlobalScope from './global-scope';
34

4-
const old = (typeof window !== 'undefined' && window.amplitude) || {};
5+
const old = (typeof GlobalScope !== 'undefined' && GlobalScope.amplitude) || {};
56
const newInstance = new Amplitude();
67
newInstance._q = old._q || [];
78

‎src/localstorage.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
* Implement localStorage to support Firefox 2-3 and IE 5-7
33
*/
44

5+
import GlobalScope from './global-scope';
6+
import WorkerStorage from './worker-storage';
7+
import utils from './utils';
8+
59
var localStorage;
610

711
if (!BUILD_COMPAT_LOCAL_STORAGE) {
8-
localStorage = window.localStorage;
12+
localStorage = GlobalScope.localStorage;
913
}
1014

1115
if (BUILD_COMPAT_LOCAL_STORAGE) {
@@ -14,9 +18,9 @@ if (BUILD_COMPAT_LOCAL_STORAGE) {
1418
var uid = new Date();
1519
var result;
1620
try {
17-
window.localStorage.setItem(uid, uid);
18-
result = window.localStorage.getItem(uid) === String(uid);
19-
window.localStorage.removeItem(uid);
21+
GlobalScope.localStorage.setItem(uid, uid);
22+
result = GlobalScope.localStorage.getItem(uid) === String(uid);
23+
GlobalScope.localStorage.removeItem(uid);
2024
return result;
2125
} catch (e) {
2226
// localStorage not available
@@ -25,12 +29,12 @@ if (BUILD_COMPAT_LOCAL_STORAGE) {
2529
};
2630

2731
if (windowLocalStorageAvailable()) {
28-
localStorage = window.localStorage;
29-
} else if (typeof window !== 'undefined' && window.globalStorage) {
32+
localStorage = GlobalScope.localStorage;
33+
} else if (typeof GlobalScope !== 'undefined' && GlobalScope.globalStorage) {
3034
// Firefox 2-3 use globalStorage
3135
// See https://developer.mozilla.org/en/dom/storage#globalStorage
3236
try {
33-
localStorage = window.globalStorage[window.location.hostname];
37+
localStorage = GlobalScope.globalStorage[GlobalScope.location.hostname];
3438
} catch (e) {
3539
// Something bad happened...
3640
}
@@ -85,6 +89,9 @@ if (BUILD_COMPAT_LOCAL_STORAGE) {
8589
} else {
8690
/* Nothing we can do ... */
8791
}
92+
} else if (utils.isWebWorkerEnvironment()) {
93+
// Web worker
94+
localStorage = new WorkerStorage();
8895
}
8996
if (!localStorage) {
9097
/* eslint-disable no-unused-vars */

‎src/metadata-storage.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import getLocation from './get-location';
1010
import ampLocalStorage from './localstorage';
1111
import topDomain from './top-domain';
1212
import utils from './utils';
13+
import GlobalScope from './global-scope';
1314

1415
const storageOptionExists = {
1516
[Constants.STORAGE_COOKIES]: true,
@@ -88,8 +89,8 @@ class MetadataStorage {
8889

8990
switch (this.storage) {
9091
case Constants.STORAGE_SESSION:
91-
if (window.sessionStorage) {
92-
window.sessionStorage.setItem(this.storageKey, value);
92+
if (GlobalScope.sessionStorage) {
93+
GlobalScope.sessionStorage.setItem(this.storageKey, value);
9394
}
9495
break;
9596
case Constants.STORAGE_LOCAL:
@@ -131,7 +132,7 @@ class MetadataStorage {
131132
}
132133
if (!str) {
133134
try {
134-
str = window.sessionStorage && window.sessionStorage.getItem(this.storageKey);
135+
str = GlobalScope.sessionStorage && GlobalScope.sessionStorage.getItem(this.storageKey);
135136
} catch (e) {
136137
utils.log.info(`window.sessionStorage unavailable. Reason: "${e}"`);
137138
}
@@ -187,8 +188,8 @@ class MetadataStorage {
187188
}
188189
if (!str) {
189190
try {
190-
str = window.sessionStorage && window.sessionStorage.getItem(this.storageKey);
191-
window.sessionStorage.clear();
191+
str = GlobalScope.sessionStorage && GlobalScope.sessionStorage.getItem(this.storageKey);
192+
GlobalScope.sessionStorage.clear();
192193
} catch (e) {
193194
utils.log.info(`window.sessionStorage unavailable. Reason: "${e}"`);
194195
}

‎src/top-domain.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import baseCookie from './base-cookie';
22
import base64Id from './base64Id';
33
import getHost from './get-host';
4+
import utils from './utils';
45

56
// Utility that finds top level domain to write to
67
const topDomain = (url) => {
@@ -9,6 +10,8 @@ const topDomain = (url) => {
910
const levels = [];
1011
const cname = '_tldtest_' + base64Id();
1112

13+
if (utils.isWebWorkerEnvironment()) return '';
14+
1215
for (let i = parts.length - 2; i >= 0; --i) {
1316
levels.push(parts.slice(i).join('.'));
1417
}

‎src/utils.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import constants from './constants';
2+
import GlobalScope from './global-scope';
23
import type from './type';
34

45
var logLevels = {
@@ -54,7 +55,7 @@ var isEmptyString = function isEmptyString(str) {
5455

5556
var sessionStorageEnabled = function sessionStorageEnabled() {
5657
try {
57-
if (window.sessionStorage) {
58+
if (GlobalScope.sessionStorage) {
5859
return true;
5960
}
6061
} catch (e) {
@@ -273,12 +274,17 @@ var getQueryParam = function getQueryParam(name, query) {
273274
return results === null ? undefined : decodeURIComponent(results[1].replace(/\+/g, ' '));
274275
};
275276

277+
const isWebWorkerEnvironment = () => {
278+
return typeof WorkerGlobalScope !== 'undefined';
279+
};
280+
276281
export default {
277282
setLogLevel,
278283
getLogLevel,
279284
logLevels,
280285
log,
281286
isEmptyString,
287+
isWebWorkerEnvironment,
282288
getQueryParam,
283289
sessionStorageEnabled,
284290
truncate,

‎src/worker-storage.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export default class WorkerStorage {
2+
constructor() {
3+
this.map = new Map();
4+
this.length = 0;
5+
}
6+
7+
key(index) {
8+
const keys = Array.from(this.map.keys());
9+
const key = keys[index];
10+
return this.map.get(key);
11+
}
12+
13+
getItem(key) {
14+
return this.map.get(key);
15+
}
16+
17+
setItem(key, value) {
18+
if (!this.map.has(key)) {
19+
this.length += 1;
20+
}
21+
this.map.set(key, value);
22+
}
23+
24+
removeItem(key) {
25+
if (this.map.has(key)) {
26+
this.length -= 1;
27+
this.map.delete(key);
28+
}
29+
}
30+
31+
clear() {
32+
this.map.clear();
33+
}
34+
}

‎src/xhr.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import queryString from 'query-string';
2+
import GlobalScope from './global-scope';
23

34
/*
45
* Simple AJAX request object
@@ -16,9 +17,9 @@ function setHeaders(xhr, headers) {
1617
}
1718

1819
Request.prototype.send = function (callback) {
19-
var isIE = window.XDomainRequest ? true : false;
20+
var isIE = GlobalScope.XDomainRequest ? true : false;
2021
if (isIE) {
21-
var xdr = new window.XDomainRequest();
22+
var xdr = new GlobalScope.XDomainRequest();
2223
xdr.open('POST', this.url, true);
2324
xdr.onload = function () {
2425
callback(200, xdr.responseText);
@@ -34,7 +35,7 @@ Request.prototype.send = function (callback) {
3435
xdr.ontimeout = function () {};
3536
xdr.onprogress = function () {};
3637
xdr.send(queryString.stringify(this.data));
37-
} else {
38+
} else if (typeof XMLHttpRequest !== 'undefined') {
3839
var xhr = new XMLHttpRequest();
3940
xhr.open('POST', this.url, true);
4041
xhr.onreadystatechange = function () {
@@ -44,6 +45,20 @@ Request.prototype.send = function (callback) {
4445
};
4546
setHeaders(xhr, this.headers);
4647
xhr.send(queryString.stringify(this.data));
48+
} else {
49+
let responseStatus = undefined;
50+
fetch(this.url, {
51+
method: 'POST',
52+
headers: this.headers,
53+
body: queryString.stringify(this.data),
54+
})
55+
.then((response) => {
56+
responseStatus = response.status;
57+
return response.text();
58+
})
59+
.then((responseText) => {
60+
callback(responseStatus, responseText);
61+
});
4762
}
4863
//log('sent request to ' + this.url + ' with data ' + decodeURIComponent(queryString(this.data)));
4964
};

‎test/global-scope.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import GlobalScope from '../src/global-scope';
2+
3+
describe('GlobalScope', function () {
4+
it('should return true', function () {
5+
assert.isTrue(GlobalScope === window);
6+
});
7+
});

‎test/tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ import './top-domain.js';
1616
import './base64Id.js';
1717
import './server-zone.js';
1818
import './config-manager.js';
19+
import './worker-storage.js';
20+
import './global-scope.js';

‎test/utils.js

+6
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,10 @@ describe('utils', function () {
254254
assert.deepEqual(utils.validateProperties(properties), expected);
255255
});
256256
});
257+
258+
describe('isWebWorkerEnvironment', function () {
259+
it('should return false', function () {
260+
assert.isFalse(utils.isWebWorkerEnvironment());
261+
});
262+
});
257263
});

‎test/web-worker.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// eslint-disable-next-line no-undef
2+
importScripts('/base/amplitude.js');
3+
4+
var isTrue = function (a) {
5+
if (!a) {
6+
throw new Error('Assertion failed: object is falsey.');
7+
}
8+
};
9+
10+
describe('web worker', function () {
11+
describe('init', () => {
12+
it('should call init successfully', () => {
13+
let successCallbackCalled = false;
14+
let errorCallbackCalled = false;
15+
amplitude.init(
16+
'API_KEY',
17+
undefined,
18+
{
19+
onError: function onError() {
20+
errorCallbackCalled = true;
21+
},
22+
eventUploadThreshold: 1,
23+
},
24+
function callback() {
25+
successCallbackCalled = true;
26+
},
27+
);
28+
isTrue(amplitude.getInstance()._isInitialized);
29+
isTrue(amplitude.getInstance()._newSession);
30+
isTrue(successCallbackCalled);
31+
isTrue(errorCallbackCalled === false);
32+
});
33+
});
34+
35+
describe('logEvent', () => {
36+
it('should call log event successfully', () => {
37+
let sendEventsCalled = false;
38+
let errorCallbackCalled = false;
39+
amplitude.getInstance().sendEvents = () => {
40+
sendEventsCalled = true;
41+
};
42+
amplitude.logEvent(
43+
'event',
44+
{},
45+
undefined,
46+
undefined,
47+
undefined,
48+
undefined,
49+
undefined,
50+
undefined,
51+
function errorCallback() {
52+
errorCallbackCalled = true;
53+
},
54+
);
55+
isTrue(sendEventsCalled);
56+
isTrue(errorCallbackCalled === false);
57+
});
58+
});
59+
});

‎test/worker-storage.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import WorkerStorage from '../src/worker-storage';
2+
3+
describe('WorkerStorage', function () {
4+
describe('constructor', function () {
5+
it('should return an instance', function () {
6+
const workerStorage = new WorkerStorage();
7+
assert.isTrue(workerStorage.map instanceof Map);
8+
assert.isTrue(workerStorage.length === 0);
9+
});
10+
});
11+
12+
describe('key', function () {
13+
it('should return one', function () {
14+
const workerStorage = new WorkerStorage();
15+
workerStorage.setItem('0', 'zero');
16+
workerStorage.setItem('1', 'one');
17+
assert.isTrue(workerStorage.key(1) === 'one');
18+
});
19+
});
20+
21+
describe('setItem/getItem', function () {
22+
it('should assign and return zero', function () {
23+
const workerStorage = new WorkerStorage();
24+
workerStorage.setItem('0', 'zero');
25+
assert.isTrue(workerStorage.getItem('0') === 'zero');
26+
});
27+
});
28+
29+
describe('removeItem', function () {
30+
it('should remove single item', function () {
31+
const workerStorage = new WorkerStorage();
32+
workerStorage.setItem('0', 'zero');
33+
workerStorage.removeItem('0');
34+
assert.isTrue(workerStorage.getItem('0') === undefined);
35+
});
36+
});
37+
38+
describe('clear', function () {
39+
it('should clear storage', function () {
40+
const workerStorage = new WorkerStorage();
41+
workerStorage.setItem('0', 'zero');
42+
workerStorage.setItem('1', 'one');
43+
workerStorage.clear();
44+
assert.isTrue(workerStorage.getItem('0') === undefined);
45+
assert.isTrue(workerStorage.getItem('1') === undefined);
46+
});
47+
});
48+
});

‎yarn.lock

+31-2
Original file line numberDiff line numberDiff line change
@@ -4370,6 +4370,15 @@ json5@^2.1.0:
43704370
dependencies:
43714371
minimist "^1.2.0"
43724372

4373+
jsonbird@^2.0.0:
4374+
version "2.2.2"
4375+
resolved "https://registry.yarnpkg.com/jsonbird/-/jsonbird-2.2.2.tgz#9a56fff493bb10c18b1717d3e559e70d375d5a94"
4376+
integrity sha512-48n9HTL6Vxhr6WqX78ROH5NddK//ZnSdu1ZnPyyOl9IzF2PyRmwC8nCKPiRFo1wx7/Byq5YezCqokq9T/McLhw==
4377+
dependencies:
4378+
jsonparse "^1.2.0"
4379+
readable-stream "^2.1.4"
4380+
shortid "^2.2.6"
4381+
43734382
jsonfile@^4.0.0:
43744383
version "4.0.0"
43754384
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
@@ -4443,6 +4452,14 @@ karma-mocha-reporter@^2.2.5:
44434452
log-symbols "^2.1.0"
44444453
strip-ansi "^4.0.0"
44454454

4455+
karma-mocha-webworker@^1.3.0:
4456+
version "1.3.0"
4457+
resolved "https://registry.yarnpkg.com/karma-mocha-webworker/-/karma-mocha-webworker-1.3.0.tgz#b5a4301b59ba86a08ee5b5f0aef1edb863becb26"
4458+
integrity sha1-taQwG1m6hqCO5bXwrvHtuGO+yyY=
4459+
dependencies:
4460+
jsonbird "^2.0.0"
4461+
minimatch "^3.0.3"
4462+
44464463
karma-mocha@^1.3.0:
44474464
version "1.3.0"
44484465
resolved "https://registry.yarnpkg.com/karma-mocha/-/karma-mocha-1.3.0.tgz#eeaac7ffc0e201eb63c467440d2b69c7cf3778bf"
@@ -5212,7 +5229,7 @@ min-indent@^1.0.0:
52125229
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869"
52135230
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==
52145231

5215-
minimatch@^3.0.2, minimatch@^3.0.4:
5232+
minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
52165233
version "3.0.4"
52175234
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
52185235
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
@@ -5364,6 +5381,11 @@ nan@^2.9.2:
53645381
resolved "https://registry.yarnpkg.com/nan/-/nan-2.12.1.tgz#7b1aa193e9aa86057e3c7bbd0ac448e770925552"
53655382
integrity sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw==
53665383

5384+
nanoid@^2.1.0:
5385+
version "2.1.11"
5386+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.11.tgz#ec24b8a758d591561531b4176a01e3ab4f0f0280"
5387+
integrity sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==
5388+
53675389
nanomatch@^1.2.9:
53685390
version "1.2.13"
53695391
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -6557,7 +6579,7 @@ read@1, read@~1.0.1, read@~1.0.7:
65576579
dependencies:
65586580
mute-stream "~0.0.4"
65596581

6560-
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.6, readable-stream@~2.3.6:
6582+
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.6, readable-stream@~2.3.6:
65616583
version "2.3.7"
65626584
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
65636585
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
@@ -7216,6 +7238,13 @@ shebang-regex@^3.0.0:
72167238
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
72177239
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
72187240

7241+
shortid@^2.2.6:
7242+
version "2.2.16"
7243+
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.16.tgz#b742b8f0cb96406fd391c76bfc18a67a57fe5608"
7244+
integrity sha512-Ugt+GIZqvGXCIItnsL+lvFJOiN7RYqlGy7QE41O3YC1xbNSeDGIRO7xg2JJXIAj1cAGnOeC1r7/T9pgrtQbv4g==
7245+
dependencies:
7246+
nanoid "^2.1.0"
7247+
72197248
signal-exit@^3.0.0, signal-exit@^3.0.2:
72207249
version "3.0.3"
72217250
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"

0 commit comments

Comments
 (0)
Please sign in to comment.