forked from dexie/Dexie.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests-chrome-transaction-durability.js
91 lines (80 loc) · 2.79 KB
/
tests-chrome-transaction-durability.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
88
89
90
91
import Dexie from 'dexie';
import {start, asyncTest, ok} from 'QUnit';
import {isChrome, resetDatabase} from './dexie-unittest-utils';
"use strict";
module("chrome-transaction-durability", {
setup: function () {
},
teardown: function () {
}
});
asyncTest("Transaction should use relaxed durability if specified", function() {
if (!isChrome) {
ok(true, "This browser does not support Chrome transaction durability");
start();
return;
}
const db = setupDb('relaxed')
db.transaction('rw', db.users, trans => {
if (trans.idbtrans.durability === void 0) {
ok(true, "This version of Chromium does not support transaction durability");
} else {
ok(trans.idbtrans.durability === 'relaxed', "Transaction has relaxed durability");
}
}).catch(function (err) {
ok(false, err);
}).finally(function () {
resetDatabase(db).catch(function (e) {
ok(false, "Error resetting database: " + e.stack);
}).finally(start);
});
});
asyncTest("Transaction should use strict durability if specified", function() {
if (!isChrome) {
ok(true, "This browser does not support Chrome transaction durability");
start();
return;
}
const db = setupDb('strict')
db.transaction('rw', db.users, trans => {
if (trans.idbtrans.durability === void 0) {
ok(true, "This version of Chromium does not support transaction durability");
} else {
ok(trans.idbtrans.durability === 'strict', "Transaction has strict durability");
}
}).catch(function (err) {
ok(false, err);
}).finally(function () {
resetDatabase(db).catch(function (e) {
ok(false, "Error resetting database: " + e.stack);
}).finally(start);
});
});
asyncTest("Transaction should use default durability if not specified", function() {
if (!isChrome) {
ok(true, "This browser does not support Chrome transaction durability");
start();
return;
}
const db = setupDb()
db.transaction('rw', db.users, trans => {
if (trans.idbtrans.durability === void 0) {
ok(true, "This version of Chromium does not support transaction durability");
} else {
ok(trans.idbtrans.durability === 'default', "Transaction has default durability");
}
}).catch(function (err) {
ok(false, err);
}).finally(function () {
resetDatabase(db).catch(function (e) {
ok(false, "Error resetting database: " + e.stack);
}).finally(start);
});
});
const setupDb = (chromeTransactionDurability) => {
const db = new Dexie("TestDBTrans", { chromeTransactionDurability });
db.version(1).stores({
users: "username",
});
return db;
}