* Defer invoking superagent's `.end()` until * the server is listening. * * @param {?Function} fn * @api public
(fn)
| 131 | * @api public |
| 132 | */ |
| 133 | end(fn) { |
| 134 | const server = this._server; |
| 135 | |
| 136 | super.end((err, res) => { |
| 137 | const localAssert = () => { |
| 138 | this.assert(err, res, fn); |
| 139 | }; |
| 140 | |
| 141 | if (server && server._handle) { |
| 142 | // Handle server closing with error handling for already closed servers |
| 143 | return server.close((closeError) => { |
| 144 | // Ignore ERR_SERVER_NOT_RUNNING errors as the server is already closed |
| 145 | if (closeError && closeError.code === 'ERR_SERVER_NOT_RUNNING') { |
| 146 | return localAssert(); |
| 147 | } |
| 148 | // For other errors, pass them through |
| 149 | if (closeError) { |
| 150 | return localAssert(); |
| 151 | } |
| 152 | localAssert(); |
| 153 | }); |
| 154 | } |
| 155 | |
| 156 | localAssert(); |
| 157 | }); |
| 158 | |
| 159 | return this; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Perform assertions and invoke `fn(err, res)`. |
no outgoing calls
no test coverage detected