-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestFileUtil.js
63 lines (47 loc) · 1.57 KB
/
testFileUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var assert = require('assert')
var fileUtil = require('./fileUtil.js')
var debug = require('debug')('myApp:testFileUtil')
//Dummy function for test purpose
function processOnFileContent(fileName, content) {
debug("File Name: " + fileName)
debug("Contet Size: " + content.length)
throw new Error("Testing failed..")
}
function onError(error) {
debug(error)
throw new Error("Testing failed..")
}
describe('ReadFiles', function() {
debug("Current Dir: " + __dirname)
it('Should Read files', function(done) {
assert.doesNotThrow(
function() {
fileUtil.readFiles(__dirname,processOnFileContent,onError)
},
Error("Testing failed..")
)
debugger
done()
})
})
/*
TODO: Need to find way for checking exception
ref: http://stackoverflow.com/questions/26073873/assertionerror-missing-expected-exception-when-testing-async-requirejs-call-usi
*/
// describe('ReadFiles for non existent file', function() {
// const error = new Error("no such file or directory")
// error.errno=-4058
// error.code='ENOENT'
// it('Should throw exception for No Such file or dir', function() {
// assert.throws(function() {
// fileUtil.readFiles("NoSuchDirExists",processOnFileContent,onError)
// }, error)
// })
// })
// { [Error: ENOENT: no such file or directory, scandir 'D:\Projects\MEAN\PCI\NoSuchDirExists']
// errno: -4058,
// code: 'ENOENT',
// syscall: 'scandir',
// path: 'D:\\Projects\\MEAN\\PCI\\NoSuchDirExists' }
// myApp:testFileUtil Error: ENOENT: no such file or directory, scandir 'D:\Projects\MEAN\PCI\NoSuchDirExists'
// at Error (native) +30ms