forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.worker.js
87 lines (73 loc) · 2.33 KB
/
browser.worker.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
var sourceFile = window.location.search.match(/[?&]sourceFile=([^&]+)/);
if (!sourceFile) {
sourceFile = '../dist/pouchdb.js';
} else {
sourceFile = '../dist/' + sourceFile[1];
}
if (typeof window.Worker === 'function') {
runTests();
}
function runTests() {
describe('browser.worker.js', function () {
var dbs = {};
beforeEach(function (done) {
dbs.name = testUtils.adapterUrl('local', 'test_worker');
dbs.remote = testUtils.adapterUrl('http', 'test_worker_remote');
testUtils.cleanup([dbs.name, dbs.remote], done);
});
after(function (done) {
testUtils.cleanup([dbs.name, dbs.remote], done);
});
it('create it', function (done) {
var worker = new Worker('worker.js');
worker.addEventListener('message', function (e) {
e.data.should.equal('pong');
worker.terminate();
done();
});
worker.postMessage(sourceFile);
worker.postMessage('ping');
});
it('check pouch version', function (done) {
var worker = new Worker('worker.js');
worker.addEventListener('message', function (e) {
PouchDB.version.should.equal(e.data);
worker.terminate();
done();
});
worker.postMessage(sourceFile);
worker.postMessage('version');
});
it('create remote db', function (done) {
var worker = new Worker('worker.js');
worker.addEventListener('error', function (e) {
throw e;
});
worker.addEventListener('message', function (e) {
e.data.should.equal('lala');
worker.terminate();
done();
});
worker.postMessage(sourceFile);
worker.postMessage(['create', dbs.remote]);
});
// Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=701634
// IE bug: https://connect.microsoft.com/IE/feedback/details/866495
if (!('mozIndexedDB' in window || 'msIndexedDB' in window)) {
it('create local db', function (done) {
var worker = new Worker('worker.js');
worker.addEventListener('error', function (e) {
throw e;
});
worker.addEventListener('message', function (e) {
e.data.should.equal('lala');
worker.terminate();
done();
});
worker.postMessage(sourceFile);
worker.postMessage(['create', dbs.name]);
});
}
});
}