2 * Copyright 2014 IBM Corp.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This test simply checks that for every .js file there exists
19 * a *_spec.js file under ./test correspondingly.
23 * Currently we're only checking the core components under ./red
24 * TODO: Increase the scope of this check
27 var fs = require("fs");
28 var should = require("should");
29 var path = require('path');
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");
35 var fs = require('fs');
36 var walkDirectory = function(dir, topdir, done) {
37 fs.readdir(dir, function(err, list) {
39 var errReturned = false;
48 // return error if there are no more files to check and error has not been previously returned to avoid multiple calls to done()
55 file = path.resolve(dir, file);
56 fs.stat(file, function(err, stat) {
57 if (stat && stat.isDirectory()) {
58 walkDirectory(file, false, function(err) {
65 if (path.extname(file) === ".js") {
66 var testFile = file.replace(jsdir, testdir).replace(".js", "_spec.js");
67 fs.exists(testFile, function (exists) {
69 exists.should.equal(true, testFile + " does not exist");
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);