diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c13c5f6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/.gitignore b/.gitignore index b281dd5..40aedea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -src/jasmine-core/ -node_modules/ -src/*.js -!gulpfile.js +/src/jasmine-core/ +/node_modules/ +/src/*.js +/**/*.map +/typings/ diff --git a/README.md b/README.md index d16d18a..1fc8232 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # chrome-storage.js +[![dependencies Status](https://img.shields.io/david/lmk123/chrome-storage-wrapper.svg?style=flat-square)](https://david-dm.org/lmk123/chrome-storage-wrapper) +[![devDependencies Status](https://img.shields.io/david/dev/lmk123/chrome-storage-wrapper.svg?style=flat-square)](https://david-dm.org/lmk123/chrome-storage-wrapper#info=devDependencies) +[![Bower Version](https://img.shields.io/bower/v/chrome-storage-wrapper.svg?style=flat-square)](https://github.com/lmk123/chrome-storage-wrapper/releases) +[![NPM Version](https://img.shields.io/npm/v/chrome-storage-wrapper.svg?style=flat-square)](https://www.npmjs.com/package/chrome-storage-wrapper) + A tiny wrapper for [chrome.storage](https://developer.chrome.com/extensions/storage) that using [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). ## Example @@ -31,7 +36,7 @@ chromeStorage.set({ ## Installation -Install with [Bower](http://bower.io/): +Install with [Bower](http://bower.io/): ``` bower install chrome-storage-wrapper @@ -117,7 +122,7 @@ chromeStorage.set({ key1:'value1', key2:'value2' }) Removes one or more items. ```js -chromeStorage.remove([ 'key1', 'key2' }) +chromeStorage.remove([ 'key1', 'key2' ]) .then(() => { // ... }); @@ -127,6 +132,10 @@ chromeStorage.remove([ 'key1', 'key2' }) Removes all items. +#### chromeStorage.sync([ area-from, area-to]) + +Sync the data from `area-from` to `area-to`. + #### chromeStorage.addChangeListener(callback[, options]) Fired when one or more items change. This function return a function, it's used by `chromeStorage.removeChangeListener`. **Note**: The changes only has the new value. See below: diff --git a/bower.json b/bower.json index 521ab20..243024f 100644 --- a/bower.json +++ b/bower.json @@ -4,8 +4,9 @@ "description" : "A tiny wrapper for chrome.storage that using Promise." , "ignore" : [ "**/*" , - "!release/*", - "!README.md" + "!release/*" , + "!README.md" , + "!package.json" ] , "moduleType" : [ "amd" , @@ -24,6 +25,6 @@ "url" : "https://github.com/lmk123/chrome-storage-wrapper.git" } , "devDependencies" : { - "jasmine-core" : "^2.0.0" + "jasmine-core" : "~2.3.4" } } diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index c2367d4..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,8 +0,0 @@ -'use strict'; - -const gulp = require( 'gulp' ) , - cpe = require( 'gulp-es6-sass' )( gulp , { - src : './src' , - es6Files : [ './src/*.es6' ] , - sassFiles : [] - } ); diff --git a/package.json b/package.json index bd7d1d4..9f3e329 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "chrome-storage-wrapper" , - "version" : "0.1.2" , + "version" : "0.1.3" , "description" : "A tiny wrapper for chrome.storage that using Promise." , "author" : { "name" : "Milk Lee" , @@ -23,7 +23,13 @@ ] , "license" : "MIT" , "devDependencies" : { - "gulp" : "^3.0.0" , - "gulp-es6-sass" : "*" + "babel-cli" : "^6.1.2" , + "babel-preset-es2015" : "^6.1.2" , + "bower" : "^1.6.5" , + "tsd" : "^0.6.5" + } , + "scripts" : { + "tsd" : "tsd" , + "bower" : "bower" } } diff --git a/src/chrome-storage.es6 b/src/chrome-storage.es6 index 1a12f95..cbefcce 100644 --- a/src/chrome-storage.es6 +++ b/src/chrome-storage.es6 @@ -7,227 +7,246 @@ * Release under MIT license. */ (function ( factory ) { - if ( 'function' === typeof define && define.amd ) { - define( [] , factory ); - } else if ( 'undefined' !== typeof module && module.exports ) { - module.exports = factory(); - } else { - window.chromeStorage = factory(); - } + if ( 'function' === typeof define && define.amd ) { + define( [] , factory ); + } else if ( 'undefined' !== typeof module && module.exports ) { + module.exports = factory(); + } else { + window.chromeStorage = factory(); + } }( function () { - const { storage , runtime } = chrome , - changeCallbacks = []; - - let context = 'local' , - defaultStorage = storage[ context ]; - - const module = { - - /** - * 封装一层获取方法 - * @param {Object|String[]|String} keys - 可以是一个对象:{ key1:'null', key2:''};也可以是一个数组:['key1','key2'];也可以是一个字符串:'key' - * @param {String} [area] - * @returns {Promise} - */ - get ( keys , area ) { - return new Promise( ( resolve , rejact ) => { - getCurrentStorage( area ).get( keys , function ( items ) { - const err = runtime.lastError; - if ( err ) { - rejact( err ); - } else { - resolve( items ); - } - } ); - } ); - } , - - /** - * 获取存储区域的所有数据 - * @param {String} [area] - */ - getAll ( area ) { - return module.get( null , area ); - } , - - /** - * 封装一层设置方法 - * @param {Object|String} key - 如果传了 value 参数,那么它只能是字符串 - * @param {*} [value] - 当以 .set('key', value) 的形式调用时,key 只能是一个字符串 - * @param {String} [area] - * @returns {Promise} - */ - set ( key , value , area ) { - let obj; - if ( 'object' === typeof key ) { - obj = key; - area = value; - } else { - obj = {}; - obj[ key ] = value; - } - return new Promise( ( resolve , reject ) => { - getCurrentStorage( area ).set( obj , function () { - var err = runtime.lastError; - if ( err ) { - reject( err ); - } else { - resolve(); - } - } ); - } ); - } , - - /** - * 封装一层删除方法 - * @param {Object|String[]|String} keys - 可以是一个对象:{ key1:'null', key2:''};也可以是一个数组:['key1','key2'];也可以是一个字符串:'key' - * @param {String} [area] - * @returns {Promise} - */ - remove ( keys , area ) { - return new Promise( ( resolve , reject ) => { - getCurrentStorage( area ).remove( keys , function ( items ) { - const err = runtime.lastError; - if ( err ) { - reject( err ); - } else { - resolve( items ); - } - } ); - } ); - } , - - /** - * 封装一层 clear 方法 - * @param {String} [area] - * @returns Promise - */ - clear ( area ) { - return new Promise( ( resolve , reject ) => { - getCurrentStorage( area ).clear( () => { - const err = runtime.lastError; - if ( err ) { - reject( err ); - } else { - resolve(); - } - } ); - } ); - } , - - /** - * 获取当前的默认存储区域 - * @returns {String} - */ - get defaultArea() { - return context; - } , - - /** - * 设置当前的默认存储区域 - * @param {String} area - */ - set defaultArea( area ) { - noAreaError( area ); - context = area; - defaultStorage = storage[ context ]; - } , - - /** - * 注册 change 事件。 - * 注意,回调里面的第一个参数仅包含最新值, - * 而不是一个有newValue和oldValue的对象。 - * 见下面的事件监听函数。 - * @param {Function} listener - * @param [options] - * @param {String[]} [options.keys] - 关心哪些键的变化 - * @param {String[]} [options.areas] - 关心哪些存储区域的变化 - * @returns {Function} 最后实际生成的监听函数 - */ - addChangeListener ( listener , options ) { - - if ( !options ) {options = {};} - - let { keys , areas } = options , newListener; - - if ( 'string' === typeof keys ) { - keys = [ keys ]; - } - - if ( 'string' === typeof areas ) { - areas = [ areas ]; - } - - newListener = ( changes , area ) => { - if ( Array.isArray( areas ) ) { - if ( areas.indexOf( area ) < 0 ) { - return; - } - } - - const keysIsArray = Array.isArray( keys ) , - myChanges = {}; - - for ( let key in changes ) { - if ( !keysIsArray || keys.indexOf( key ) >= 0 ) { - myChanges[ key ] = changes[ key ]; - } - } - - for ( let hasMyChange in myChanges ) { - listener( myChanges , area ); - break; - } - }; - changeCallbacks.push( newListener ); - return newListener; - } , - - /** - * 删除一个监听函数 - * @param {Function} listener - */ - removeChangeListener ( newListener ) { - const index = changeCallbacks.indexOf( newListener ); - if ( index >= 0 ) { - changeCallbacks.splice( index , 1 ); - } - } - }; + const { storage , runtime } = chrome , + changeCallbacks = []; - storage.onChanged.addListener( function ( changes , area ) { - const customChanges = {}; + let context = 'local' , + defaultStorage = storage[ context ]; - for ( let key in changes ) { - customChanges[ key ] = changes[ key ].newValue; - } + const module = { - changeCallbacks.forEach( ( newListener ) => { - newListener( customChanges , area ); + /** + * 封装一层获取方法 + * @param {Object|String[]|String} keys - 可以是一个对象:{ key1:'null', key2:''};也可以是一个数组:['key1','key2'];也可以是一个字符串:'key' + * @param {String} [area] + * @returns {Promise} + */ + get ( keys , area ) { + return new Promise( ( resolve , reject ) => { + getCurrentStorage( area ).get( keys , items => { + const err = runtime.lastError; + if ( err ) { + reject( err ); + } else { + resolve( items ); + } } ); - } ); + } ); + } , + + /** + * 获取存储区域的所有数据 + * @param {String} [area] + */ + getAll ( area ) { + return module.get( null , area ); + } , + + /** + * 封装一层设置方法 + * @param {Object|String} key - 如果传了 value 参数,那么它只能是字符串 + * @param {*} [value] - 当以 .set('key', value) 的形式调用时,key 只能是一个字符串 + * @param {String} [area] + * @returns {Promise} + */ + set ( key , value , area ) { + let obj; + if ( 'object' === typeof key ) { + obj = key; + area = value; + } else { + obj = {}; + obj[ key ] = value; + } + return new Promise( ( resolve , reject ) => { + getCurrentStorage( area ).set( obj , function () { + var err = runtime.lastError; + if ( err ) { + reject( err ); + } else { + resolve(); + } + } ); + } ); + } , - return module; + /** + * 封装一层删除方法 + * @param {Object|String[]|String} keys - 可以是一个对象:{ key1:'null', key2:''};也可以是一个数组:['key1','key2'];也可以是一个字符串:'key' + * @param {String} [area] + * @returns {Promise} + */ + remove ( keys , area ) { + return new Promise( ( resolve , reject ) => { + getCurrentStorage( area ).remove( keys , function ( items ) { + const err = runtime.lastError; + if ( err ) { + reject( err ); + } else { + resolve( items ); + } + } ); + } ); + } , /** - * 获取默认的存储空间 + * 封装一层 clear 方法 * @param {String} [area] - * @returns {*} + * @returns Promise + */ + clear ( area ) { + return new Promise( ( resolve , reject ) => { + getCurrentStorage( area ).clear( () => { + const err = runtime.lastError; + if ( err ) { + reject( err ); + } else { + resolve(); + } + } ); + } ); + } , + + /** + * 获取当前的默认存储区域 + * @returns {String} + */ + get defaultArea() { + return context; + } , + + /** + * 设置当前的默认存储区域 + * @param {String} area + */ + set defaultArea( area ) { + noAreaError( area ); + context = area; + defaultStorage = storage[ context ]; + } , + + /** + * 注册 change 事件。 + * 注意,回调里面的第一个参数仅包含最新值, + * 而不是一个有newValue和oldValue的对象。 + * 见下面的事件监听函数。 + * @param {Function} listener + * @param [options] + * @param {String[]} [options.keys] - 关心哪些键的变化 + * @param {String[]} [options.areas] - 关心哪些存储区域的变化 + * @returns {Function} 最后实际生成的监听函数 */ - function getCurrentStorage( area ) { - let currentStorage; - if ( undefined === area ) { - currentStorage = defaultStorage; - } else { - noAreaError( area ); - currentStorage = storage[ area ]; + addChangeListener ( listener , options ) { + + if ( !options ) { options = {}; } + + let { keys , areas } = options , newListener; + + if ( 'string' === typeof keys ) { + keys = [ keys ]; + } + + if ( 'string' === typeof areas ) { + areas = [ areas ]; + } + + newListener = ( changes , area ) => { + if ( Array.isArray( areas ) ) { + if ( areas.indexOf( area ) < 0 ) { + return; + } + } + + const keysIsArray = Array.isArray( keys ) , + myChanges = {}; + + for ( let key in changes ) { + if ( !keysIsArray || keys.indexOf( key ) >= 0 ) { + myChanges[ key ] = changes[ key ]; + } } - return currentStorage; - } - function noAreaError( area ) { - if ( !storage[ area ] ) { - throw new Error( 'chrome.storage 不支持 ' + area + ' 存储区域。' ); + for ( let hasMyChange in myChanges ) { + listener( myChanges , area ); + break; } + }; + changeCallbacks.push( newListener ); + return newListener; + } , + + /** + * 删除一个监听函数 + * @param {Function} newListener + */ + removeChangeListener ( newListener ) { + const index = changeCallbacks.indexOf( newListener ); + if ( index >= 0 ) { + changeCallbacks.splice( index , 1 ); + } + } , + + /** + * 在存储区域间同步数据 + * @param {String} [from] + * @param {String} [to] + * @returns {Promise} + */ + sync( from = 'local' , to = 'sync' ){ + return Promise + .all( [ + module.getAll( from ) , + module.clear( to ) + ] ) + .then( ( [data] )=> module.set( data , to ) ); + } + }; + + storage.onChanged.addListener( ( changes , area )=> { + const customChanges = {}; + + for ( let key in changes ) { + customChanges[ key ] = changes[ key ].newValue; + } + + changeCallbacks.forEach( ( newListener ) => { + newListener( customChanges , area ); + } ); + } ); + + return module; + + /** + * 获取默认的存储空间 + * @param {String} [area] + * @returns {chrome.storage.StorageArea} + */ + function getCurrentStorage( area ) { + let currentStorage; + if ( undefined === area ) { + currentStorage = defaultStorage; + } else { + noAreaError( area ); + currentStorage = storage[ area ]; + } + return currentStorage; + } + + /** + * 如果没有指定的存储区域则报错 + * @param {String} area + */ + function noAreaError( area ) { + if ( !storage[ area ] ) { + throw new Error( 'chrome.storage 不支持 ' + area + ' 存储区域。' ); } + } } )); diff --git a/src/test.es6 b/src/test.es6 index 69dd7fa..7956440 100644 --- a/src/test.es6 +++ b/src/test.es6 @@ -1,181 +1,197 @@ describe( '完整测试。下面这些测试要按照顺序执行,所以没有分成多个 describe' , () => { - // 测试 getter/setter - it( '使用对象设置数据' , ( done ) => { - chromeStorage.set( { - key1 : 'value1' - } ).then( () => { - return chromeStorage.get( 'key1' ); - } ).then( ( itmes ) => { - expect( itmes.key1 ).toBe( 'value1' ); - done(); - } ); - } ); - - it( '使用两个参数设置数据' , ( done ) => { - chromeStorage.set( 'key2' , 'value2' ) - .then( () => chromeStorage.get( 'key2' ) ) - .then( ( itmes ) => { - expect( itmes.key2 ).toBe( 'value2' ); - done(); - } ); - } ); - it( '改变存储区域' , ( done ) => { - chromeStorage.set( { - key3 : 'value3' - } , 'sync' ) - .then( () => chromeStorage.get( 'key3' , 'sync' ) ) - .then( ( items ) => { - expect( items.key3 ).toBe( 'value3' ); - done(); - } ); + it( 'sync 能同步数据' , done => { + const data = { test : 1 , g : '2' }; + + chromeStorage + .set( data ) + .then( ()=> chromeStorage.sync() ) + .then( ()=> chromeStorage.getAll( 'sync' ) ) + .then( s => { + expect( s ).toEqual( data ); + Promise.all( [ + chromeStorage.clear( 'local' ) , + chromeStorage.clear( 'sync' ) + ] ).then( done ); + } ); + } ); + + it( '使用对象设置数据' , ( done ) => { + chromeStorage.set( { + key1 : 'value1' + } ).then( () => { + return chromeStorage.get( 'key1' ); + } ).then( ( itmes ) => { + expect( itmes.key1 ).toBe( 'value1' ); + done(); } ); - - it( '测试使用数组读取多个值' , ( done ) => { - chromeStorage.get( [ 'key1' , 'key2' ] ) - .then( ( items ) => { - expect( items ).toEqual( { - key1 : 'value1' , - key2 : 'value2' - } ); - done(); - } ); - } ); - - it( '测试 getAll:local 区域的数据应该匹配前面写入的数据' , ( done ) => { - chromeStorage.getAll() - .then( ( items ) => { - expect( items ).toEqual( { - key1 : 'value1' , - key2 : 'value2' - } ); - done(); - } ); - } ); - - it( '测试 getAll:sync 区域的数据应该匹配前面写入的数据' , ( done ) => { - chromeStorage.getAll( 'sync' ) - .then( ( items ) => { - expect( items ).toEqual( { - key3 : 'value3' - } ); - done(); - } ); - } ); - - // 测试数据监听函数 - let spy1 , - listener1; - - it( '应该能监听到数据的变化' , ( done ) => { - spy1 = jasmine.createSpy( 'spy1' ); - listener1 = chromeStorage.addChangeListener( ( changes , area ) => { - spy1(); - if ( 1 === spy1.calls.count() ) { - expect( changes ).toEqual( { - key1 : 'value1 - changed' - } ); - expect( area ).toBe( 'local' ); - } + } ); + + it( '使用两个参数设置数据' , ( done ) => { + chromeStorage.set( 'key2' , 'value2' ) + .then( () => chromeStorage.get( 'key2' ) ) + .then( ( itmes ) => { + expect( itmes.key2 ).toBe( 'value2' ); + done(); + } ); + } ); + + it( '改变存储区域' , ( done ) => { + chromeStorage.set( { + key3 : 'value3' + } , 'sync' ) + .then( () => chromeStorage.get( 'key3' , 'sync' ) ) + .then( ( items ) => { + expect( items.key3 ).toBe( 'value3' ); + done(); + } ); + } ); + + it( '测试使用数组读取多个值' , ( done ) => { + chromeStorage.get( [ 'key1' , 'key2' ] ) + .then( ( items ) => { + expect( items ).toEqual( { + key1 : 'value1' , + key2 : 'value2' } ); - chromeStorage.set( 'key1' , 'value1 - changed' ) - .then( () => { - setTimeout( done , 1000 ); - } ); - } ); - - it( '应该能取消事件监听函数' , ( done ) => { - chromeStorage.removeChangeListener( listener1 ); - - chromeStorage.set( 'key1' , 'value1' ) - .then( () => { - setTimeout( () => { - expect( spy1.calls.count() ).toBe( 1 ); - done(); - } , 1000 ); - } ); - } ); - - let spy2 , - listener2; - - it( '应该能使用第二个参数限定 change 事件的产生' , ( done ) => { - spy2 = jasmine.createSpy( 'spy2' ); - listener2 = chromeStorage.addChangeListener( ( changes , area ) => { - spy2(); - expect( changes ).toEqual( { key2 : 'value2 - changed' } ); - expect( area ).toBe( 'local' ); - } , { - keys : 'key2' , - areas : 'local' + done(); + } ); + } ); + + it( '测试 getAll:local 区域的数据应该匹配前面写入的数据' , ( done ) => { + chromeStorage.getAll() + .then( ( items ) => { + expect( items ).toEqual( { + key1 : 'value1' , + key2 : 'value2' } ); - - chromeStorage.set( 'key1' , 'value1 - changed' ) - .then( () => { - return new Promise( ( resolve ) => { - setTimeout( () => { - resolve( chromeStorage.set( 'key2' , 'value2 - changed' ) ) - } , 1000 ); - } ); - } ) - .then( () => { - expect( spy2.calls.count() ).toBe( 1 ); - done(); - } ); - } ); - - it( '同样应该能取消事件监听' , ( done ) => { - chromeStorage.removeChangeListener( listener2 ); - - chromeStorage.set( 'key1' , 'value1' ) - .then( () => { - return new Promise( ( resolve ) => { - setTimeout( () => { - resolve( chromeStorage.set( 'key2' , 'value2' ) ) - } , 1000 ); - } ); - } ) - .then( () => { - setTimeout( () => { - expect( spy2.calls.count() ).toBe( 1 ); - done(); - } , 1000 ); - } ); + done(); + } ); + } ); + + it( '测试 getAll:sync 区域的数据应该匹配前面写入的数据' , ( done ) => { + chromeStorage.getAll( 'sync' ) + .then( ( items ) => { + expect( items ).toEqual( { + key3 : 'value3' + } ); + done(); + } ); + } ); + + // 测试数据监听函数 + let spy1 , + listener1; + + it( '应该能监听到数据的变化' , ( done ) => { + spy1 = jasmine.createSpy( 'spy1' ); + listener1 = chromeStorage.addChangeListener( ( changes , area ) => { + spy1(); + if ( 1 === spy1.calls.count() ) { + expect( changes ).toEqual( { + key1 : 'value1 - changed' + } ); + expect( area ).toBe( 'local' ); + } } ); - - // 测试默认存储区域的设置 - it( '设置一个不存在的默认存储区域时会抛出错误' , () => { - expect( () => { - chromeStorage.defaultArea = 'hasNoThisStorage'; - } ).toThrow(); + chromeStorage.set( 'key1' , 'value1 - changed' ) + .then( () => { + setTimeout( done , 1000 ); + } ); + } ); + + it( '应该能取消事件监听函数' , ( done ) => { + chromeStorage.removeChangeListener( listener1 ); + + chromeStorage.set( 'key1' , 'value1' ) + .then( () => { + setTimeout( () => { + expect( spy1.calls.count() ).toBe( 1 ); + done(); + } , 1000 ); + } ); + } ); + + let spy2 , + listener2; + + it( '应该能使用第二个参数限定 change 事件的产生' , ( done ) => { + spy2 = jasmine.createSpy( 'spy2' ); + listener2 = chromeStorage.addChangeListener( ( changes , area ) => { + spy2(); + expect( changes ).toEqual( { key2 : 'value2 - changed' } ); + expect( area ).toBe( 'local' ); + } , { + keys : 'key2' , + areas : 'local' } ); - it( '设置一个存在的存储区域' , ( done ) => { - chromeStorage.defaultArea = 'sync'; - chromeStorage.get( 'key3' ).then( ( items ) => { - expect( items.key3 ).toBe( 'value3' ); - done(); + chromeStorage.set( 'key1' , 'value1 - changed' ) + .then( () => { + return new Promise( ( resolve ) => { + setTimeout( () => { + resolve( chromeStorage.set( 'key2' , 'value2 - changed' ) ) + } , 1000 ); } ); + } ) + .then( () => { + expect( spy2.calls.count() ).toBe( 1 ); + done(); + } ); + } ); + + it( '同样应该能取消事件监听' , ( done ) => { + chromeStorage.removeChangeListener( listener2 ); + + chromeStorage.set( 'key1' , 'value1' ) + .then( () => { + return new Promise( ( resolve ) => { + setTimeout( () => { + resolve( chromeStorage.set( 'key2' , 'value2' ) ) + } , 1000 ); + } ); + } ) + .then( () => { + setTimeout( () => { + expect( spy2.calls.count() ).toBe( 1 ); + done(); + } , 1000 ); + } ); + } ); + + // 测试默认存储区域的设置 + it( '设置一个不存在的默认存储区域时会抛出错误' , () => { + expect( () => { + chromeStorage.defaultArea = 'hasNoThisStorage'; + } ).toThrow(); + } ); + + it( '设置一个存在的存储区域' , ( done ) => { + chromeStorage.defaultArea = 'sync'; + chromeStorage.get( 'key3' ).then( ( items ) => { + expect( items.key3 ).toBe( 'value3' ); + done(); } ); - - it( '测试清空默认存储区域的数据' , ( done ) => { - chromeStorage.clear() - .then( () => { - return chromeStorage.get( null ); - } ) - .then( ( items ) => { - expect( items ).toEqual( {} ); - } ) - .then( () => { - chromeStorage.defaultArea = 'local'; - return chromeStorage.clear(); - } ) - .then( () => { - return chromeStorage.get( null ); - } ) - .then( ( items ) => { - expect( items ).toEqual( {} ); - } ) - .then( done ); - } ); + } ); + + it( '测试清空默认存储区域的数据' , ( done ) => { + chromeStorage.clear() + .then( () => { + return chromeStorage.get( null ); + } ) + .then( ( items ) => { + expect( items ).toEqual( {} ); + } ) + .then( () => { + chromeStorage.defaultArea = 'local'; + return chromeStorage.clear(); + } ) + .then( () => { + return chromeStorage.get( null ); + } ) + .then( ( items ) => { + expect( items ).toEqual( {} ); + } ) + .then( done ); + } ); } ); diff --git a/tsd.json b/tsd.json new file mode 100644 index 0000000..f12f4ba --- /dev/null +++ b/tsd.json @@ -0,0 +1,27 @@ +{ + "version": "v4", + "repo": "borisyankov/DefinitelyTyped", + "ref": "master", + "path": "typings", + "bundle": "typings/tsd.d.ts", + "installed": { + "webrtc/MediaStream.d.ts": { + "commit": "35989a3ab4834b8e8b2b56788f1d4fc46a25dc8d" + }, + "es6-promise/es6-promise.d.ts": { + "commit": "35989a3ab4834b8e8b2b56788f1d4fc46a25dc8d" + }, + "filesystem/filesystem.d.ts": { + "commit": "35989a3ab4834b8e8b2b56788f1d4fc46a25dc8d" + }, + "filewriter/filewriter.d.ts": { + "commit": "35989a3ab4834b8e8b2b56788f1d4fc46a25dc8d" + }, + "chrome/chrome.d.ts": { + "commit": "35989a3ab4834b8e8b2b56788f1d4fc46a25dc8d" + }, + "jasmine/jasmine.d.ts": { + "commit": "35989a3ab4834b8e8b2b56788f1d4fc46a25dc8d" + } + } +}