-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathrender.test.js
84 lines (73 loc) · 2.82 KB
/
render.test.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
const assert = require('assert');
const {
createRxDatabase,
addRxPlugin,
getBroadcastChannelReference,
createBlob
} = require('rxdb');
const { RxDBLeaderElectionPlugin } = require('rxdb/plugins/leader-election');
const { RxDBAttachmentsPlugin } = require('rxdb/plugins/attachments');
const { getRxStorageMemory } = require('rxdb/plugins/storage-memory');
const { wrappedValidateAjvStorage } = require('rxdb/plugins/validate-ajv');
addRxPlugin(RxDBLeaderElectionPlugin);
addRxPlugin(RxDBAttachmentsPlugin);
/**
* this tests run inside of the browser-windows so we can ensure
* rxdb works correctly
*/
module.exports = (function () {
const runTests = async function () {
// issue #587 Incorrect working attachments in electron-render
await (async function () {
const db = await createRxDatabase({
// generate simple random ID to avoid conflicts when running tests at the same time
name: 'foobar587' + Math.round(Math.random() * 0xffffff).toString(16),
storage: wrappedValidateAjvStorage({ storage: getRxStorageMemory() }),
password: 'myLongAndStupidPassword',
multiInstance: true
});
await db.waitForLeadership();
const broadcastChannel = getBroadcastChannelReference(
db.token,
db.name,
{}
);
if (broadcastChannel.method.type !== 'native') {
throw new Error('wrong BroadcastChannel-method chosen: ' + db.broadcastChannel.method.type);
}
await db.addCollections({
heroes: {
schema: {
primaryKey: 'id',
version: 0,
type: 'object',
properties: {
id: {
type: 'string',
maxLength: 100
}
},
attachments: {}
}
}
});
const doc = await db.heroes.insert({
id: 'foo'
});
assert.ok(doc);
const dataString = 'foo bar asldfkjalkdsfj';
const attachmentData = createBlob(dataString, 'text/plain');
const attachment = await doc.putAttachment({
id: 'cat.jpg',
data: attachmentData,
type: 'text/plain'
});
assert.ok(attachment);
// issue #1371 Attachments not working in electron renderer with idb
const readData = await attachment.getStringData();
assert.strictEqual(readData, dataString);
await db.close();
}());
};
return runTests;
}());