mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-06 22:48:21 +00:00
Work around jest bug that swallows console output (#30405)
* Work around jest bug that swallows console output Hacky workaround for https://github.com/jestjs/jest/issues/15747 * Fix unit test * Only write logs if there are some to write * Another test fix
This commit is contained in:
committed by
GitHub
parent
fc04ad26ce
commit
d384a9b71b
+20
-1
@@ -6,12 +6,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { env } from "process";
|
||||||
import "@testing-library/jest-dom";
|
import "@testing-library/jest-dom";
|
||||||
import "blob-polyfill";
|
import "blob-polyfill";
|
||||||
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
|
|
||||||
import { PredictableRandom } from "./test-utils/predictableRandom"; // https://github.com/jsdom/jsdom/issues/2555
|
import { PredictableRandom } from "./test-utils/predictableRandom";
|
||||||
|
import * as rageshake from "../src/rageshake/rageshake";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// eslint-disable-next-line no-var
|
// eslint-disable-next-line no-var
|
||||||
@@ -37,6 +39,23 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Somewhat hacky workaround for https://github.com/jestjs/jest/issues/15747: if the GHA reporter is enabled,
|
||||||
|
// capture logs using the rageshake infrastructure, then dump them out after the test.
|
||||||
|
if (env["GITHUB_ACTIONS"] !== undefined) {
|
||||||
|
beforeEach(async () => {
|
||||||
|
await rageshake.init(/* setUpPersistence = */ false);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const logs = global.mx_rage_logger.flush(/* keeplogs = */ false);
|
||||||
|
if (logs) {
|
||||||
|
process.stderr.write(`::group::Console logs from test '${expect.getState().currentTestName}'\n\n`);
|
||||||
|
process.stderr.write(logs);
|
||||||
|
process.stderr.write("::endgroup::\n");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Very carefully enable the mocks for everything else in
|
// Very carefully enable the mocks for everything else in
|
||||||
// a specific order. We use this order to ensure we properly
|
// a specific order. We use this order to ensure we properly
|
||||||
// establish an application state that actually works.
|
// establish an application state that actually works.
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ describe("BugReportDialog", () => {
|
|||||||
return render(<BugReportDialog onFinished={onFinished} />);
|
return render(<BugReportDialog onFinished={onFinished} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let prevLogger: ConsoleLogger;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
SdkConfig.put({
|
SdkConfig.put({
|
||||||
@@ -48,24 +49,14 @@ describe("BugReportDialog", () => {
|
|||||||
consume: jest.fn(),
|
consume: jest.fn(),
|
||||||
warn: jest.fn(),
|
warn: jest.fn(),
|
||||||
} as unknown as Mocked<ConsoleLogger>;
|
} as unknown as Mocked<ConsoleLogger>;
|
||||||
|
mockConsoleLogger.flush.mockReturnValue("line 1\nline 2\n");
|
||||||
|
|
||||||
// @ts-ignore - mock the console logger
|
prevLogger = global.mx_rage_logger;
|
||||||
global.mx_rage_logger = mockConsoleLogger;
|
global.mx_rage_logger = mockConsoleLogger;
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
mockConsoleLogger.flush.mockReturnValue([
|
|
||||||
{
|
|
||||||
id: "instance-0",
|
|
||||||
line: "line 1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "instance-1",
|
|
||||||
line: "line 2",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
global.mx_rage_logger = prevLogger;
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
SdkConfig.reset();
|
SdkConfig.reset();
|
||||||
fetchMock.restore();
|
fetchMock.restore();
|
||||||
|
|||||||
@@ -524,25 +524,16 @@ describe("Rageshakes", () => {
|
|||||||
consume: jest.fn(),
|
consume: jest.fn(),
|
||||||
warn: jest.fn(),
|
warn: jest.fn(),
|
||||||
} as unknown as Mocked<ConsoleLogger>;
|
} as unknown as Mocked<ConsoleLogger>;
|
||||||
|
mockConsoleLogger.flush.mockReturnValue("line 1\nline 2\n");
|
||||||
|
|
||||||
// @ts-ignore - mock the console logger
|
const prevLogger = global.mx_rage_logger;
|
||||||
global.mx_rage_logger = mockConsoleLogger;
|
global.mx_rage_logger = mockConsoleLogger;
|
||||||
|
try {
|
||||||
// @ts-ignore
|
const formData = await collectBugReport({ sendLogs: true });
|
||||||
mockConsoleLogger.flush.mockReturnValue([
|
expect(formData.get("compressed-log")).toBeDefined();
|
||||||
{
|
} finally {
|
||||||
id: "instance-0",
|
global.mx_rage_logger = prevLogger;
|
||||||
line: "line 1",
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "instance-1",
|
|
||||||
line: "line 2",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const formData = await collectBugReport({ sendLogs: true });
|
|
||||||
|
|
||||||
expect(formData.get("compressed-log")).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("A-Element-R label", () => {
|
describe("A-Element-R label", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user