-
Notifications
You must be signed in to change notification settings - Fork 48
/
testsScore.js
45 lines (39 loc) · 1.06 KB
/
testsScore.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
function getScore(jestObject) {
// Initiliaze score trackers
let totalScore = 0;
let score = 0;
const moduleScores = {
Arrays: 0,
Numbers: 0,
Strings: 0,
"Conditionals and Loops": 0,
};
const moduleTotalScores = {
Arrays: 0,
Strings: 0,
"Conditionals and Loops": 0,
Numbers: 0,
};
// Populate the results
jestObject.testResults.forEach((testResult) => {
testResult.testResults.forEach((test) => {
// Get the constants
const category = test.ancestorTitles[0];
const points = parseInt(test.title.split(" ")[0].slice(1));
// Update totals
totalScore += points;
moduleTotalScores[category] += points;
// Update scores if passed
if (test.status === "passed") {
score += points;
moduleScores[category] += points;
}
});
});
// Log results to terminal
console.log("\n\n");
console.log(`You scored ${score}/${totalScore} points.\n\nHere are your module-wise scores:`);
for (mod in moduleScores) console.log(`${mod}\t: ${moduleScores[mod]}/${moduleTotalScores[mod]}`);
return jestObject;
}
module.exports = getScore;