-
Notifications
You must be signed in to change notification settings - Fork 0
/
proof.js
39 lines (33 loc) · 1.55 KB
/
proof.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
const fs = require('fs');
const cheerio = require('cheerio');
const glob = require("glob");
//note : the npm main command must be run from the project root
const appDir = process.cwd();
const generateTestsResults = function() {
glob(`${appDir}/**/*_proof.js`, function (er, files) {
files.forEach(file => {
const fixtures = require(`${file}`);
var contents = fs.readFileSync(`${file.substr(0, file.lastIndexOf("."))}.html`).toString();
let $ = cheerio.load(contents);
let rows = $('tr');
rows.map(function () {
let functionToExecute = $(this).parent().data('execute');
let args = [];
const columns = $(this).find('td');
for (let i = 0; i < columns.length - 1; i++) {
args.push($(this).find('td').eq(i).text());
}
const expected = $(this).find('td').eq(columns.length - 1).text();
const result = fixtures[functionToExecute](args);
if (expected == result) {
$(this).find('td').eq(columns.length - 1).css('background-color', "green");
} else {
$(this).find('td').eq(columns.length - 1).css('background-color', "red");
$(this).find('td').eq(columns.length - 1).text(`expected ${expected } but was ${result}`);
}
});
fs.writeFileSync(`${file.substr(0, file.lastIndexOf("."))}_result.html`, $.html());
})
});
};
generateTestsResults();