-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Hargne/develop
Develop
- Loading branch information
Showing
7 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Splits test suites apart based on individual test status and sorts by that status: | ||
* 1. Pending | ||
* 2. Failed | ||
* 3. Passed | ||
* @param {Object} suiteResults | ||
*/ | ||
const sortSuiteResultsByStatus = (suiteResults) => { | ||
const pendingSuites = []; | ||
const failingSuites = []; | ||
const passingSuites = []; | ||
|
||
suiteResults.forEach((suiteResult) => { | ||
const pending = []; | ||
const failed = []; | ||
const passed = []; | ||
|
||
suiteResult.testResults.forEach((x) => { | ||
if (x.status === 'pending') { | ||
pending.push(x); | ||
} else if (x.status === 'failed') { | ||
failed.push(x); | ||
} else { | ||
passed.push(x); | ||
} | ||
}); | ||
|
||
if (pending.length) { | ||
pendingSuites.push(Object.assign({}, suiteResult, { testResults: pending })); | ||
} | ||
if (failed.length) { | ||
failingSuites.push(Object.assign({}, suiteResult, { testResults: failed })); | ||
} | ||
if (passed.length) { | ||
passingSuites.push(Object.assign({}, suiteResult, { testResults: passed })); | ||
} | ||
}); | ||
|
||
return [].concat(pendingSuites, failingSuites, passingSuites); | ||
}; | ||
|
||
/** | ||
* Sorts test suite results | ||
* If sort is undefined or is not a supported value this has no effect | ||
* @param {Object} suiteResults | ||
* @param {String} sort The configured sort | ||
*/ | ||
const sortSuiteResults = (suiteResults, sort) => { | ||
if (sort === 'status') { | ||
return sortSuiteResultsByStatus(suiteResults); | ||
} | ||
|
||
return suiteResults; | ||
}; | ||
|
||
module.exports = { | ||
sortSuiteResults, | ||
sortSuiteResultsByStatus, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
module.exports = { | ||
jestTestData: { | ||
success: true, | ||
startTime: 1498476492, | ||
numTotalTestSuites: 3, | ||
numPassedTestSuites: 1, | ||
numFailedTestSuites: 1, | ||
numRuntimeErrorTestSuites: 1, | ||
numTotalTests: 9, | ||
numPassedTests: 7, | ||
numFailedTests: 1, | ||
numPendingTests: 1, | ||
testResults: [ | ||
{ | ||
numFailingTests: 0, | ||
numPassingTests: 3, | ||
numPendingTests: 0, | ||
testResults: [ | ||
{ | ||
title: 'title', | ||
status: 'passed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
{ | ||
title: 'title', | ||
status: 'passed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
{ | ||
title: 'title', | ||
status: 'passed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
], | ||
perfStats: { | ||
start: 1498476492, | ||
end: 1498476639, | ||
}, | ||
testFilePath: 'index-a.js', | ||
}, | ||
{ | ||
numFailingTests: 1, | ||
numPassingTests: 1, | ||
numPendingTests: 1, | ||
testResults: [ | ||
{ | ||
title: 'title', | ||
status: 'pending', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
{ | ||
title: 'title', | ||
status: 'failed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: ['failure'], | ||
numPassingAsserts: 0, | ||
}, | ||
{ | ||
title: 'title', | ||
status: 'passed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
], | ||
perfStats: { | ||
start: 1498476492, | ||
end: 1498476639, | ||
}, | ||
testFilePath: 'index-b.js', | ||
}, | ||
{ | ||
numFailingTests: 1, | ||
numPassingTests: 1, | ||
numPendingTests: 1, | ||
testResults: [ | ||
{ | ||
title: 'title', | ||
status: 'pending', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
{ | ||
title: 'title', | ||
status: 'failed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: ['failure'], | ||
numPassingAsserts: 0, | ||
}, | ||
{ | ||
title: 'title', | ||
status: 'passed', | ||
ancestorTitles: ['ancestor'], | ||
failureMessages: [], | ||
numPassingAsserts: 0, | ||
}, | ||
], | ||
perfStats: { | ||
start: 1498476492, | ||
end: 1498476639, | ||
}, | ||
testFilePath: 'index-c.js', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const sorting = require('../src/sorting'); | ||
const mockdataSorting = require('./_mockdata-sorting'); | ||
|
||
describe('sorting', () => { | ||
it('should have no effect when sort not configured', () => { | ||
const { testResults } = mockdataSorting.jestTestData; | ||
const sortedTestResults = sorting.sortSuiteResults(testResults, undefined); | ||
|
||
expect(sortedTestResults.length).toEqual(testResults.length); | ||
|
||
testResults.forEach((testResult, index) => { | ||
expect(sortedTestResults[index].testFilePath).toEqual(testResult.testFilePath); | ||
}); | ||
}); | ||
|
||
describe('sortByStatus', () => { | ||
/* | ||
see _mockdata-sorting for test data | ||
expected results for "status" are: | ||
pending from index-b | ||
pending from index-c | ||
failed from index-b | ||
failed from index-c | ||
passed from index-a | ||
passed from index-b | ||
passed from index-c | ||
meaning that the results are now broken into three sections: | ||
1. pending | ||
2. failed | ||
3. passed | ||
the pending and failed sections' sorting should match the passed section's sorting to make tests easier to find | ||
*/ | ||
|
||
it('should order results as 1.pending 2.failed 3.passed', () => { | ||
const { testResults } = mockdataSorting.jestTestData; | ||
const sortedTestResults = sorting.sortSuiteResultsByStatus(testResults); | ||
|
||
// pending | ||
expect(sortedTestResults[0].testResults.length).toEqual(1); | ||
expect(sortedTestResults[0].numPendingTests).toEqual(1); | ||
expect(sortedTestResults[0].testFilePath).toEqual('index-b.js'); | ||
|
||
expect(sortedTestResults[1].testResults.length).toEqual(1); | ||
expect(sortedTestResults[1].numPendingTests).toEqual(1); | ||
expect(sortedTestResults[1].testFilePath).toEqual('index-c.js'); | ||
|
||
// failed | ||
expect(sortedTestResults[2].testResults.length).toEqual(1); | ||
expect(sortedTestResults[2].numFailingTests).toEqual(1); | ||
expect(sortedTestResults[2].testFilePath).toEqual('index-b.js'); | ||
|
||
expect(sortedTestResults[3].testResults.length).toEqual(1); | ||
expect(sortedTestResults[3].numFailingTests).toEqual(1); | ||
expect(sortedTestResults[3].testFilePath).toEqual('index-c.js'); | ||
|
||
// passed | ||
expect(sortedTestResults[4].testResults.length).toEqual(3); | ||
expect(sortedTestResults[4].numPassingTests).toEqual(3); | ||
expect(sortedTestResults[4].testFilePath).toEqual('index-a.js'); | ||
|
||
expect(sortedTestResults[5].testResults.length).toEqual(1); | ||
expect(sortedTestResults[5].numPassingTests).toEqual(1); | ||
expect(sortedTestResults[5].testFilePath).toEqual('index-b.js'); | ||
|
||
expect(sortedTestResults[6].testResults.length).toEqual(1); | ||
expect(sortedTestResults[6].numPassingTests).toEqual(1); | ||
expect(sortedTestResults[6].testFilePath).toEqual('index-c.js'); | ||
}); | ||
|
||
it('should sort all passed tests as default', () => { | ||
const { testResults } = mockdataSorting.jestTestData; | ||
const sortedTestResults = sorting.sortSuiteResultsByStatus(testResults); | ||
|
||
// skipping the pending and failed sections of the output, the remainder should match | ||
// currently the test data has two suites that each have one failed and one pending test, so skip 4 | ||
expect(sortedTestResults[4].testFilePath).toEqual(testResults[0].testFilePath); | ||
expect(sortedTestResults[5].testFilePath).toEqual(testResults[1].testFilePath); | ||
expect(sortedTestResults[6].testFilePath).toEqual(testResults[2].testFilePath); | ||
}); | ||
}); | ||
}); |