mirror of
https://github.com/BoostIo/Boostnote
synced 2026-02-19 02:38:51 +00:00
fixed eslint error & integrated with prettier as well as formatted the whole codebase (#3450)
This commit is contained in:
@@ -6,7 +6,10 @@ 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 localStorage = (window.localStorage = global.localStorage = new Storage(
|
||||
null,
|
||||
{ strict: true }
|
||||
))
|
||||
const path = require('path')
|
||||
const TestDummy = require('../fixtures/TestDummy')
|
||||
const sander = require('sander')
|
||||
@@ -16,18 +19,20 @@ const os = require('os')
|
||||
|
||||
const dummyStoragePath = path.join(os.tmpdir(), 'test/migrate-test-storage')
|
||||
|
||||
test.beforeEach((t) => {
|
||||
const dummyData = t.context.dummyData = TestDummy.dummyLegacyStorage(dummyStoragePath)
|
||||
test.beforeEach(t => {
|
||||
const dummyData = (t.context.dummyData = TestDummy.dummyLegacyStorage(
|
||||
dummyStoragePath
|
||||
))
|
||||
console.log('init count', dummyData.notes.length)
|
||||
localStorage.setItem('storages', JSON.stringify([dummyData.cache]))
|
||||
})
|
||||
|
||||
test.serial('Migrate legacy storage into v1 storage', (t) => {
|
||||
test.serial('Migrate legacy storage into v1 storage', t => {
|
||||
return Promise.resolve()
|
||||
.then(function test () {
|
||||
.then(function test() {
|
||||
return migrateFromV6Storage(dummyStoragePath)
|
||||
})
|
||||
.then(function assert (data) {
|
||||
.then(function assert(data) {
|
||||
// Check the result. It must be true if succeed.
|
||||
t.true(data)
|
||||
|
||||
@@ -36,29 +41,31 @@ test.serial('Migrate legacy storage into v1 storage', (t) => {
|
||||
const noteDirPath = path.join(dummyStoragePath, 'notes')
|
||||
const fileList = sander.readdirSync(noteDirPath)
|
||||
t.is(dummyData.notes.length, fileList.length)
|
||||
const noteMap = fileList
|
||||
.map((filePath) => {
|
||||
return CSON.readFileSync(path.join(noteDirPath, filePath))
|
||||
})
|
||||
dummyData.notes
|
||||
.forEach(function (targetNote) {
|
||||
t.true(_.find(noteMap, {title: targetNote.title, folder: targetNote.folder}) != null)
|
||||
})
|
||||
const noteMap = fileList.map(filePath => {
|
||||
return CSON.readFileSync(path.join(noteDirPath, filePath))
|
||||
})
|
||||
dummyData.notes.forEach(function(targetNote) {
|
||||
t.true(
|
||||
_.find(noteMap, {
|
||||
title: targetNote.title,
|
||||
folder: targetNote.folder
|
||||
}) != null
|
||||
)
|
||||
})
|
||||
|
||||
// Check legacy folder directory is removed
|
||||
dummyData.json.folders
|
||||
.forEach(function (folder) {
|
||||
try {
|
||||
sander.statSync(dummyStoragePath, folder.key)
|
||||
t.fail('Folder still remains. ENOENT error must be occured.')
|
||||
} catch (err) {
|
||||
t.is(err.code, 'ENOENT')
|
||||
}
|
||||
})
|
||||
dummyData.json.folders.forEach(function(folder) {
|
||||
try {
|
||||
sander.statSync(dummyStoragePath, folder.key)
|
||||
t.fail('Folder still remains. ENOENT error must be occured.')
|
||||
} catch (err) {
|
||||
t.is(err.code, 'ENOENT')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test.after.always(function () {
|
||||
test.after.always(function() {
|
||||
localStorage.clear()
|
||||
sander.rimrafSync(dummyStoragePath)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user