【发布时间】:2021-12-19 18:10:19
【问题描述】:
在我的包含 Puppeteer UI 测试的 Typescript 存储库中,我有一个最近更新为导出异步对象的 jest.config.ts 文件,因为我们必须进行 api 调用来获取需要放入测试报告中的信息,使用开玩笑的reporters 属性
注意到由于这是一个异步导出,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,
};
}) : {}
],
}
]
],
};
};
【问题讨论】:
标签: typescript jestjs ts-jest jest-puppeteer