![](/img/trans.png)
[英]Jest ecountered transfomer error after jest.config.ts was moved to a different folder
[英]Jest calls async jest.config.ts twice
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
注意到由於這是一個異步導出,jest 開始執行 jest.config.ts 兩次。 因此,api 調用次數比必要次數多兩次。 當它不是異步時,這不會發生。
這可能是一個錯誤或我缺少的東西嗎? 我的瘋狂猜測是 jest.config.ts 第一次執行全局配置,第二次執行項目配置,但這僅在其異步時發生。
這是我的 jest.config.ts 文件:
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,
};
}) : {}
],
}
]
],
};
};
我遇到了同樣的問題並遇到了你的帖子。 我能夠解決它,因此它不會通過直接調用 function 來調用 function 兩次,如下所示:
export default (async (): Promise<Config.InitialOptions> => {
//something here
})();
這為我解決了它,希望它對你有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.