From eeaf6bc72f3a2fcb9aac0c5e6ba7088d435a2811 Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Thu, 13 Mar 2025 13:25:46 +0530 Subject: [PATCH 1/4] increased code coverage of utils.js file --- test/utils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/utils.js b/test/utils.js index d1142266ac4..b11b26680bd 100644 --- a/test/utils.js +++ b/test/utils.js @@ -25,6 +25,18 @@ describe('utils.etag(body, encoding)', function(){ }) }) +describe('utils.normalizeType acceptParams method', () => { + it('should handle a type with a malformed parameter and break the loop in acceptParams', () => { + const result = utils.normalizeType('text/plain;invalid'); + assert.deepEqual(result,{ + value: 'text/plain', + quality: 1, + params: {} // No parameters are added since "invalid" has no "=" + }); + }); +}); + + describe('utils.setCharset(type, charset)', function () { it('should do anything without type', function () { assert.strictEqual(utils.setCharset(), undefined); From 576ce52bdadff92a8486f401abb63923d1329130 Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Sun, 15 Mar 2026 16:01:14 +0530 Subject: [PATCH 2/4] added new test cases for covering uncovered lines of response.js file --- test/app.response.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/app.response.js b/test/app.response.js index 5fb69f6275a..42696f520cb 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -139,5 +139,45 @@ describe('app', function(){ .get('/sub/foo') .expect(200, 'FOO', cb) }) + + it('should deprecate when redirect called without a url', function (done) { + var app = express() + + app.use(function (req, res) { + res.redirect('') + }) + + request(app) + .get('/') + .expect(302) + .expect('Location', '') + .expect(/Redirecting to/, done) + }) + + it('should deprecate when redirect address is not a string', function (done) { + var app = express() + + app.use(function (req, res) { + res.redirect(302, 123) + }) + + request(app) + .get('/') + .expect(302) + .expect('Location', '123') + .expect(/Redirecting to 123/, done) + }) + + it('should raise when redirect status is not a number', function (done) { + var app = express() + + app.use(function (req, res) { + res.redirect('foo', '/bar') + }) + + request(app) + .get('/') + .expect(500, /Invalid status code/, done) + }) }) }) From daaa05dbb97c86d683bef2318bc4000f2d64453e Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Sun, 15 Mar 2026 18:00:00 +0530 Subject: [PATCH 3/4] Update feedback reviewed --- test/app.response.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/test/app.response.js b/test/app.response.js index 42696f520cb..262a28c9ff3 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -142,6 +142,14 @@ describe('app', function(){ it('should deprecate when redirect called without a url', function (done) { var app = express() + var warnings = [] + + // Capture deprecation warnings + process.on('warning', function (warning) { + if (warning.name === 'DeprecationWarning') { + warnings.push(warning.message) + } + }) app.use(function (req, res) { res.redirect('') @@ -151,11 +159,22 @@ describe('app', function(){ .get('/') .expect(302) .expect('Location', '') - .expect(/Redirecting to/, done) + .expect(/Redirecting to/, function () { + assert(warnings.some(msg => msg.includes('res.redirect(url): Use res.redirect(status, url) instead'))) + done() + }) }) it('should deprecate when redirect address is not a string', function (done) { var app = express() + var warnings = [] + + // Capture deprecation warnings + process.on('warning', function (warning) { + if (warning.name === 'DeprecationWarning') { + warnings.push(warning.message) + } + }) app.use(function (req, res) { res.redirect(302, 123) @@ -165,7 +184,10 @@ describe('app', function(){ .get('/') .expect(302) .expect('Location', '123') - .expect(/Redirecting to 123/, done) + .expect(/Redirecting to 123/, function () { + assert(warnings.some(msg => msg.includes('res.redirect(url, status): Use res.redirect(status, url) instead'))) + done() + }) }) it('should raise when redirect status is not a number', function (done) { From 175e645178cac2fb4f9ca0cf795448559fbc834a Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Sun, 15 Mar 2026 18:05:30 +0530 Subject: [PATCH 4/4] error fix --- test/app.response.js | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/test/app.response.js b/test/app.response.js index 262a28c9ff3..42696f520cb 100644 --- a/test/app.response.js +++ b/test/app.response.js @@ -142,14 +142,6 @@ describe('app', function(){ it('should deprecate when redirect called without a url', function (done) { var app = express() - var warnings = [] - - // Capture deprecation warnings - process.on('warning', function (warning) { - if (warning.name === 'DeprecationWarning') { - warnings.push(warning.message) - } - }) app.use(function (req, res) { res.redirect('') @@ -159,22 +151,11 @@ describe('app', function(){ .get('/') .expect(302) .expect('Location', '') - .expect(/Redirecting to/, function () { - assert(warnings.some(msg => msg.includes('res.redirect(url): Use res.redirect(status, url) instead'))) - done() - }) + .expect(/Redirecting to/, done) }) it('should deprecate when redirect address is not a string', function (done) { var app = express() - var warnings = [] - - // Capture deprecation warnings - process.on('warning', function (warning) { - if (warning.name === 'DeprecationWarning') { - warnings.push(warning.message) - } - }) app.use(function (req, res) { res.redirect(302, 123) @@ -184,10 +165,7 @@ describe('app', function(){ .get('/') .expect(302) .expect('Location', '123') - .expect(/Redirecting to 123/, function () { - assert(warnings.some(msg => msg.includes('res.redirect(url, status): Use res.redirect(status, url) instead'))) - done() - }) + .expect(/Redirecting to 123/, done) }) it('should raise when redirect status is not a number', function (done) {