Browse Source

wip commit

Ben Hsieh 7 years ago
parent
commit
eef6fcc999

+ 1
- 0
scripts/test.sh View File

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

+ 3
- 4
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java View File

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
     @Override
79
     @Override
81
     public MediaType contentType() {
80
     public MediaType contentType() {
82
         return mime;
81
         return mime;

+ 36
- 0
src/node-polyfill/events.js View File

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 View File

2
 // Use of this source code is governed by a MIT-style license that can be
2
 // Use of this source code is governed by a MIT-style license that can be
3
 // found in the LICENSE file.
3
 // found in the LICENSE file.
4
 // @flow
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 View File

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

+ 8
- 3
src/node-polyfill/util.js View File

5
 import Log from '../utils/log'
5
 import Log from '../utils/log'
6
 const log = new Log('node-util')
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
 function inherits(ctor, superCtor):any {
11
 function inherits(ctor, superCtor):any {
12
   log.verbose('inherits', superCtor, superCtor)
12
   log.verbose('inherits', superCtor, superCtor)
17
   return ctor
17
   return ctor
18
 }
18
 }
19
 
19
 
20
+function isArray(arr:any):boolean {
21
+  return Array.isArray(arr)
22
+}
23
+
20
 // since nodejs modules uses es5 export by default, we should use es5 export here
24
 // since nodejs modules uses es5 export by default, we should use es5 export here
21
 export {
25
 export {
22
-  inherits
26
+  inherits,
27
+  isArray
23
 }
28
 }

+ 4
- 0
test/nedb.js
File diff suppressed because it is too large
View File


+ 4
- 3
test/test-init.js View File

18
 // test environment variables
18
 // test environment variables
19
 
19
 
20
 prop('FILENAME', `${Platform.OS}-0.8.0-${Date.now()}.png`)
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
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24
 prop('styles', {
24
 prop('styles', {
25
   image : {
25
   image : {
68
 // require('./test-0.8.0')
68
 // require('./test-0.8.0')
69
 // require('./test-0.9.0')
69
 // require('./test-0.9.0')
70
 // require('./test-0.9.2')
70
 // require('./test-0.9.2')
71
-require('./test-0.10.0')
71
+// require('./test-0.10.0')
72
+require('./test-nedb')
72
 // require('./test-fetch')
73
 // require('./test-fetch')
73
 // require('./test-fs')
74
 // require('./test-fs')
74
 // require('./test-xmlhttp')
75
 // require('./test-xmlhttp')

+ 14
- 8
test/test-nedb.js View File

1
 import RNTest from './react-native-testkit/'
1
 import RNTest from './react-native-testkit/'
2
 import React from 'react'
2
 import React from 'react'
3
 import RNFetchBlob from 'react-native-fetch-blob'
3
 import RNFetchBlob from 'react-native-fetch-blob'
4
+import DataStore from 'nedb'
4
 import {
5
 import {
5
   StyleSheet,
6
   StyleSheet,
6
   Text,
7
   Text,
10
   Dimensions,
11
   Dimensions,
11
   Image,
12
   Image,
12
 } from 'react-native';
13
 } from 'react-native';
13
-import DataStore from 'nedb'
14
 
14
 
15
 const fs = RNFetchBlob.fs
15
 const fs = RNFetchBlob.fs
16
 const { Assert, Comparer, Info, prop } = RNTest
16
 const { Assert, Comparer, Info, prop } = RNTest
24
 const dirs = RNFetchBlob.fs.dirs
24
 const dirs = RNFetchBlob.fs.dirs
25
 
25
 
26
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
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
 describe('nedb persistant constructor test', (report, done) =>{
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
 })