Jez Nicholson (14) [Avatar] Offline
#1
In CodeBuild, if one of the tests fails then it reports an ugly "Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.". The promise doesn't resolve because the assert throws an error.

Am currently reading https://wietse.loves.engineering/testing-promises-with-mocha-90df8b7d2e35 about it. I'm just getting my head round doing a 'co'-friendly version but am a bit slow. What do you think for:

    it(`Should succeed`, co.wrap(function*() {
      let res = yield when.we_get_player(user)
      expect(res.statusCode).to.equal(200)
    }))


?
Yan Cui (65) [Avatar] Offline
#2
Jez Nicholson (14) [Avatar] Offline
#3
I might not have explained right....my code above is modelled on that test, yes, but when it failed in CodePipeline (because I had recreated a DynamoDB table and there was no data) I got a timeout error rather than a proper message about what went wrong. I believe that when an expect() fails that it leaves the promise hanging until it times out. Not 100% certain, but pretty much.
Yan Cui (65) [Avatar] Offline
#4
Ah I see, I misunderstood you! Let me take a look at it and see if there's an easy way around it, would like to keep co as it makes everything easier to read but if it hides errors then that's no good for our tests.
Yan Cui (65) [Avatar] Offline
#5
According to this SO answer the right way to use co with mocha is to include `.then(done, done)` to the co-wrapped Promise.

I'll look around so more to see if there's a more elegant way to do this.