Ben Hsieh 7 лет назад
Родитель
Сommit
eef6fcc999

+ 1
- 0
scripts/test.sh Просмотреть файл

@@ -45,6 +45,7 @@ npm install --save firebase
45 45
 npm install --save oboe
46 46
 npm install --save nedb
47 47
 # for node polyfills
48
+npm install crypto-js --save
48 49
 npm install babel-plugin-add-module-exports --save-dev
49 50
 npm install babel-plugin-modue-alias --save-dev
50 51
 npm install path-parse --save

+ 3
- 4
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java Просмотреть файл

@@ -73,10 +73,9 @@ public class RNFetchBlobBody extends RequestBody{
73 73
         }
74 74
     }
75 75
 
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
+
80 79
     @Override
81 80
     public MediaType contentType() {
82 81
         return mime;

+ 36
- 0
src/node-polyfill/events.js Просмотреть файл

@@ -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
+}

+ 6
- 11
src/node-polyfill/fs.js Просмотреть файл

@@ -2,18 +2,13 @@
2 2
 // Use of this source code is governed by a MIT-style license that can be
3 3
 // found in the LICENSE file.
4 4
 // @flow
5
+import Log from '../utils/log'
6
+const log = new Log('node-fs')
5 7
 
6
-import {
7
-  NativeModules,
8
-  DeviceEventEmitter,
9
-  Platform,
10
-  NativeAppEventEmitter,
11
-} from 'react-native'
8
+log.level(3)
9
+log.info('polyfill loaded')
12 10
 
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 {
18 13
 
19 14
 }

+ 12
- 6
src/node-polyfill/path.js Просмотреть файл

@@ -3,41 +3,47 @@
3 3
 // found in the LICENSE file.
4 4
 // @flow
5 5
 import Log from '../utils/log'
6
-import path from 'path-parse'
6
+const parse = require('path-parse')
7 7
 const log = new Log('node-path')
8
-
9 8
 log.level(3)
10
-log.info('node-path polyfill loaded')
9
+log.info('polyfill loaded')
11 10
 
12 11
 const sep = '/'
13 12
 
14 13
 function basename(str:string):string {
15
-  return path.parse(str).base
14
+  log.verbose('basename', str)
15
+  return parse(str).base
16 16
 }
17 17
 
18 18
 function dirname(str:string):string {
19
-  return path.parse(str).dir
19
+  log.verbose('dirname', str)
20
+  return parse(str).dir
20 21
 }
21 22
 
22 23
 function extname(str:string):string {
23
-  return path.parse(str).ext
24
+  log.verbose('extname', str)
25
+  return parse(str).ext
24 26
 }
25 27
 
26 28
 function format(args:any):string {
29
+  log.verbose('format', args)
27 30
   // TODO :
28 31
 }
29 32
 
30 33
 function isAbsolute(str:string):boolean {
34
+  log.verbose('isAbsolute', str)
31 35
   // TODO :
32 36
   return true
33 37
 }
34 38
 
35 39
 function join(arr:Array):string {
40
+  log.verbose('join', arr)
36 41
   // TODO : error handling and type checking
37 42
   return arr.join('')
38 43
 }
39 44
 
40 45
 function normalize(str:string):string {
46
+  log.verbose('normalize', str)
41 47
   // TODO
42 48
   return str
43 49
 }

+ 8
- 3
src/node-polyfill/util.js Просмотреть файл

@@ -5,8 +5,8 @@
5 5
 import Log from '../utils/log'
6 6
 const log = new Log('node-util')
7 7
 
8
-log.level(3)
9
-log.info('node-util polyfill loaded')
8
+log.level(1)
9
+log.info('polyfill loaded')
10 10
 
11 11
 function inherits(ctor, superCtor):any {
12 12
   log.verbose('inherits', superCtor, superCtor)
@@ -17,7 +17,12 @@ function inherits(ctor, superCtor):any {
17 17
   return ctor
18 18
 }
19 19
 
20
+function isArray(arr:any):boolean {
21
+  return Array.isArray(arr)
22
+}
23
+
20 24
 // since nodejs modules uses es5 export by default, we should use es5 export here
21 25
 export {
22
-  inherits
26
+  inherits,
27
+  isArray
23 28
 }

+ 4
- 0
test/nedb.js
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 4
- 3
test/test-init.js Просмотреть файл

@@ -18,8 +18,8 @@ const { Assert, Comparer, Info, prop } = RNTest
18 18
 // test environment variables
19 19
 
20 20
 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')
23 23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24 24
 prop('styles', {
25 25
   image : {
@@ -68,7 +68,8 @@ describe('GET image from server', (report, done) => {
68 68
 // require('./test-0.8.0')
69 69
 // require('./test-0.9.0')
70 70
 // require('./test-0.9.2')
71
-require('./test-0.10.0')
71
+// require('./test-0.10.0')
72
+require('./test-nedb')
72 73
 // require('./test-fetch')
73 74
 // require('./test-fs')
74 75
 // require('./test-xmlhttp')

+ 14
- 8
test/test-nedb.js Просмотреть файл

@@ -1,6 +1,7 @@
1 1
 import RNTest from './react-native-testkit/'
2 2
 import React from 'react'
3 3
 import RNFetchBlob from 'react-native-fetch-blob'
4
+import DataStore from 'nedb'
4 5
 import {
5 6
   StyleSheet,
6 7
   Text,
@@ -10,7 +11,6 @@ import {
10 11
   Dimensions,
11 12
   Image,
12 13
 } from 'react-native';
13
-import DataStore from 'nedb'
14 14
 
15 15
 const fs = RNFetchBlob.fs
16 16
 const { Assert, Comparer, Info, prop } = RNTest
@@ -24,15 +24,21 @@ const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles }
24 24
 const dirs = RNFetchBlob.fs.dirs
25 25
 
26 26
 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
29 29
 
30 30
 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
+  // })
31 36
 
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
+})
37 38
 
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
+  })
38 44
 })