feat: updates

This commit is contained in:
lohxt1 2024-10-25 15:12:39 +05:30
parent 23531ec7af
commit a6b54d8d9c
2 changed files with 34 additions and 7 deletions

View File

@ -114,10 +114,21 @@ class TestRuntime {
}
if (this.runtime === 'quickjs') {
await executeQuickJsVmAsync({
script: testsFile,
context: context
});
try {
await executeQuickJsVmAsync({
script: testsFile,
context: context
});
}
catch(error) {
__brunoTestResults.addResult({
description: 'Invalid test script',
status: 'fail',
error: [
`${error.message || 'An unexpected error occurred.'}`
]
});
}
} else {
// default runtime is vm2
const vm = new NodeVM({
@ -156,7 +167,23 @@ class TestRuntime {
}
});
const asyncVM = vm.run(`module.exports = async () => { ${testsFile}}`, path.join(collectionPath, 'vm.js'));
await asyncVM();
try {
await asyncVM();
}
catch(error) {
const errorStackLines = error?.stack?.split?.("\n");
const lineInfo = errorStackLines?.[1];
const lineNumber = lineInfo?.split(':')?.at?.(-2);
const columnNumber = lineInfo?.split(':')?.at?.(-1);
__brunoTestResults.addResult({
description: 'Invalid test script',
status: 'fail',
error: [
`Error occurred at line ${lineNumber} and character ${columnNumber}`,
`${error.message || 'An unexpected error occurred.'}`
]
});
}
}
return {

View File

@ -13,8 +13,8 @@ const Test = (__brunoTestResults, chai) => async (description, callback) => {
expected
});
} else {
const errorStackLines = error.stack.split("\n");
const lineInfo = errorStackLines[1];
const errorStackLines = error?.stack?.split?.("\n");
const lineInfo = errorStackLines?.[1];
const lineNumber = lineInfo?.split(':')?.at?.(-2);
const columnNumber = lineInfo?.split(':')?.at?.(-1);
__brunoTestResults.addResult({