forked from apidoc/apidoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_input_folder_test.js
98 lines (75 loc) · 3.3 KB
/
multi_input_folder_test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*jshint unused:false, expr:true */
/**
* Test: apiDoc creation from multiple folder
*/
var fs = require('fs-extra');
var exec = require('child_process').exec;
var path = require('path');
var should = require('should');
describe('apiDoc multiple folder input', function() {
var fixturePath = 'test/multi_input_folder/fixtures';
var projectBaseBath = 'test/multi_input_folder/testproject';
var testTargetPath = "./tmp/apidocmulti";
var fixtureFiles = [
'api_data.js',
'api_data.json',
'api_project.js',
'api_project.json',
'index.html'
];
before(function(done) {
fs.removeSync(testTargetPath);
done();
});
after(function(done) {
done();
});
it('should create apidoc in /tmp/apidocmulti with multiple input folders', function(done) {
var commonDefinitions = path.join('', 'folder1');
var historyDefinition = path.join('', 'folder2');
var srcFolder = path.join('', 'src');
var cmd = 'cd ' + projectBaseBath + ' && ';
cmd += 'node ../../../bin/apidoc';
cmd += ' -i ' + commonDefinitions;
cmd += ' -i ' + historyDefinition;
cmd += ' -i ' + srcFolder;
cmd += ' -o ../../../tmp/apidocmulti';
cmd += ' -t ../../template/';
exec(cmd, function(err, stdout, stderr) {
if (err)
throw err;
if (stderr)
throw stderr;
done();
});
});
it('created files should equal to fixtures', function(done) {
var timeRegExp = /\"time\"\:\s\"(.*)\"/g;
var versionRegExp = /\"version\"\:\s\"(.*)\"/g;
var filenameRegExp = new RegExp('(?!"filename":\\s")(' + projectBaseBath + '/)', 'g');
fixtureFiles.forEach(function(name) {
var fixtureContent = fs.readFileSync(path.join(fixturePath, name), 'utf8');
var createdContent = fs.readFileSync(path.join(testTargetPath, name), 'utf8');
// creation time remove (never equal)
fixtureContent = fixtureContent.replace(timeRegExp, '');
createdContent = createdContent.replace(timeRegExp, '');
// creation time remove (or fixtures must be updated every time the version change)
fixtureContent = fixtureContent.replace(versionRegExp, '');
createdContent = createdContent.replace(versionRegExp, '');
// remove the base path
createdContent = createdContent.replace(filenameRegExp, '');
var fixtureLines = fixtureContent.split(/\n/);
var createdLines = createdContent.split(/\n/);
if (fixtureLines.length !== createdLines.length)
throw new Error('File ' + path.join(testTargetPath, name) + ' not equals to ' + fixturePath + '/' + name);
for (var lineNumber = 0; lineNumber < fixtureLines.length; lineNumber += 1) {
if (fixtureLines[lineNumber] !== createdLines[lineNumber])
throw new Error('File ' + path.join(testTargetPath, name) + ' not equals to ' + fixturePath + '/' + name + ' in line ' + (lineNumber + 1) +
'\nfixture: ' + fixtureLines[lineNumber] +
'\ncreated: ' + createdLines[lineNumber]
);
}
});
done();
});
});