Repository navigation
test: cover deprecation warnings for res.redirect - #7571
saiyam-jain-dev wants to merge 1 commit into
Conversation
yxshee
left a comment
There was a problem hiding this comment.
Ran this branch: 1293 passing (master is 1290), and the three new tests pass on their own as well.
One suggestion for the third test: res.redirect('301', url) throws in 5.x (TypeError: Invalid status code: "301". Status code must be an integer. from res.status), and the empty catch swallows it. As written, the test would still pass if redirect started throwing something else, or stopped throwing and redirected with a string status. Asserting the error explicitly would pin both halves of the behavior:
app.use(function (req, res) {
assert.throws(function () {
res.redirect('301', 'http://google.com')
}, TypeError)
res.end()
})Also a small point: depd reports each deprecation once per call site, so these tests stay reliable as long as each res.redirect(...) call keeps its own line. A one-line comment saying so would stop someone from refactoring them into a shared helper and breaking the assertions.
Signed-off-by: Saiyam Jain <jimisierra2@gmail.com>
0176cea to
e3f5eed
Compare
|
Please don’t open PRs to address that deprecation. |
|
Hi @bjohansebas, thanks for the note! Just to clarify, this PR was not attempting to change or resolve the deprecation behavior; it was only adding test coverage for the existing warning emissions. Completely understand if tests for temporary deprecations are not needed right now though. Thanks for your time! |
Add regression test coverage in
test/res.redirect.jsfor the deprecation warnings emitted byres.redirect()when called with missing or invalid arguments:Provide a url argumentandUrl must be a stringUrl must be a stringStatus must be a numberThe tests attach a listener to
process.on('deprecation', ...)to verify thatdepdemits the expected warning messages and clean up the listener in the completion callback.All 1,293 tests pass (
npm test), line coverage acrosslib/response.jsis 100%, andnpm run lintpasses with zero errors.