Skip to content

Commit 2dbd11d

Browse files
committed
Added coveralls support and initial FileSystem test.
1 parent 18859e0 commit 2dbd11d

File tree

8 files changed

+81
-7
lines changed

8 files changed

+81
-7
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/coverage

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
"semi": [
3939
"error",
4040
"always"
41-
]
41+
],
42+
"no-var": "error"
4243
}
4344
};

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/node_modules
1+
/node_modules
2+
/coverage

lib/FileSystem.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ export class FileSystem {
192192
}
193193

194194
// Hit network and download file to local disk.
195+
let result = null;
195196
try {
196197

197-
var result = await RNFetchBlob
198+
result = await RNFetchBlob
198199
.config({
199200
path: path
200201
})

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "React Native Higher Order Component that adds advanced caching functionality to the react native Image component.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jest",
7+
"test": "./node_modules/.bin/jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
88
"lint": "eslint ."
99
},
1010
"repository": {
@@ -33,6 +33,7 @@
3333
"homepage": "https://github.com/billmalarky/react-native-image-cache-hoc#readme",
3434
"devDependencies": {
3535
"babel-eslint": "^8.0.1",
36+
"coveralls": "^3.0.0",
3637
"eslint": "^4.9.0",
3738
"eslint-plugin-react": "^7.4.0",
3839
"eslint-plugin-react-native": "^3.1.0",
@@ -41,7 +42,10 @@
4142
"should": "^13.1.2"
4243
},
4344
"jest": {
44-
"preset": "react-native"
45+
"preset": "react-native",
46+
"setupFiles": [
47+
"./tests/config.js"
48+
]
4549
},
4650
"dependencies": {
4751
"buffer": "^5.0.8",

tests/FileSystem.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
// Define globals for eslint.
3+
/* global describe it */
4+
5+
// Load dependencies
6+
import should from 'should'; // eslint-disable-line no-unused-vars
7+
import FileSystemFactory from '../lib/FileSystem';
8+
9+
describe('lib/FileSystem', function() {
10+
11+
const fileSystem = FileSystemFactory();
12+
13+
it('#getFileNameFromUrl should create a sha1 filename from a PNG/JPG/GIF url.', () => {
14+
15+
let pngFilename = fileSystem.getFileNameFromUrl('https://img.wennermedia.com/5333a62d-07db-432a-92e2-198cafa38a14-326adb1a-d8ed-4a5d-b37e-5c88883e1989.png');
16+
17+
pngFilename.should.equal('cd7d2199cd8e088cdfd9c99fc6359666adc36289.png');
18+
19+
let gifFilename = fileSystem.getFileNameFromUrl('https://upload.wikimedia.org/wikipedia/commons/2/2c/Rotating_earth_%28large%29.gif');
20+
21+
gifFilename.should.equal('c048132247cd28c7879ab36d78a8f45194640006.gif');
22+
23+
let jpgFilename = fileSystem.getFileNameFromUrl('https://cdn2.hubspot.net/hub/42284/file-14233687-jpg/images/test_in_red.jpg');
24+
25+
jpgFilename.should.equal('6adf4569ecc3bf8c378bb4d47b1995cd85c5a13c.jpg');
26+
27+
});
28+
29+
});

tests/config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
*
3+
* Mocked objects for testing.
4+
*
5+
*/
6+
7+
/* global jest */
8+
9+
jest.mock('react-native-fetch-blob', () => {
10+
return {
11+
fs: {
12+
dirs: {
13+
CacheDir: 'test'
14+
}
15+
},
16+
DocumentDir: () => {},
17+
polyfill: () => {},
18+
};
19+
});

yarn.lock

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,16 @@ [email protected], core-util-is@~1.0.0:
12721272
version "1.0.2"
12731273
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
12741274

1275+
coveralls@^3.0.0:
1276+
version "3.0.0"
1277+
resolved "https://registry.yarnpkg.com/coveralls/-/coveralls-3.0.0.tgz#22ef730330538080d29b8c151dc9146afde88a99"
1278+
dependencies:
1279+
js-yaml "^3.6.1"
1280+
lcov-parse "^0.0.10"
1281+
log-driver "^1.2.5"
1282+
minimist "^1.2.0"
1283+
request "^2.79.0"
1284+
12751285
12761286
version "3.3.0"
12771287
resolved "https://registry.yarnpkg.com/crc/-/crc-3.3.0.tgz#fa622e1bc388bf257309082d6b65200ce67090ba"
@@ -2740,7 +2750,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
27402750
version "3.0.2"
27412751
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
27422752

2743-
js-yaml@^3.7.0, js-yaml@^3.9.1:
2753+
js-yaml@^3.6.1, js-yaml@^3.7.0, js-yaml@^3.9.1:
27442754
version "3.10.0"
27452755
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
27462756
dependencies:
@@ -2866,6 +2876,10 @@ lcid@^1.0.0:
28662876
dependencies:
28672877
invert-kv "^1.0.0"
28682878

2879+
lcov-parse@^0.0.10:
2880+
version "0.0.10"
2881+
resolved "https://registry.yarnpkg.com/lcov-parse/-/lcov-parse-0.0.10.tgz#1b0b8ff9ac9c7889250582b70b71315d9da6d9a3"
2882+
28692883
left-pad@^1.1.3:
28702884
version "1.1.3"
28712885
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
@@ -3010,6 +3024,10 @@ lodash@^4.14.0, lodash@^4.16.6, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lo
30103024
version "4.17.4"
30113025
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
30123026

3027+
log-driver@^1.2.5:
3028+
version "1.2.5"
3029+
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.5.tgz#7ae4ec257302fd790d557cb10c97100d857b0056"
3030+
30133031
longest@^1.0.1:
30143032
version "1.0.1"
30153033
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
@@ -3711,7 +3729,7 @@ react-devtools-core@^2.5.0:
37113729
shell-quote "^1.6.1"
37123730
ws "^2.0.3"
37133731

3714-
react-native-fetch-blob@^0.10.8:
3732+
37153733
version "0.10.8"
37163734
resolved "https://registry.yarnpkg.com/react-native-fetch-blob/-/react-native-fetch-blob-0.10.8.tgz#4fc256abae0cb5f10e7c41f28c11b3ff330d72a9"
37173735
dependencies:

0 commit comments

Comments
 (0)