Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit eef6fcc

Browse files
committed
wip commit
1 parent f92cfb6 commit eef6fcc

File tree

9 files changed

+88
-35
lines changed

9 files changed

+88
-35
lines changed

scripts/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ npm install --save firebase
4545
npm install --save oboe
4646
npm install --save nedb
4747
# for node polyfills
48+
npm install crypto-js --save
4849
npm install babel-plugin-add-module-exports --save-dev
4950
npm install babel-plugin-modue-alias --save-dev
5051
npm install path-parse --save

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ public RNFetchBlobBody(String taskId, RNFetchBlobReq.RequestType type, String ra
7373
}
7474
}
7575

76-
@Override
77-
public long contentLength() {
78-
return contentLength;
79-
}
76+
// ${RN 0.26+ ONLY} @Override
77+
// ${RN 0.26+ ONLY} public long contentLength() { return contentLength; }
78+
8079
@Override
8180
public MediaType contentType() {
8281
return mime;

src/node-polyfill/events.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2016 wkh237@github. All rights reserved.
2+
// Use of this source code is governed by a MIT-style license that can be
3+
// found in the LICENSE file.
4+
// @flow
5+
import Log from '../utils/log'
6+
import EventEmitter from 'eventemitter3'
7+
const log = new Log('node-event')
8+
9+
log.level(3)
10+
log.info('polyfill loaded')
11+
12+
// class EventEmitter {
13+
//
14+
// static defaultMaxListeners:number = 10;
15+
//
16+
// static listenerCount(emitter:EventEmitter, eventName:string):number {
17+
// return emitter._listeners ? emitter._listeners.length : 0
18+
// }
19+
//
20+
// constructor() {
21+
// log.verbose('new EventEmitter created')
22+
// this._emitter = new ee()
23+
// }
24+
//
25+
// emit() {
26+
//
27+
// }
28+
//
29+
//
30+
// }
31+
32+
33+
// since nodejs modules uses es5 export by default, we should use es5 export here
34+
export {
35+
EventEmitter
36+
}

src/node-polyfill/fs.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
// Use of this source code is governed by a MIT-style license that can be
33
// found in the LICENSE file.
44
// @flow
5+
import Log from '../utils/log'
6+
const log = new Log('node-fs')
57

6-
import {
7-
NativeModules,
8-
DeviceEventEmitter,
9-
Platform,
10-
NativeAppEventEmitter,
11-
} from 'react-native'
8+
log.level(3)
9+
log.info('polyfill loaded')
1210

13-
const RNFB = NativeModules.RNFetchBlob
14-
15-
export default class FS {
16-
17-
static
11+
// since nodejs modules uses es5 export by default, we should use es5 export here
12+
export {
1813

1914
}

src/node-polyfill/path.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,47 @@
33
// found in the LICENSE file.
44
// @flow
55
import Log from '../utils/log'
6-
import path from 'path-parse'
6+
const parse = require('path-parse')
77
const log = new Log('node-path')
8-
98
log.level(3)
10-
log.info('node-path polyfill loaded')
9+
log.info('polyfill loaded')
1110

1211
const sep = '/'
1312

1413
function basename(str:string):string {
15-
return path.parse(str).base
14+
log.verbose('basename', str)
15+
return parse(str).base
1616
}
1717

1818
function dirname(str:string):string {
19-
return path.parse(str).dir
19+
log.verbose('dirname', str)
20+
return parse(str).dir
2021
}
2122

2223
function extname(str:string):string {
23-
return path.parse(str).ext
24+
log.verbose('extname', str)
25+
return parse(str).ext
2426
}
2527

2628
function format(args:any):string {
29+
log.verbose('format', args)
2730
// TODO :
2831
}
2932

3033
function isAbsolute(str:string):boolean {
34+
log.verbose('isAbsolute', str)
3135
// TODO :
3236
return true
3337
}
3438

3539
function join(arr:Array):string {
40+
log.verbose('join', arr)
3641
// TODO : error handling and type checking
3742
return arr.join('')
3843
}
3944

4045
function normalize(str:string):string {
46+
log.verbose('normalize', str)
4147
// TODO
4248
return str
4349
}

src/node-polyfill/util.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import Log from '../utils/log'
66
const log = new Log('node-util')
77

8-
log.level(3)
9-
log.info('node-util polyfill loaded')
8+
log.level(1)
9+
log.info('polyfill loaded')
1010

1111
function inherits(ctor, superCtor):any {
1212
log.verbose('inherits', superCtor, superCtor)
@@ -17,7 +17,12 @@ function inherits(ctor, superCtor):any {
1717
return ctor
1818
}
1919

20+
function isArray(arr:any):boolean {
21+
return Array.isArray(arr)
22+
}
23+
2024
// since nodejs modules uses es5 export by default, we should use es5 export here
2125
export {
22-
inherits
26+
inherits,
27+
isArray
2328
}

test/nedb.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-init.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const { Assert, Comparer, Info, prop } = RNTest
1818
// test environment variables
1919

2020
prop('FILENAME', `${Platform.OS}-0.8.0-${Date.now()}.png`)
21-
prop('TEST_SERVER_URL', 'http://192.168.0.12:8123')
22-
prop('TEST_SERVER_URL_SSL', 'https://192.168.0.12:8124')
21+
prop('TEST_SERVER_URL', 'http://192.168.16.70:8123')
22+
prop('TEST_SERVER_URL_SSL', 'https://192.168.16.70:8124')
2323
prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
2424
prop('styles', {
2525
image : {
@@ -68,7 +68,8 @@ describe('GET image from server', (report, done) => {
6868
// require('./test-0.8.0')
6969
// require('./test-0.9.0')
7070
// require('./test-0.9.2')
71-
require('./test-0.10.0')
71+
// require('./test-0.10.0')
72+
require('./test-nedb')
7273
// require('./test-fetch')
7374
// require('./test-fs')
7475
// require('./test-xmlhttp')

test/test-nedb.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import RNTest from './react-native-testkit/'
22
import React from 'react'
33
import RNFetchBlob from 'react-native-fetch-blob'
4+
import DataStore from 'nedb'
45
import {
56
StyleSheet,
67
Text,
@@ -10,7 +11,6 @@ import {
1011
Dimensions,
1112
Image,
1213
} from 'react-native';
13-
import DataStore from 'nedb'
1414

1515
const fs = RNFetchBlob.fs
1616
const { Assert, Comparer, Info, prop } = RNTest
@@ -24,15 +24,21 @@ const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles }
2424
const dirs = RNFetchBlob.fs.dirs
2525

2626
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
27-
const DB_PATH = fs.dirs.documentDir + `/nedb/test-db-${Date.now()}.db`
28-
const dbs = []
27+
const DB_PATH = fs.dirs.DocumentDir + `/nedb/test-db-${Date.now()}.db`
28+
const db = null
2929

3030
describe('nedb persistant constructor test', (report, done) =>{
31+
db = new DataStore(DB_PATH)
32+
// db.loadDatabase(function(err) {
33+
// report(<Assert key="database should created" expect={null} actual={err}/>)
34+
// done()
35+
// })
3136

32-
let db = new DataStore(DB_PATH)
33-
db.loadDatabase(function(err) {
34-
report(<Assert key="database should created" expect={null} actual={err}/>)
35-
done()
36-
})
37+
})
3738

39+
describe('db CRUD test', (report, done) => {
40+
let data = 'first record' + Date.now()
41+
db.insert(data, (err, newDoc) => {
42+
console.log(err, newDoc)
43+
})
3844
})

0 commit comments

Comments
 (0)