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
@@ -27,6 +27,7 @@ describe("BugReportDialog", () => {
|
||||
return render(<BugReportDialog onFinished={onFinished} />);
|
||||
}
|
||||
|
||||
let prevLogger: ConsoleLogger;
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
SdkConfig.put({
|
||||
@@ -48,24 +49,14 @@ describe("BugReportDialog", () => {
|
||||
consume: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
} 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;
|
||||
|
||||
// @ts-ignore
|
||||
mockConsoleLogger.flush.mockReturnValue([
|
||||
{
|
||||
id: "instance-0",
|
||||
line: "line 1",
|
||||
},
|
||||
{
|
||||
id: "instance-1",
|
||||
line: "line 2",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.mx_rage_logger = prevLogger;
|
||||
jest.restoreAllMocks();
|
||||
SdkConfig.reset();
|
||||
fetchMock.restore();
|
||||
|
||||
@@ -524,25 +524,16 @@ describe("Rageshakes", () => {
|
||||
consume: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
} 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;
|
||||
|
||||
// @ts-ignore
|
||||
mockConsoleLogger.flush.mockReturnValue([
|
||||
{
|
||||
id: "instance-0",
|
||||
line: "line 1",
|
||||
},
|
||||
{
|
||||
id: "instance-1",
|
||||
line: "line 2",
|
||||
},
|
||||
]);
|
||||
|
||||
const formData = await collectBugReport({ sendLogs: true });
|
||||
|
||||
expect(formData.get("compressed-log")).toBeDefined();
|
||||
try {
|
||||
const formData = await collectBugReport({ sendLogs: true });
|
||||
expect(formData.get("compressed-log")).toBeDefined();
|
||||
} finally {
|
||||
global.mx_rage_logger = prevLogger;
|
||||
}
|
||||
});
|
||||
|
||||
describe("A-Element-R label", () => {
|
||||
|
||||
Reference in New Issue
Block a user