-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
77 lines (59 loc) · 3.21 KB
/
script.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
const { execSync } = require('child_process');
const Utilities = require('./utilities');
const path = require("path");
async function main(){
const projectName = 'biojava';
const projectURL = 'https://github.com/biojava/biojava';
const unfixedFlakyTestsFilePath = 'unfixedFlakyTests/list.csv';
console.log('=================================================================');
console.log(` Running NonDex script for ID tests`);
console.log('=================================================================');
console.log(` Project Name: ${projectName}`);
console.log(` Project URL: ${projectURL}`);
console.log('=================================================================');
console.log();
const unfixedFlakyTests = await Utilities.readCSV(unfixedFlakyTestsFilePath);
const unfixedTests = unfixedFlakyTests.map(x=>x['Fully-Qualified Test Name (packageName.ClassName.methodName)']);
const commits = Array.from(new Set(unfixedFlakyTests.map(x=>x['SHA Detected'])));
const latestCommit = execSync(`git ls-remote ${projectURL} | head -1 | sed "s/HEAD//"`).toString().replace('\t\n','');
console.log(`Latest commit from master branch is ${latestCommit}`);
console.log(`Current commit from master branch is ${commits}`);
console.log();
if (commits.includes(latestCommit)) {
console.log(`There are no updates on the git repository. There are still ${unfixedFlakyTests.length} flaky tests:`);
console.log(unfixedTests.join('\n'));
return 0;
}
console.log(`Running NoDex script for ID tests. This may take up to several hours.`);
execSync('rm -rf projects/*');
execSync(`cd projects && git clone ${projectURL}`);
const output = execSync(`cd projects/${projectName} && mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex`).toString();
// mocking log file
// const output = Utilities.readFile('mockedLogs/output.log');
const rePattern = new RegExp(/file:\/\/(.*)/g);
let paths = output.match(rePattern);
paths = paths.map(x=>Utilities.removeFilePart(x.replace('file:\/\/','')));
console.log(`Analysing results, this may take up to several minutes.`);
console.log();
let newflakyTests = [];
for (const p of paths){
const failurePath = path.join(p,'failures');
if (Utilities.fileExists(failurePath)){
const result = Utilities.readFile(failurePath);
newflakyTests = newflakyTests.concat(result.split('\n').filter((item) => newflakyTests.indexOf(item) < 0 && item !== ''));
}
}
const oldTests = unfixedTests.filter(x=>newflakyTests.includes(x));
const newTests = newflakyTests.filter(x=>!unfixedTests.includes(x));
const fixedTests = unfixedTests.filter(x=>!newflakyTests.includes(x));
console.log(`There are still ${oldTests.length} old unfixed flaky tests, ${newTests.length} new flaky tests, and ${fixedTests.length} fixed flaky tests.`);
console.log('Old flaky tests:');
console.log(oldTests.join('\n'));
console.log();
console.log('New flaky tests:');
console.log(newTests.join('\n'));
console.log();
console.log('Fixed flaky tests:');
console.log(fixedTests.join('\n'));
}
main();