In my Typescript repository containing Puppeteer UI tests, i have a jest.config.ts file that was recently updated to export an async object because we had to make api calls to fetch information that needs to be put in a test report using jest's reporters
property
Noticed that since this was made an async export, jest started executing jest.config.ts twice. Due to this the api calls are made twice than what is necessary. This did not happen when it was not async.
Could this be a bug or something that i am missing? My wild guess is that jest.config.ts is executed the first time for global config and second time for project config but this happens only when its async.
Here is my jest.config.ts file:
import type { Config } from '@jest/types';
import BitBucketAPI from './BitBucketAPI';
export default async (): Promise<Config.InitialOptions> => {
return {
verbose: true,
bail: false,
maxWorkers: 4,
forceExit: true,
preset: 'ts-jest',
testEnvironment: 'node',
testSequencer: './test-sequencer.ts',
testRegex: '((\\.|/)(spec))\\.(ts)$',
reporters: [
'default',
[
'jest-html-reporters',
{
publicPath: './test-reports',
filename: 'main.html',
pageTitle: 'Test Report',
customInfos: [
{
title: 'Environment URL',
value: 'Test',
},
await new BitBucketAPI().retrieveCommitInformation().then(commitInformation => {
return {
title: 'BitBucket data',
value: commitInformation,
};
}) : {}
],
}
]
],
};
};
I ran into the same problem and ran into your post. I was able to solve it so it won't call the function twice by calling the function directly as following:
export default (async (): Promise<Config.InitialOptions> => {
//something here
})();
This solved it for me, hope it helps you!