Skip to content

Commit 0f39f3d

Browse files
awadhanazondervancalvez
authored andcommitted
test: jestify runtime-plugin-import test and fix flaky test
Migrated test from Tap to Jest. File Path: packages/cactus-test-cmd-api-server/src/test/typescript/integration/runtime-plugin-imports.test.ts ======================================================================= This is a flaky test case that can't be reliably reproduce. I've ran the test individually 40 times and all 40 times it has passed successfully. This error, however, seems to pop up only when the `yarn jest` command is run (when I ran the test individually). Based on the linked ["hint"](https://stackoverflow.com/a/50793993) from the issue, it seems like using `jest.useFakeTimers()` a good solution. However, using the `jest.useFakeTimers()` with`async/await` was not recommended. However, I found a [different source] (https://gist.github.com/apieceofbart/e6dea8d884d29cf88cdb54ef14ddbcc4#file-test-js-L58) that showed examples of how to use the `jest.useFakeTimers()`. Our original problem, however, is probably because the after the test environment is torn down, the second test file is trying to import files from the first environment, triggering the error ([explained here](jestjs/jest#11438 (comment))). So I've come to the solution of installing another node package: [node-cleanup](https://www.npmjs.com/package/node-cleanup) and running that within the afterAll at the very end of the test. My laptop can't take running the `yarn jest` script too much so I haven't seen it reproduce the error yet. (WOT ruhrow) _______________________edit below _________________________ So it turns out that this flaky test due to libraries trying to third libraries trying to run after the test runs is a simple fix that was documented [here](https://testing-library.com/docs/using-fake-timers/) where we just add the `useRealTimer` in the `afterEach`. Lol so sorry!! ======================================================================= This is a PARTIAL resolution to issue hyperledger-cacti#238 Fixes hyperledger-cacti#1667 Signed-off-by: awadhana <awadhana0825@gmail.com> Signed-off-by: Youngone Lee <youngone.lee@accenture.com> Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
1 parent f7d4e33 commit 0f39f3d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/cactus-test-cmd-api-server/src/test/typescript/integration/runtime-plugin-imports.test.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const logLevel: LogLevelDesc = "TRACE";
1616
const testCase = "can import plugins at runtime (CLI)";
1717
describe(testCase, () => {
1818
let apiServer: ApiServer;
19+
20+
afterEach(() => {
21+
jest.useRealTimers();
22+
});
23+
1924
test(testCase, async () => {
2025
const pluginsPath = path.join(
2126
__dirname, // start at the current file's path
@@ -67,5 +72,7 @@ describe(testCase, () => {
6772
];
6873
await expect(apiServer.start()).not.toReject();
6974
});
70-
afterAll(async () => await apiServer.shutdown());
75+
afterAll(async () => {
76+
await apiServer.shutdown();
77+
});
7178
});

0 commit comments

Comments
 (0)