Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
add a unit test
  • Loading branch information
siyuniu-ms committed Mar 6, 2023
1 parent 68af47f commit 8d8c617
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
75 changes: 38 additions & 37 deletions shared/AppInsightsCommon/Tests/Unit/src/Exception.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,44 @@ export class ExceptionTests extends AITestClass {
}
});

// this.testCase({
// name: "ExceptionDetails: ExceptionDetails will be truncated",
// test: () => {
// try {
// // const define
// const MAX_MESSAGE_LENGTH = DataSanitizer.MAX_MESSAGE_LENGTH;
// const messageLong = new Array(MAX_MESSAGE_LENGTH + 10).join('abc');


// let errObj = {
// reason:{
// message: "message",
// stack: messageLong + "\n" + messageLong + "\n" + messageLong
// }
// };

// let exception = Exception.CreateAutoException("message",
// "url",
// 9,
// 0,
// errObj
// );

// const exceptionDetails = new _ExceptionDetails(this.logger, exception);
// const exceptionDetailsInterface: IExceptionDetailsInternal = exceptionDetails.toInterface();

// Assert.ok(exceptionDetailsInterface.stack.length < MAX_MESSAGE_LENGTH)
// // console.log(exceptionDetailsInterface.message)
// // console.log(exceptionDetailsInterface.message.length)

// } catch (e) {
// console.log(e.stack);
// console.log(e.toString());
// Assert.ok(false, e.toString());
// }
// }
// });
this.testCase({
name: "ExceptionDetails: ExceptionDetails assembly field will be truncated",
test: () => {
try {
// const define
const MAX_STRING_LENGTH = DataSanitizer.MAX_STRING_LENGTH;
const messageLong = new Array(MAX_STRING_LENGTH + 10).join("abc");

const messageFollowRegex = "at functionName (a.js:1:1)"
const longMessageFollowRegex = messageFollowRegex.replace("functionName", messageLong)

let errObj = {
reason:{
message: "message",
stack: longMessageFollowRegex + "\n" + longMessageFollowRegex + "\n" + longMessageFollowRegex
}
};

let exception = Exception.CreateAutoException("message",
"url",
9,
0,
errObj
);
const exceptionDetails = new _ExceptionDetails(this.logger, exception);
console.log("exception", exceptionDetails.parsedStack)
console.log(exceptionDetails.parsedStack.length)
for (let i = 0; i < exceptionDetails.parsedStack.length; i++) {
Assert.ok(exceptionDetails.parsedStack[i].assembly.length <= MAX_STRING_LENGTH);
console.log(exceptionDetails.parsedStack[i].assembly.length, MAX_STRING_LENGTH)
}
} catch (e) {
console.log(e.stack);
console.log(e.toString());
Assert.ok(false, e.toString());
}
}
});


this.testCase({
Expand Down
2 changes: 1 addition & 1 deletion shared/AppInsightsCommon/src/Telemetry/Exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export class _ExceptionDetails implements IExceptionDetails, ISerializable {
_self.parsedStack = _parseStack(stack);

// after parsedStack is inited, iterate over each frame object, sanitize its assembly field
if (_self.parsedStack instanceof Array){
if (isArray(_self.parsedStack)){
arrMap(_self.parsedStack, (frame: _StackFrame) => frame.assembly = dataSanitizeString(logger, frame.assembly));
}

Expand Down

0 comments on commit 8d8c617

Please sign in to comment.