Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/browser-pool/basic-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export class BasicPool implements Pool {
});
}

cancel(): void {
cancel(err?: Error): void {
this._cancelled = true;

_.forEach(this._activeSessions, browser => browser.quit());
_.forEach(this._activeSessions, browser => browser.quit(err));

this._activeSessions = {};
}
Expand Down
4 changes: 2 additions & 2 deletions src/browser-pool/caching-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export class CachingPool implements Pool {
return cache.push(browser);
}

cancel(): void {
cancel(err?: Error): void {
this.log("cancel");
this.underlyingPool.cancel();
this.underlyingPool.cancel(err);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export class NoRefImageError extends BaseStateError {
super(stateName, currImg, refImg);

this.message = `can not find reference image at ${this.refImg.path} for "${stateName}" state`;
this.stack = undefined;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove stack for no ref image error

}
}
3 changes: 2 additions & 1 deletion src/runner/test-runner/regular-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const crypto = require("crypto");
const _ = require("lodash");
const { RunnableEmitter } = require("../types");
const logger = require("../../utils/logger");
const { formatError } = require("../../utils/format-error");
const { MasterEvents } = require("../../events");
const AssertViewResults = require("../../browser/commands/assert-view/assert-view-results");
const RuntimeConfig = require("../../config/runtime-config");
Expand Down Expand Up @@ -85,7 +86,7 @@ module.exports = class RegularTestRunner extends RunnableEmitter {

this._emit(MasterEvents.TEST_PASS);
} catch (error) {
this._test.err = this._browser?.exitError || error;
this._test.err = formatError(this._browser?.exitError || error);

this._applyTestResults(this._test.err);

Expand Down
2 changes: 2 additions & 0 deletions src/testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ export class Testplane extends BaseTestplane {
message: this._profiler.sanitizeMessage(err?.message ?? "Testplane run was aborted"),
});

signalHandler.emit(MasterEvents.EXIT, err);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this one needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need for send event to reporter


if (timeout > 0) {
setTimeout(() => {
logger.error("Forcing shutdown...");
Expand Down
15 changes: 15 additions & 0 deletions src/utils/format-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const formatError = (err: Error): Error => {
const TRIM_MARKERS = ["Tests were stopped by the user"];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove stack for some errors, now only for force stop


if (!TRIM_MARKERS.some(marker => err.stack?.includes(marker))) {
return err;
}

const newErr = new Error(err.message);

if (err.stack) {
newErr.stack = err.stack.split("\n")[0];
}

return newErr;
};
54 changes: 54 additions & 0 deletions test/src/utils/format-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { formatError } from "../../../src/utils/format-error";

describe("utils/format-error", () => {
describe("when stack does not contain trigger string", () => {
it("should return the same error instance", () => {
const err = new Error("some error");
err.stack = "Error: some error\n at foo (foo.js:1:1)\n at bar (bar.js:2:2)";

const result = formatError(err);

assert.strictEqual(result, err);
});
});

describe("when stack contains 'Tests were stopped by the user'", () => {
it("should return a new Error instance", () => {
const err = new Error("Tests were stopped by the user");
err.stack = "Error: Tests were stopped by the user\n at foo (foo.js:1:1)";

const result = formatError(err);

assert.notStrictEqual(result, err);
});

it("should preserve original error message", () => {
const err = new Error("Tests were stopped by the user");
err.stack = "Error: Tests were stopped by the user\n at foo (foo.js:1:1)";

const result = formatError(err);

assert.equal(result.message, err.message);
});

it("should trim stack to first line only", () => {
const err = new Error("Tests were stopped by the user");
err.stack = "Error: Tests were stopped by the user\n at foo (foo.js:1:1)\n at bar (bar.js:2:2)";

const result = formatError(err);

assert.equal(result.stack, "Error: Tests were stopped by the user");
});
});

describe("when stack is undefined", () => {
it("should return the same error instance", () => {
const err = new Error("some error");
err.stack = undefined;

const result = formatError(err);

assert.strictEqual(result, err);
});
});
});
Loading