forked from localForage/localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.webworkers.js
67 lines (56 loc) · 1.9 KB
/
test.webworkers.js
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
63
64
65
66
67
/* global before:true, beforeEach:true, describe:true, expect:true, it:true, Modernizr:true */
var DRIVERS = [
localforage.INDEXEDDB,
localforage.LOCALSTORAGE,
localforage.WEBSQL
];
DRIVERS.forEach(function(driverName) {
if (
(!localforage.supports(localforage.INDEXEDDB) &&
driverName === localforage.INDEXEDDB) ||
(!localforage.supports(localforage.LOCALSTORAGE) &&
driverName === localforage.LOCALSTORAGE) ||
(!localforage.supports(localforage.WEBSQL) &&
driverName === localforage.WEBSQL)
) {
// Browser doesn't support this storage library, so we exit the API
// tests.
return;
}
describe('Web Worker support in ' + driverName, function() {
'use strict';
before(function(done) {
localforage.setDriver(driverName).then(done);
});
beforeEach(function(done) {
localforage.clear(done);
});
if (!Modernizr.webworkers) {
it.skip("doesn't have web worker support");
return;
}
if (
driverName === localforage.LOCALSTORAGE ||
driverName === localforage.WEBSQL
) {
it.skip(driverName + ' is not supported in web workers');
return;
}
it('saves data', function(done) {
var webWorker = new Worker('/test/webworker-client.js');
webWorker.addEventListener('message', function(e) {
var body = e.data.body;
window.console.log(body);
expect(body).to.be('I have been set');
done();
});
webWorker.addEventListener('error', function(e) {
window.console.log(e);
});
webWorker.postMessage({
driver: driverName,
value: 'I have been set'
});
});
});
});