-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.js
86 lines (76 loc) · 2.47 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
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
/**
* Checks if a test spec is marked as skipped
* @param {Object} spec - Test specification object
* @returns {boolean} True if the test is skipped
*/
function isTestSkipped(spec) {
return spec.tests?.[0] && (
spec.tests[0].annotations?.some(a => a.type === 'skip') ||
spec.tests[0].status === 'skipped'
);
}
/**
* Extracts test information from a test suite recursively
* @param {Object} suite - Test suite object
* @param {string} parentTitle - Parent suite title for nested suites
* @returns {Array} Array of test objects with metadata
*/
function extractTestsFromSuite(suite, parentTitle = '') {
const tests = [];
const fullSuiteTitle = parentTitle ? `${parentTitle} > ${suite.title}` : suite.title;
// Process individual test specs
if (suite.specs) {
const suiteTests = suite.specs.map(spec => {
const isSkipped = isTestSkipped(spec);
return {
title: spec.title,
fullTitle: `${fullSuiteTitle} > ${spec.title}`,
status: isSkipped ? 'skipped' : (spec.ok ? 'passed' : 'failed'),
file: suite.file,
skipped: isSkipped
};
});
tests.push(...suiteTests);
}
// Recursively process nested suites
if (suite.suites) {
suite.suites.forEach(nestedSuite => {
const nestedTests = extractTestsFromSuite(nestedSuite, fullSuiteTitle);
tests.push(...nestedTests);
});
}
return tests;
}
/**
* Compares current and main branch test results
* @param {Array} currentTests - Tests from current branch
* @param {Array} mainTests - Tests from main branch
* @returns {Object} Test comparison results
*/
function compareTests(currentTests, mainTests) {
const comparison = { new: [], skipped: [], deleted: [] };
const currentTestMap = new Map(currentTests.map(t => [t.fullTitle, t]));
const mainTestMap = new Map(mainTests.map(t => [t.fullTitle, t]));
// Find new and skipped tests
for (const [fullTitle, test] of currentTestMap) {
if (!mainTestMap.has(fullTitle)) {
comparison.new.push(`${test.title} (${test.file})`);
}
if (test.skipped) {
comparison.skipped.push(`${test.title} (${test.file})`);
}
}
// Find deleted tests
for (const [fullTitle, test] of mainTestMap) {
if (!currentTestMap.has(fullTitle)) {
comparison.deleted.push(`${test.title} (${test.file})`);
}
}
comparison.skipped = Array.from(new Set(comparison.skipped));
return comparison;
}
module.exports = {
isTestSkipped,
extractTestsFromSuite,
compareTests
};