Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9aac82d

Browse files
jaggederestclaude
andcommitted
test: add Logger integration tests for error.ts
- Add tests verifying CertificateError logs parsing errors through Logger- Test certificate parsing failure logs error message with details- Verify compatibility with Storage's Logger interface- Use createMockOutputChannelWithLogger factory for consistent test setup- No code changes needed in error.ts - already compatible via Logger interface🤖 Generated with [Claude Code](https://claude.ai/code)Co-Authored-By: Claude <noreply@anthropic.com>
1 parent3595bda commit9aac82d

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

‎src/error.test.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,92 @@ describe("CertificateError instance methods", () => {
615615
expect(allowInsecureSpy).toHaveBeenCalled();
616616
});
617617
});
618+
619+
describe("Logger integration",()=>{
620+
it("should log certificate parsing errors through Logger",async()=>{
621+
const{logger:realLogger}=createMockOutputChannelWithLogger();
622+
623+
// Create a logger that uses the real Logger
624+
constloggerWrapper={
625+
writeToCoderOutputChannel:(msg:string)=>{
626+
realLogger.info(msg);
627+
},
628+
};
629+
630+
// Create an axios error that will trigger certificate parsing
631+
constaxiosError={
632+
isAxiosError:true,
633+
code:X509_ERR_CODE.UNABLE_TO_VERIFY_LEAF_SIGNATURE,
634+
message:"unable to verify the first certificate",
635+
};
636+
637+
// Mock CertificateError.determineVerifyErrorCause to throw an error
638+
constdetermineVerifyErrorCauseSpy=vi
639+
.spyOn(CertificateError,"determineVerifyErrorCause")
640+
.mockRejectedValue(newError("Failed to parse certificate"));
641+
642+
// Call maybeWrap which should log the parsing error
643+
constresult=awaitCertificateError.maybeWrap(
644+
axiosError,
645+
"https://test.com",
646+
loggerWrapper,
647+
);
648+
649+
// Verify the error was logged
650+
constlogs=realLogger.getLogs();
651+
expect(logs.length).toBe(1);
652+
expect(logs[0].message).toBe(
653+
"Failed to parse certificate from https://test.com: Error: Failed to parse certificate",
654+
);
655+
expect(logs[0].level).toBe("INFO");
656+
657+
// Verify the original error was returned (not wrapped)
658+
expect(result).toBe(axiosError);
659+
660+
// Restore the spy
661+
determineVerifyErrorCauseSpy.mockRestore();
662+
});
663+
664+
it("should work with Storage instance that has Logger set",async()=>{
665+
const{logger:realLogger}=createMockOutputChannelWithLogger();
666+
667+
// Simulate Storage with Logger
668+
constmockStorage={
669+
writeToCoderOutputChannel:(msg:string)=>{
670+
realLogger.info(msg);
671+
},
672+
};
673+
674+
// Create an axios error that will trigger certificate parsing
675+
constaxiosError={
676+
isAxiosError:true,
677+
code:X509_ERR_CODE.UNABLE_TO_VERIFY_LEAF_SIGNATURE,
678+
message:"unable to verify the first certificate",
679+
};
680+
681+
// Mock determineVerifyErrorCause to throw
682+
constdetermineVerifyErrorCauseSpy=vi
683+
.spyOn(CertificateError,"determineVerifyErrorCause")
684+
.mockRejectedValue(newError("Certificate parsing failed"));
685+
686+
// Call maybeWrap with the mockStorage
687+
awaitCertificateError.maybeWrap(
688+
axiosError,
689+
"https://example.com:8443",
690+
mockStorage,
691+
);
692+
693+
// Verify error was logged through Logger
694+
constlogs=realLogger.getLogs();
695+
expect(logs.length).toBeGreaterThan(0);
696+
consthasExpectedLog=logs.some((log)=>
697+
log.message.includes(
698+
"Failed to parse certificate from https://example.com:8443",
699+
),
700+
);
701+
expect(hasExpectedLog).toBe(true);
702+
703+
// Restore the spy
704+
determineVerifyErrorCauseSpy.mockRestore();
705+
});
706+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp