From 8d96368ea6753523e41a6ffd0200957ff8e0ca96 Mon Sep 17 00:00:00 2001 From: Dick Choi Date: Sat, 27 Aug 2016 16:05:29 +0900 Subject: [PATCH] cleanup test remove crypto dependency from renameStorage refactor removeStorage remove dummy files --- tests/dataApi/removeStorage.js | 28 +++++++++---------- tests/dataApi/renameStorage.js | 2 +- tests/dummy/dummyStorage/boostnote.json | 9 ------ .../dummy/dummyStorage/fc6ba88e8ecf/data.json | 24 ---------------- 4 files changed, 15 insertions(+), 48 deletions(-) delete mode 100644 tests/dummy/dummyStorage/boostnote.json delete mode 100644 tests/dummy/dummyStorage/fc6ba88e8ecf/data.json diff --git a/tests/dataApi/removeStorage.js b/tests/dataApi/removeStorage.js index 09c8473a..041983b7 100644 --- a/tests/dataApi/removeStorage.js +++ b/tests/dataApi/removeStorage.js @@ -8,23 +8,22 @@ 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 crypto = require('crypto') +const TestDummy = require('../fixtures/TestDummy') +const sander = require('sander') +const os = require('os') + +const storagePath = path.join(os.tmpdir(), 'test/remove-storage') + +test.beforeEach((t) => { + t.context.storage = TestDummy.dummyStorage(storagePath) + localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) +}) test('Remove a storage', (t) => { - const dummyStoragePath = path.join(__dirname, '..', 'dummy/dummyStorage') - const dummyStorageKey = crypto.randomBytes(6).toString('hex') - const dummyRawStorage = { - name: 'test1', - key: dummyStorageKey, - path: dummyStoragePath - } - + const stoargeKey = t.context.storage.cache.key return Promise.resolve() - .then(function before () { - localStorage.setItem('storages', JSON.stringify([dummyRawStorage])) - }) - .then(function test () { - return removeStorage(dummyStorageKey) + .then(function doTest () { + return removeStorage(stoargeKey) }) .then(function assert (data) { t.is(JSON.parse(localStorage.getItem('storages')).length, 0) @@ -33,4 +32,5 @@ test('Remove a storage', (t) => { test.after(function after () { localStorage.clear() + sander.rimrafSync(storagePath) }) diff --git a/tests/dataApi/renameStorage.js b/tests/dataApi/renameStorage.js index cbbed615..de4b9e79 100644 --- a/tests/dataApi/renameStorage.js +++ b/tests/dataApi/renameStorage.js @@ -8,13 +8,13 @@ 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 crypto = require('crypto') const _ = require('lodash') const TestDummy = require('../fixtures/TestDummy') const sander = require('sander') const os = require('os') const storagePath = path.join(os.tmpdir(), 'test/rename-storage') + test.beforeEach((t) => { t.context.storage = TestDummy.dummyStorage(storagePath) localStorage.setItem('storages', JSON.stringify([t.context.storage.cache])) diff --git a/tests/dummy/dummyStorage/boostnote.json b/tests/dummy/dummyStorage/boostnote.json deleted file mode 100644 index ae4e4df4..00000000 --- a/tests/dummy/dummyStorage/boostnote.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "folders": [ - { - "key": "fc6ba88e8ecf", - "name": "test", - "color": "#FF5555" - } - ] -} diff --git a/tests/dummy/dummyStorage/fc6ba88e8ecf/data.json b/tests/dummy/dummyStorage/fc6ba88e8ecf/data.json deleted file mode 100644 index 08e002c1..00000000 --- a/tests/dummy/dummyStorage/fc6ba88e8ecf/data.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "notes": [ - { - "tags": [], - "title": "Footnote test", - "content": "# Footnote test\n\ntest test", - "type": "MARKDOWN_NOTE", - "key": "93c6ac2a7953", - "isStarred": false, - "createdAt": "2016-07-25T16:19:55.620Z", - "updatedAt": "2016-07-26T08:00:11.326Z" - }, - { - "tags": [], - "title": "Checkbox test", - "content": "# Checkbox test\n\n- [x] Task1\n- [ ] Task2\n- [ ] Task3\n\n", - "type": "MARKDOWN_NOTE", - "key": "4568d84331d9", - "isStarred": false, - "createdAt": "2016-07-25T16:58:43.685Z", - "updatedAt": "2016-08-21T06:14:50.381Z" - } - ] -}