Files
bruno/packages/bruno-js/src/test.js
gopu-bruno 910581a627 feat: improve stack traces for script and test failures (#7181)
* chore: update package-lock.json to include yaml dependency

* feat: add script-aware stack traces and source context for script/test failures

* chore: sync package-lock.json with yaml dependency in bruno-js

* fix: handle null check in getErrorTypeName and align JSDoc style

* refactor: derive script path from request.pathname and use SCRIPT_TYPES constant

* fix: avoid showing source context for collection/folder script errors

* feat: map collection/folder script errors to source file and line

* fix: update error formatting and avoid undefined message

* fix: resolve script block location in collection/folder yml files

* refactor: use script wrapper utils and rename wrapper offsets

* refactor: move script wrapper to utils, add wrapScriptInClosure fn
2026-03-02 15:27:18 +05:30

30 lines
814 B
JavaScript

const Test = (__brunoTestResults, chai) => async (description, callback) => {
try {
await callback();
__brunoTestResults.addResult({ description, status: 'pass' });
} catch (error) {
if (error instanceof chai.AssertionError) {
const { message, actual, expected } = error;
__brunoTestResults.addResult({
description,
status: 'fail',
error: message,
actual,
expected,
stack: error.stack || null,
errorName: error.name || 'AssertionError'
});
} else {
__brunoTestResults.addResult({
description,
status: 'fail',
error: error.message || 'An unexpected error occurred.',
stack: error.stack || null,
errorName: error.name || 'Error'
});
}
}
};
module.exports = Test;