question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async keyword causes test to be seen as single promise => timeout too short

See original GitHub issue

Description

When using Node 8, transpiling all, and babel-preset-env with node:true as target, some of my longer tests time out via finishDueToInactivity. This doesn’t happen when the async is transpiled by babel. I assume that the async creates a single promise where the transpiled version splits in many?

If so, I propose that the timeout gets reset every time one of the test functions gets called?

Test Source

test('long test with many steps', async t => {
    t.snapshot(await slowThing1(), 'after 1')
    t.snapshot(await slowThing2(), 'after 2')
// ... Sometime here it will say "Promise returned by test never resolved"
    t.snapshot(await slowThing8(), 'after 8')
})

Error Message & Stack Trace

 Promise returned by test never resolved

  Test.finishDueToInactivity (node_modules/ava/lib/test.js:377:7)
  onBeforeExit (node_modules/ava/lib/sequence.js:43:20)
  process.beforeExitHandler (node_modules/ava/lib/sequence.js:6:3)
  processEmit [as emit] (node_modules/sqlite3/node_modules/node-pre-gyp/node_modules/npmlog/node_modules/gauge/node_modules/signal-exit/index.js:146:32)

Config

Copy the relevant section from package.json:

{
  "ava": {
    "files": [
      "{src,lib}/**/{__tests__/*,*.test}.js{,x}"
    ],
    "babel": "inherit",
    "concurrency": 5,
    "require": [
      "babel-register",
      "babel-polyfill"
    ]
  }
}

Command-Line Arguments

Copy your npm build scripts or the ava command used:

ava --watch

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:

Node.js v8.4.0
darwin 16.5.0
0.22.0
5.3.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
novemberborncommented, Dec 28, 2017

@Smilebags could you share your example?

0reactions
Smilebagscommented, Dec 28, 2017

I am also experiencing this issue with a rather simple example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest: Timer and Promise don't work well. (setTimeout and ...
Fortunately it is actually quite easy to let all pending jobs in PromiseJobs run within an async test, all you need to do...
Read more >
async function - JavaScript - MDN Web Docs - Mozilla
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await ...
Read more >
Testing-library: avoid these mistakes in async tests
In our test, when we are calling render with await , JavaScript implicitly wraps the result into a promise and waits for it...
Read more >
Async Methods - Testing Library
The async methods return Promises, so be sure to use await or .then when ... hopefully make it easier to track down what...
Read more >
How to use React Testing library to wait for async elements, a ...
JavaScript is a single-threaded and asynchronous language which is a ... in an async way using Promises and the newer async/await syntax.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found