Blame view

unitTest/test.js 1.3 KB
30fb6c36   sumatek   update fixbug post
1
var readTextFile = require('read-text-file');
180aaa4d   sumatek   update unit test
2
const path = require('path');
30fb6c36   sumatek   update fixbug post
3
4


180aaa4d   sumatek   update unit test
5
6
var dir = path.parse(__dirname);

30fb6c36   sumatek   update fixbug post
7
8
9
10
11
12
13
14
15
try{
  var testCaseStr = readTextFile.readSync('./unitTest/testCase.txt').trim("\r\n").split("\r\n");
  var testCase = [];
  // console.log(testCaseStr);
  for(var i=0;i<testCaseStr.length;i++)
    testCase.push(JSON.parse(testCaseStr[i])); 


    describe('unitTest app',function() {      
49559b6c   sumatek   merge
16
      
30fb6c36   sumatek   update fixbug post
17
      for(var i=0;i<testCase.length;i++)
8349d210   sumatek   update unittest
18
19
20
      {        
        var func = require(dir.dir+path.sep+testCase[i].from);
        var expect = testCase[i].expect;
30fb6c36   sumatek   update fixbug post
21
        var comment = testCase[i].comment!=""?" => "+testCase[i].comment:testCase[i].comment;
180aaa4d   sumatek   update unit test
22
23
        

180aaa4d   sumatek   update unit test
24
25
       
        testCase[i].input = getTrueData(testCase[i].input);
8349d210   sumatek   update unittest
26
27
28
29
30

        var cal = func[testCase[i].function](...testCase[i].input);
        it(testCase[i].function+comment ,function(done) {
          
          if (expect == cal) {
180aaa4d   sumatek   update unit test
31
            done();
49559b6c   sumatek   merge
32
          } else {
30fb6c36   sumatek   update fixbug post
33
34
35
36
37
            done(new Error("fail"));
          }
      
        });
      }
49559b6c   sumatek   merge
38
    });
30fb6c36   sumatek   update fixbug post
39
}
49559b6c   sumatek   merge
40
catch(err) {
49559b6c   sumatek   merge
41
  // console.log(err);
30fb6c36   sumatek   update fixbug post
42
43
44
45
}

function getTrueData(input)
{
49559b6c   sumatek   merge
46

180aaa4d   sumatek   update unit test
47
48
  // console.log(input);
  for(var j=0;j<input.length;j++)
49559b6c   sumatek   merge
49
  {
180aaa4d   sumatek   update unit test
50
51
52
53
54
55
56
57
58
59
60
61
    try
    {
      input[j] = JSON.parse(input[j]);
    }catch(err) {
      // console.log(err);
    }
    
    // console.log(input[j]);
  }

  return input;
}