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:
+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.
|
||||
*/
|
||||
|
||||
import { env } from "process";
|
||||
import "@testing-library/jest-dom";
|
||||
import "blob-polyfill";
|
||||
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
||||
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 {
|
||||
// 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
|
||||
// a specific order. We use this order to ensure we properly
|
||||
// establish an application state that actually works.
|
||||
|
||||
Reference in New Issue
Block a user