Skip to content

Commit

Permalink
test: wait for async process completion (#539)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
bpinto authored Jan 25, 2022
1 parent f31dc61 commit a8341af
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { exec } from 'child_process';
import { existsSync } from 'fs';
import { resolve } from 'path';
import util from 'util';

import plugin from '../lib';

const generateConfigs = () => exec(`npm run generate:configs`);
const execAsync = util.promisify(exec);
const generateConfigs = () => execAsync(`npm run generate:configs`);

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

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

const allConfigs = plugin.configs;
expect(allConfigs).toMatchSnapshot();
});
}, 20000);

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

0 comments on commit a8341af

Please sign in to comment.