-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Find duplicate and slow tests (#9188)
- Loading branch information
Showing
13 changed files
with
43 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
10.14.2 | ||
|
||
20.15.0 |
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
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
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 |
---|---|---|
@@ -1,15 +1,45 @@ | ||
// Sets a global variable to the current test spec | ||
// ex: global.currentSpec.description | ||
|
||
const { performance } = require('perf_hooks'); | ||
global.currentSpec = null; | ||
|
||
const timerMap = {}; | ||
const duplicates = []; | ||
/** The minimum execution time in seconds for a test to be considered slow. */ | ||
const slowTestLimit = 2; | ||
|
||
class CurrentSpecReporter { | ||
specStarted(spec) { | ||
if (timerMap[spec.fullName]) { | ||
console.log('Duplicate spec: ' + spec.fullName); | ||
duplicates.push(spec.fullName); | ||
} | ||
timerMap[spec.fullName] = performance.now(); | ||
global.currentSpec = spec; | ||
} | ||
specDone() { | ||
specDone(result) { | ||
if (result.status === 'excluded') { | ||
delete timerMap[result.fullName]; | ||
return; | ||
} | ||
timerMap[result.fullName] = (performance.now() - timerMap[result.fullName]) / 1000; | ||
global.currentSpec = null; | ||
} | ||
} | ||
global.displaySlowTests = function() { | ||
const times = Object.values(timerMap).sort((a,b) => b - a); | ||
if (times.length > 0) { | ||
console.log(`Slow tests with execution time >=${slowTestLimit}s:`); | ||
} | ||
times.forEach((time) => { | ||
if (time >= slowTestLimit) { | ||
console.warn(`${time.toFixed(1)}s:`, Object.keys(timerMap).find(key => timerMap[key] === time)); | ||
} | ||
}); | ||
console.log('\n'); | ||
duplicates.forEach((spec) => { | ||
console.warn('Duplicate spec: ' + spec); | ||
}); | ||
}; | ||
|
||
module.exports = CurrentSpecReporter; |