Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ops] Add debug logging to certain jest error cases #175988

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/kbn-test/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ module.exports = {
globals: {
structuredClone: {},
},

testResultsProcessor:
'<rootDir>/packages/kbn-test/src/jest/result_processors/logging_result_processor.js',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

const FAILURE_MESSAGE_TRIGGERS = ['but is not defined anymore'];
const log = (...args) => {
const loggable = args.map((arg) =>
typeof arg === 'string' ? arg : JSON.stringify(arg, null, 2)
);
process.stdout.write(`${loggable.join(' ')}\n`, 'utf8');
};
/**
* This processor looks for specific errors, and logs the result context of test suites where they occur.
* @param results
* @returns {*}
*/
module.exports = (results) => {
const resultsThatMatchTriggers = results.testResults.filter(
(e) =>
e.failureMessage &&
FAILURE_MESSAGE_TRIGGERS.some((trigger) => e.failureMessage.includes(trigger))
);

if (resultsThatMatchTriggers.length !== 0) {
log('The following test suites failed, with notable errors:');
resultsThatMatchTriggers.forEach((e) => {
log(` -> ${e.testFilePath}`, 'Details: ', e, '\n');
});
}

return results;
};