Skip to content

Commit

Permalink
Merge pull request #1 from CodingZeal/test-coverage
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
randycoulman committed Jun 16, 2017
2 parents 62fce90 + 9b0aa9c commit 4031b2d
Show file tree
Hide file tree
Showing 12 changed files with 1,068 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .babelrc
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
coverage/*
5 changes: 4 additions & 1 deletion .eslintrc.js
Expand Up @@ -6,5 +6,8 @@ module.exports = {
"prettier",
"prettier/react"
],
root: true
root: true,
rules: {
"callback-return": "off"
}
};
3 changes: 2 additions & 1 deletion README.md
@@ -1,6 +1,7 @@
# redux-persist-sensitive-storage

[![npm version](https://badge.fury.io/js/redux-persist-sensitive-storage.svg)](https://www.npmjs.com/package/redux-persist-sensitive-storage)
[![CircleCI](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage.svg?style=shield)](https://circleci.com/gh/CodingZeal/redux-persist-sensitive-storage)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

redux-persist storage engine for react-native-sensitive-info
Expand All @@ -16,7 +17,7 @@ More details coming soon!
- [ ] Mention that storage is not (yet) secure on Android, but point at branch on r-n-s-i that adds that.
- [ ] Contributing

- [ ] Add tests
- [x] Add tests

- [ ] Test on both iOS and Android

Expand Down
15 changes: 15 additions & 0 deletions circle.yml
@@ -0,0 +1,15 @@
machine:
environment:
PATH: "${PATH:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
node:
version: 6.11.0

dependencies:
cache_directories:
- ~/.cache/yarn
override:
- yarn

test:
override:
- yarn validate
27 changes: 16 additions & 11 deletions index.js
Expand Up @@ -28,50 +28,55 @@ export default function(options = {}) {
android: Object.keys
});

const noop = () => null;

return {
/* eslint-disable callback-return */
async getItem(key, callback) {
async getItem(key, callback = noop) {
try {
// getItem() returns `null` on Android and `undefined` on iOS;
// explicitly return `null` here as `undefined` causes an exception
// upstream.
const result = (await sensitiveInfo.getItem(key, options)) || null;
let result = await sensitiveInfo.getItem(key, options);

if (typeof result === "undefined") {
result = null;
}

callback && callback(null, result);
callback(null, result);

return result;
} catch (error) {
callback && callback(error);
callback(error);
throw error;
}
},

async setItem(key, value, callback) {
async setItem(key, value, callback = noop) {
try {
await sensitiveInfo.setItem(key, value, options);
callback && callback(null);
callback(null);
} catch (error) {
callback(error);
throw error;
}
},

async removeItem(key, callback) {
async removeItem(key, callback = noop) {
try {
await sensitiveInfo.deleteItem(key, options);
callback && callback(null);
callback(null);
} catch (error) {
callback(error);
throw error;
}
},

async getAllKeys(callback) {
async getAllKeys(callback = noop) {
try {
const values = await sensitiveInfo.getAllItems(options);
const result = extractKeys(values);

callback && callback(null, result);
callback(null, result);

return result;
} catch (error) {
Expand Down
20 changes: 17 additions & 3 deletions package.json
Expand Up @@ -3,12 +3,16 @@
"version": "0.1.0",
"description": "redux-persist storage engine for react-native-sensitive-info",
"main": "index.js",
"files": ["index.js"],
"files": [
"index.js"
],
"scripts": {
"format": "prettier --write '**/*.js'",
"lint": "eslint '**/*.js' --max-warnings 0",
"precommit": "lint-staged",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest --coverage",
"test:watch": "jest --watch",
"validate": "npm-run-all -p lint test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,17 +41,27 @@
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"eslint": "3.19.0",
"eslint-config-prettier": "^2.1.1",
"eslint-config-zeal": "^1.0.0",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jest": "^20.0.3",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-react-native": "^2.3.2",
"husky": "^0.13.4",
"jest": "^20.0.4",
"lint-staged": "^3.6.1",
"npm-run-all": "^4.0.2",
"prettier": "^1.4.4",
"react": "16.0.0-alpha.12",
"react-native": "^0.45.1"
"react-native": "^0.45.1",
"react-native-sensitive-info": "^5.1.0",
"testdouble": "^3.0.0"
},
"jest": {
"preset": "react-native",
"setupTestFrameworkScriptFile": "<rootDir>/test/setupTests.js"
},
"lint-staged": {
"*.js": "prettier --list-different"
Expand Down
7 changes: 7 additions & 0 deletions test/.eslintrc.json
@@ -0,0 +1,7 @@
{
"extends": ["zeal/jest"],
"rules": {
"arrow-body-style": "off",
"global-require": "off"
}
}

0 comments on commit 4031b2d

Please sign in to comment.