对于单个执行,可以有一个存储执行信息的顶级对象,该对象在
afterAll
方法。
这里是一个虚拟的测试套件,它突出了我的意思。当然,你可以获得创造性和更有组织性,甚至在更高的层次上拥有对象。
然后您可以将它们存储在一个文件中,将结果发送到服务器等。
测试.js
describe('A suite', () => {
let suiteSpecificData = {};
test('a test', () => {
expect(1).toBe(1)
suiteSpecificData["a test"] = "ok"
})
test('another test', () => {
let theOtherTestData = suiteSpecificData["a test"];
let thisTestData = suiteSpecificData["another test"] = {};
if (theOtherTestData === "ok") {
thisTestData.messageOne = "All good with the other test";
thisTestData.someMoreRandomStuff = [1,2,3];
}
})
afterAll(() => {
console.log(JSON.stringify(suiteSpecificData));
});
});