Skip to content

Commit a8341af

Browse files
authored
test: wait for async process completion (#539)
`generateConfigs()` function executes a nodejs [exec] that takes many seconds to complete. As the test was not waiting for the process to terminate, Jest was complaining with the following error message: ``` Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ``` Additionally, this test could have a false positive expectation since it was likely to run the snapshot comparison with previously generated plugin configurations. By default Jest tests will timeout if they take longer than 5 seconds to complete, since this test takes more than 10 seconds to complete on my local machine, this test timeout configuration has been increased to 20 seconds. [exec]: https://nodejs.org/api/child_process.html#child_processexeccommand-options-callback
1 parent f31dc61 commit a8341af

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/index.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { exec } from 'child_process';
22
import { existsSync } from 'fs';
33
import { resolve } from 'path';
4+
import util from 'util';
45

56
import plugin from '../lib';
67

7-
const generateConfigs = () => exec(`npm run generate:configs`);
8+
const execAsync = util.promisify(exec);
9+
const generateConfigs = () => execAsync(`npm run generate:configs`);
810

911
const numberOfRules = 26;
1012
const ruleNames = Object.keys(plugin.rules);
@@ -47,11 +49,11 @@ it('should have the correct amount of rules', () => {
4749
});
4850

4951
it("should have run 'generate:configs' script when changing config rules", async () => {
50-
generateConfigs();
52+
await generateConfigs();
5153

5254
const allConfigs = plugin.configs;
5355
expect(allConfigs).toMatchSnapshot();
54-
});
56+
}, 20000);
5557

5658
it('should export configs that refer to actual rules', () => {
5759
const allConfigs = plugin.configs;

0 commit comments

Comments
 (0)