Skip to content

Commit

Permalink
Merge pull request #1031 from gemini-testing/TESTPLANE-347.snippet_wa…
Browse files Browse the repository at this point in the history
…rning

fix: remove extra warning on code snippet extend error
  • Loading branch information
KuznetsovRoman authored Nov 20, 2024
2 parents 89673f3 + 714434a commit 0ff58f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/error-snippets/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { findRelevantStackFrame, resolveLocationWithStackFrame } from "./frames";
import { extractSourceMaps, resolveLocationWithSourceMap } from "./source-maps";
import { getSourceCodeFile, formatErrorSnippet, shouldNotAddCodeSnippet } from "./utils";
import logger from "../utils/logger";
import type { ResolvedFrame, SufficientStackFrame, WithSnippetError } from "./types";

const stackFrameLocationResolver = async (stackFrame: SufficientStackFrame): Promise<ResolvedFrame> => {
Expand Down Expand Up @@ -31,8 +30,6 @@ export const extendWithCodeSnippet = async (err: WithSnippetError): Promise<With

return err;
} catch (snippetError) {
logger.warn("Unable to apply code snippet:", snippetError);

return err;
}
};
14 changes: 2 additions & 12 deletions test/src/error-snippets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ describe("error-snippets", () => {
let fetchStub: SinonStub;
let formatErrorSnippetStub: SinonStub;
let findRelevantStackFrameStub: SinonStub;
let loggerStub: { warn: SinonStub };

beforeEach(() => {
fsReadFileStub = sandbox.stub(fs, "readFile");
fetchStub = sandbox.stub(globalThis, "fetch");

formatErrorSnippetStub = sandbox.stub();
findRelevantStackFrameStub = sandbox.stub();
loggerStub = { warn: sandbox.stub() };

extendWithCodeSnippet = proxyquire("../../../src/error-snippets", {
"./utils": { formatErrorSnippet: formatErrorSnippetStub },
"./frames": { findRelevantStackFrame: findRelevantStackFrameStub },
"../utils/logger": loggerStub,
}).extendWithCodeSnippet;
});

Expand All @@ -63,8 +60,6 @@ describe("error-snippets", () => {
await assert.eventually.isUndefined(extendWithCodeSnippet());
await assert.eventually.isNull(extendWithCodeSnippet(null));
await assert.eventually.equal(extendWithCodeSnippet(""), "");

assert.notCalled(loggerStub.warn);
});

it("should not modify error, if could not find relevant stack frame", async () => {
Expand All @@ -74,7 +69,6 @@ describe("error-snippets", () => {

await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.strictEqual(error, savedError);
});

Expand All @@ -89,7 +83,6 @@ describe("error-snippets", () => {

assert.strictEqual(error, savedError);
assert.strictEqual(error, result);
assert.calledOnceWith(loggerStub.warn, "Unable to apply code snippet:");
});

it("should return the same Object.is object", async () => {
Expand All @@ -101,7 +94,6 @@ describe("error-snippets", () => {

const result = await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.equal(error, result);
});

Expand All @@ -114,7 +106,6 @@ describe("error-snippets", () => {

const result = await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.equal(result.snippet, "code snippet");
});

Expand All @@ -130,7 +121,6 @@ describe("error-snippets", () => {

const result = await extendWithCodeSnippet(error);

assert.notCalled(loggerStub.warn);
assert.equal(result.snippet, "code snippet");
});

Expand All @@ -141,9 +131,9 @@ describe("error-snippets", () => {
fsReadFileStub.returns("source code");
formatErrorSnippetStub.throws(new Error());

await extendWithCodeSnippet(error);
const returnedError = await extendWithCodeSnippet(error);

assert.calledOnceWith(loggerStub.warn, "Unable to apply code snippet:");
assert.strictEqual(error, returnedError);
});
});
});

0 comments on commit 0ff58f9

Please sign in to comment.