玩笑测试中循环中的Javascript行为会有所不同

我有此功能,它具有数组映射和三级嵌套的promise。 Index.js

const promiseA=require('./promiseA')


console.log(' Starting ')
//setInterval(()=>console.log('executed'), 5000)

const sample=async ()=>{
    const newArray=[1,2,3,4,5]
    let result =undefined

    await Promise.all(newArray.map(async()=>{
        result = await promiseA();
        console.log('after calling A')
    }))
    console.log(`final result ${result}`)

    return result;
}
sample();
module.exports=sample

承诺A

const promiseB=require('./promiseB')

const promiseA=async()=>{
    return Promise.resolve(await promiseB())
}

module.exports=promiseA

承诺B

const promiseC=require('./promiseC')


const promiseB=async()=>{
    return Promise.resolve(await promiseC())
}

module.exports=promiseB

承诺C

const promiseC=async()=>{
    return Promise.resolve([1,2,3])
}

module.exports=promiseC

当我执行npm start时,得到以下输出

 Starting 
after calling A
after calling A
after calling A
after calling A
after calling A
final result 1,2,3

输出与预期的相同。

开玩笑。

index.test.js


const sample=require('../src/index')

describe('all tests', ()=>{

    it('should', async()=>{
        const result = await sample()
        expect(result).toBeDefined();
    })
})

当我做npm测试时,我得到以下输出

console.log
     Starting

      at Object.<anonymous> (src/index.js:7:9)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    final result 1,2,3

      at sample (src/index.js:33:13)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    after calling A

      at Promise.all.newArray.map (src/index.js:19:17)

  console.log
    final result 1,2,3

      at sample (src/index.js:33:13)

这是我不明白的事情。输出被打印两次。有人可以帮忙吗?在过去的两天里,我一直陷入类似的问题。