mock-async-storage
Advanced tools
Comparing version 2.0.5 to 2.1.0
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _mockAsyncStorage = require('./mockAsyncStorage'); | ||
var _mockAsyncStorage = _interopRequireDefault(require("./mockAsyncStorage")); | ||
var _mockAsyncStorage2 = _interopRequireDefault(_mockAsyncStorage); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = _mockAsyncStorage2.default; | ||
var _default = _mockAsyncStorage.default; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,13 +6,22 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _deepmerge = require('deepmerge'); | ||
var _deepmerge = _interopRequireDefault(require("deepmerge")); | ||
var _deepmerge2 = _interopRequireDefault(_deepmerge); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
/* global Iterable */ | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const isStringified = str => { | ||
@@ -28,3 +37,2 @@ try { | ||
class AsyncDict { | ||
size() { | ||
@@ -39,2 +47,4 @@ return this.store.size; | ||
constructor() { | ||
_defineProperty(this, "store", void 0); | ||
this.store = new Map(); | ||
@@ -58,2 +68,3 @@ } | ||
_this2.store.set(k, v); | ||
if (cb) cb(null); | ||
@@ -68,2 +79,3 @@ })(); | ||
_this3.store.delete(k); | ||
if (cb) cb(null); | ||
@@ -78,2 +90,3 @@ })(); | ||
_this4.store.clear(); | ||
if (cb) cb(null); | ||
@@ -97,5 +110,3 @@ })(); | ||
return _asyncToGenerator(function* () { | ||
const requested = keys.map(function (k) { | ||
return [k, _this6.store.get(k) || null]; | ||
}); | ||
const requested = keys.map(k => [k, _this6.store.get(k) || null]); | ||
if (cb) cb(null, requested); | ||
@@ -110,5 +121,29 @@ return requested; | ||
return _asyncToGenerator(function* () { | ||
for (const [key, value] of entries) { | ||
_this7.store.set(key, value); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const _step$value = _slicedToArray(_step.value, 2), | ||
key = _step$value[0], | ||
value = _step$value[1]; | ||
_this7.store.set(key, value); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
if (cb) cb(null); | ||
@@ -122,8 +157,31 @@ })(); | ||
return _asyncToGenerator(function* () { | ||
for (const key of keys) { | ||
_this8.store.delete(key); | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = keys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
const key = _step2.value; | ||
_this8.store.delete(key); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
if (cb) cb(null); | ||
})(); | ||
} | ||
} | ||
@@ -137,13 +195,9 @@ | ||
const item = yield _this9.getItem(key); | ||
if (!item) throw new Error(`No item with ${ key } key`); | ||
if (!isStringified(item)) throw new Error(`Invalid item with ${ key } key`); | ||
if (!isStringified(value)) throw new Error(`Invalid value to merge with ${ key }`); | ||
if (!item) throw new Error(`No item with ${key} key`); | ||
if (!isStringified(item)) throw new Error(`Invalid item with ${key} key`); | ||
if (!isStringified(value)) throw new Error(`Invalid value to merge with ${key}`); | ||
const itemObj = JSON.parse(item); | ||
const valueObj = JSON.parse(value); | ||
const merged = (0, _deepmerge2.default)(itemObj, valueObj); | ||
const merged = (0, _deepmerge.default)(itemObj, valueObj); | ||
yield _this9.setItem(key, JSON.stringify(merged)); | ||
if (cb) cb(null); | ||
@@ -159,8 +213,35 @@ })(); | ||
/* eslint no-restricted-syntax: "off" */ | ||
/* eslint no-await-in-loop: "off" */ | ||
for (const [key, value] of entries) { | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
try { | ||
for (var _iterator3 = entries[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
const _step3$value = _slicedToArray(_step3.value, 2), | ||
key = _step3$value[0], | ||
value = _step3$value[1]; | ||
try { | ||
if (value) { | ||
yield _this10.mergeItem(key, value); | ||
} | ||
} catch (err) { | ||
errors.push(err); | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
} finally { | ||
try { | ||
yield _this10.mergeItem(key, value); | ||
} catch (err) { | ||
errors.push(err); | ||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) { | ||
_iterator3.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
} | ||
} | ||
@@ -180,4 +261,6 @@ } | ||
flushGetRequests() {} | ||
} | ||
exports.default = MockAsyncStorage; | ||
var _default = MockAsyncStorage; | ||
exports.default = _default; |
{ | ||
"name": "mock-async-storage", | ||
"title": "Jest Mock AsyncStorage for react-native", | ||
"version": "2.0.5", | ||
"version": "2.1.0", | ||
"description": "Its a mock of react-native AsyncStorage for jest tests", | ||
@@ -15,22 +15,17 @@ "main": "lib/index.js", | ||
{ | ||
"description": "Source + ESNext + Import + Flow", | ||
"entry": "src/index.js", | ||
"description": "Source + Typescript", | ||
"entry": "src/index.ts", | ||
"syntaxes": [ | ||
"javascript", | ||
"esnext", | ||
"import", | ||
"arrows", | ||
"const", | ||
"let", | ||
"destructuring", | ||
"async" | ||
"typescript" | ||
] | ||
}, | ||
{ | ||
"description": "Babel Compiled + ES2015 + Require", | ||
"description": "Babel Compiled + ESNext + Require", | ||
"entry": "lib/index.js", | ||
"syntaxes": [ | ||
"import", | ||
"javascript", | ||
"es2015", | ||
"require" | ||
"esnext", | ||
"require", | ||
"async" | ||
] | ||
@@ -51,13 +46,14 @@ } | ||
"scripts": { | ||
"tsc": "tsc", | ||
"tdd": "jest src/** --watch", | ||
"lint": "standard src/*.js src/**/*.js", | ||
"lint": "standard src/*.ts src/**/*.ts", | ||
"test:src": "jest src/**", | ||
"test": "npm run lint && npm run test:src && npm run examples", | ||
"build": "babel src --out-dir lib --ignore spec.js", | ||
"test": "yarn run tsc && yarn run lint && yarn run test:src && yarn run examples", | ||
"build": "babel src --out-dir lib --ignore spec.ts --extensions .ts", | ||
"projectz": "projectz compile", | ||
"compile": "npm run lint && npm run build && npm run projectz", | ||
"compile": "yarn run lint && yarn run build && yarn run projectz", | ||
"example-jest": "jest ./examples/with-jest/**", | ||
"example-sinon": "jest ./examples/with-sinon/**", | ||
"examples": "npm run example-jest && npm run example-sinon", | ||
"prepublish": "npm run build" | ||
"examples": "yarn run example-jest && yarn run example-sinon", | ||
"prepublish": "yarn run build" | ||
}, | ||
@@ -68,23 +64,22 @@ "engines": { | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-eslint": "^7.1.1", | ||
"babel-jest": "^18.0.0", | ||
"babel-plugin-transform-async-to-generator": "^6.16.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.21.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.20.2", | ||
"babel-preset-node6": "^11.0.0", | ||
"eslint-plugin-flowtype": "^2.29.1", | ||
"flow-bin": "^0.37.4", | ||
"jest": "^18.0.0", | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.4", | ||
"@babel/plugin-proposal-class-properties": "^7.4.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"@babel/preset-typescript": "^7.3.3", | ||
"@babel/runtime": "^7.4.4", | ||
"@types/jest": "^24.0.12", | ||
"babel-eslint": "^10.0.1", | ||
"babel-jest": "^24.7.1", | ||
"jest": "^24.7.1", | ||
"sinon": "^4.0.0", | ||
"standard": "^8.6.0" | ||
"standard": "^12.0.1", | ||
"typescript": "^3.4.5" | ||
}, | ||
"standard": { | ||
"parser": "babel-eslint", | ||
"plugins": [ | ||
"flowtype" | ||
] | ||
"parser": "babel-eslint" | ||
}, | ||
"dependencies": { | ||
"deepmerge": "^1.3.1" | ||
"deepmerge": "^3.2.0" | ||
}, | ||
@@ -91,0 +86,0 @@ "maintainers": [], |
@@ -31,15 +31,25 @@ <!-- TITLE/ --> | ||
<li>Install: <code>npm install --save mock-async-storage</code></li> | ||
<li>Module: <code>require('mock-async-storage')</code></li></ul> | ||
<li>Module: <code>require('mock-async-storage')</code></li> | ||
<li>Import: <code>import MockAsyncStorage from 'mock-async-storage'</code></li></ul> | ||
<h3><a href="https://github.com/bevry/editions" title="Editions are the best way to produce and consume packages you care about.">Editions</a></h3> | ||
<!-- /INSTALL --> | ||
<p>This package is published with the following editions:</p> | ||
<h1>Quick Jest Example</h1> | ||
<ul><li><code>mock-async-storage/src/index.js</code> is Source + <a href="https://babeljs.io/docs/learn-es2015/" title="ECMAScript Next">ESNext</a> + <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> + Flow</li> | ||
<li><code>mock-async-storage</code> aliases <code>mock-async-storage/lib/index.js</code></li> | ||
<li><code>mock-async-storage/lib/index.js</code> is <a href="https://babeljs.io" title="The compiler for writing next generation JavaScript">Babel</a> Compiled + <a href="http://babeljs.io/docs/plugins/preset-es2015/" title="ECMAScript 2015">ES2015</a> + <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a></li></ul> | ||
```JavaScript | ||
// jest.config.js | ||
module.exports = { | ||
setupFilesAfterEnv: [ | ||
'<rootDir>/setup-tests.js', | ||
], | ||
}; | ||
``` | ||
<p>Older environments may need <a href="https://babeljs.io/docs/usage/polyfill/" title="A polyfill that emulates missing ECMAScript environment features">Babel's Polyfill</a> or something similar.</p> | ||
```JavaScript | ||
// setup-tests.js | ||
import MockAsyncStorage from 'mock-async-storage'; | ||
<!-- /INSTALL --> | ||
const mockImpl = new MockAsyncStorage(); | ||
jest.mock('@react-native-community/async-storage', () => mockImpl); | ||
``` | ||
@@ -46,0 +56,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253201
13
712
176
14
1
+ Addeddeepmerge@3.3.0(transitive)
- Removeddeepmerge@1.5.2(transitive)
Updateddeepmerge@^3.2.0