-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
49 lines (41 loc) · 1.32 KB
/
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
var fs = require('fs');
var file = fs.readFileSync('./tutorials.json', 'utf8');
describe('tutorials.json', function(){
it('should have valid json structure', function(){
JSON.parse(file);
})
it('all files exists', function() {
var json = JSON.parse(file);
if (!Array.isArray(json)) {
throw Error('tutorials.json is not an array');
}
for (var i = 0; i < json.length; i++) {
var page = json[i];
var fileContents = fs.readFileSync('./tutorials/' + page.file, 'utf8');
if (!fileContents) {
throw Error('file "' + page.file + '" is empty');
}
}
})
it('should not generate errors with highlightjs', function() {
var json = JSON.parse(file);
if (!Array.isArray(json)) {
throw Error('tutorials.json is not an array');
}
for (var i = 0; i < json.length; i++) {
var page = json[i];
var fileContents = fs.readFileSync('./tutorials/' + page.file, 'utf8');
if (!fileContents) {
throw Error('file "' + page.file + '" is empty');
}
var re = /\n```.*```/g;
if (re.test(fileContents)) {
throw Error('code without language should not start in a new line');
}
var re = /```console\n/g;
if (re.test(fileContents)) {
throw Error('console language does not exist');
}
}
});
})