Environment info
- Node.js version: 8.11.1
- nock version: 9.2.5
Code example
The following code example demonstrates that nock.cleanAll() call doesn't remove delayed requests from Node.js event loop:
'use strict';
const nock = require('nock');
const got = require('got');
nock('http://test')
.get('/')
.query(true)
.delay(5000)
.reply(200);
const start = Date.now();
(async () => {
try {
await got('http://test', {timeout: 100});
} catch (err) {
console.error('got error "%s" after %s ms', err.message, Date.now() - start);
nock.cleanAll();
}
})();
process.on('exit', () => {
console.log('exit after %s ms', Date.now() - start);
})
Actual behavior
Node.js process waits while 5 seconds timeout will be reached:
$ node test.js
got error "Request timed out" after 108 ms
exit after 5018 ms
Expected behavior
nock.cleanAll() method removes all request timeouts.
More information
This causes problem with mocha >= 4.0.0, because Mocha will no longer force the process to exit once all tests complete. See https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#default-behavior.
Related issues
Environment info
Code example
The following code example demonstrates that
nock.cleanAll()call doesn't remove delayed requests from Node.js event loop:Actual behavior
Node.js process waits while 5 seconds timeout will be reached:
Expected behavior
nock.cleanAll()method removes all request timeouts.More information
This causes problem with
mocha >= 4.0.0, because Mocha will no longer force the process to exit once all tests complete. See https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#default-behavior.Related issues