Use released versions of maven artifacts
[ccsdk/distribution.git] / dgbuilder / test / _spec.js
1 /**
2  * Copyright 2014 IBM Corp.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  **/
16
17 /**
18  * This test simply checks that for every .js file there exists
19  * a *_spec.js file under ./test correspondingly.
20  */
21
22 /**
23  * Currently we're only checking the core components under ./red
24  * TODO: Increase the scope of this check
25  */
26
27 var fs = require("fs");
28 var should = require("should");
29 var path = require('path');
30
31 // Directories to check with .js files and _spec.js files respectively
32 var jsdir = path.resolve(__dirname, "../red");
33 var testdir = path.resolve(__dirname, "red");
34
35 var fs = require('fs');
36 var walkDirectory = function(dir, topdir, done) {
37     fs.readdir(dir, function(err, list) {
38         var error;
39         var errReturned = false;
40         if (err) {
41             return done(err);
42         }
43
44         var i = 0;
45         (function next() {
46             var file = list[i++];
47
48             // return error if there are no more files to check and error has not been previously returned to avoid multiple calls to done()
49             if (!file) {
50                 if (!errReturned) {
51                     errReturned = true;
52                     return done(error);
53                 }
54             } else {
55                 file = path.resolve(dir, file);
56                 fs.stat(file, function(err, stat) {
57                     if (stat && stat.isDirectory()) {
58                         walkDirectory(file, false, function(err) {
59                             if (!error) {
60                                 error = err;
61                             }
62                             next();
63                         });
64                     } else {
65                         if (path.extname(file) === ".js") {
66                             var testFile = file.replace(jsdir, testdir).replace(".js", "_spec.js");
67                             fs.exists(testFile, function (exists) {
68                                 try {
69                                     exists.should.equal(true, testFile + " does not exist");
70                                 } catch (err) {
71                                     if (!topdir) {
72                                         return done(err);
73                                     } else {
74                                         error = err;
75                                         return;
76                                     }
77                                 }
78                             });
79                         }
80                         next();
81                     }
82                 });
83             }
84         })();
85     });
86 };
87
88 describe('_spec.js', function() {
89     this.timeout(50000); // we might not finish within the Mocha default timeout limit, project will also grow
90     it('is checking if all .js files have a corresponding _spec.js test file.', function(done) {
91         walkDirectory(jsdir, true, done);
92     });
93 });