forked from BoostIO/BoostNote-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
65 lines (58 loc) · 2.18 KB
/
Copy pathinit.js
File metadata and controls
65 lines (58 loc) · 2.18 KB
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
const test = require('ava')
const init = require('browser/main/lib/dataApi/init')
global.document = require('jsdom').jsdom('<body></body>')
global.window = document.defaultView
global.navigator = window.navigator
const Storage = require('dom-storage')
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const keygen = require('browser/lib/keygen')
const sander = require('sander')
const _ = require('lodash')
const os = require('os')
const v1StoragePath = path.join(os.tmpdir(), 'test/init-v1-storage')
const legacyStoragePath = path.join(os.tmpdir(), 'test/init-legacy-storage')
const emptyDirPath = path.join(os.tmpdir(), 'test/init-empty-storage')
test.beforeEach((t) => {
localStorage.clear()
// Prepare 3 types of dir
t.context.v1StorageData = TestDummy.dummyStorage(v1StoragePath, {cache: {name: 'v1'}})
t.context.legacyStorageData = TestDummy.dummyLegacyStorage(legacyStoragePath, {cache: {name: 'legacy'}})
t.context.emptyStorageData = {
cache: {
type: 'FILESYSTEM',
name: 'empty',
key: keygen(),
path: emptyDirPath
}
}
localStorage.setItem('storages', JSON.stringify([t.context.v1StorageData.cache, t.context.legacyStorageData.cache, t.context.emptyStorageData.cache]))
})
test.serial('Initialize All Storages', (t) => {
const { v1StorageData, legacyStorageData } = t.context
return Promise.resolve()
.then(function test () {
return init()
})
.then(function assert (data) {
t.true(Array.isArray(data.storages))
t.is(data.notes.length, v1StorageData.notes.length + legacyStorageData.notes.length)
t.is(data.storages.length, 3)
data.storages.forEach(function assertStorage (storage) {
t.true(_.isString(storage.key))
t.true(_.isString(storage.name))
t.true(storage.type === 'FILESYSTEM')
t.true(_.isString(storage.path))
})
})
.then(function after () {
localStorage.clear()
})
})
test.after.always(() => {
localStorage.clear()
sander.rimrafSync(v1StoragePath)
sander.rimrafSync(legacyStoragePath)
sander.rimrafSync(emptyDirPath)
})