enforce strict Jest test time limits for build health
refs DE-1303 Change-Id: I121ee4a6180b12aa0f9e9e6993a047890162409b Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/298136 Reviewed-by: James Butters <jbutters@instructure.com> QA-Review: Aaron Ogata <aogata@instructure.com> Product-Review: Aaron Ogata <aogata@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
parent
acfa2adf17
commit
df9ea9fe1f
|
@ -74,7 +74,7 @@ module.exports = {
|
|||
moduleFileExtensions: [...defaults.moduleFileExtensions, 'coffee', 'handlebars'],
|
||||
restoreMocks: true,
|
||||
|
||||
testEnvironment: 'jsdom',
|
||||
testEnvironment: '<rootDir>/jest/strictTimeLimitEnvironment.js',
|
||||
|
||||
transform: {
|
||||
'\\.coffee$': '<rootDir>/jest/coffeeTransformer.js',
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2022 - present Instructure, Inc.
|
||||
*
|
||||
* This file is part of Canvas.
|
||||
*
|
||||
* Canvas is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License as published by the Free
|
||||
* Software Foundation, version 3 of the License.
|
||||
*
|
||||
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
const BaseEnvironment = require('jest-environment-jsdom').default;
|
||||
|
||||
const CUSTOM_TIMEOUT_LIMIT = 5000
|
||||
const ABSOLUTE_TIMEOUT = 7500
|
||||
|
||||
class StrictTimeLimitEnvironment extends BaseEnvironment {
|
||||
async handleTestEvent(event, state) {
|
||||
if (state.testTimeout > CUSTOM_TIMEOUT_LIMIT) {
|
||||
throw new Error(`Custom timeouts cannot exceed the ${CUSTOM_TIMEOUT_LIMIT}ms limit!`)
|
||||
} else if ((event.test?.duration || 0) > ABSOLUTE_TIMEOUT) {
|
||||
// Jest is supposed to enforce the CUSTOM_TIMEOUT_LIMIT, but it doesn't always for
|
||||
// async tests. The duration value is always accurate so just enforce it here.
|
||||
throw new Error(`Exceeded the absolute ${ABSOLUTE_TIMEOUT}ms runtime limit for this spec!`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StrictTimeLimitEnvironment;
|
|
@ -31,7 +31,7 @@ module.exports = {
|
|||
],
|
||||
setupFiles: ['jest-canvas-mock', '<rootDir>/jest/jest-setup.js'],
|
||||
setupFilesAfterEnv: ['@testing-library/jest-dom/extend-expect'],
|
||||
testEnvironment: 'jsdom',
|
||||
testEnvironment: '<rootDir>../../jest/strictTimeLimitEnvironment.js',
|
||||
testMatch: ['**/__tests__/**/?(*.)(spec|test).js'],
|
||||
testPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/lib', '<rootDir>/es'],
|
||||
transform: {
|
||||
|
|
|
@ -48,5 +48,5 @@ module.exports = {
|
|||
statements: 80
|
||||
}
|
||||
},
|
||||
testEnvironment: 'jsdom'
|
||||
testEnvironment: '<rootDir>../../jest/strictTimeLimitEnvironment.js'
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ module.exports = {
|
|||
testPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/lib', '<rootDir>/canvas'],
|
||||
testMatch: ['**/__tests__/**/?(*.)(spec|test).js'],
|
||||
modulePathIgnorePatterns: ['<rootDir>/es', '<rootDir>/lib', '<rootDir>/canvas'],
|
||||
testEnvironment: 'jsdom',
|
||||
testEnvironment: '<rootDir>../../jest/strictTimeLimitEnvironment.js',
|
||||
moduleNameMapper: {
|
||||
// jest can't import the icons
|
||||
'@instructure/ui-icons/es/svg': '<rootDir>/src/rce/__tests__/_mockIcons.js',
|
||||
|
|
Loading…
Reference in New Issue