From f0146d03621031bfe17f7fb373db8a7f72cf6ace Mon Sep 17 00:00:00 2001 From: Wes Todd Date: Sat, 31 Aug 2024 10:34:57 -0500 Subject: [PATCH] fix(test): fixed up preferred encoding tests --- index.js | 2 +- test/encoding.js | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index b83a81b..4f51315 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ Negotiator.prototype.encoding = function encoding(available, opts) { }; Negotiator.prototype.encodings = function encodings(available, options) { - opts = options || {}; + var opts = options || {}; return preferredEncodings(this.request.headers['accept-encoding'], available, opts.preferred); }; diff --git a/test/encoding.js b/test/encoding.js index cb90854..29801d4 100644 --- a/test/encoding.js +++ b/test/encoding.js @@ -212,14 +212,12 @@ describe('negotiator.encoding(array)', function () { it('should return most client-preferred encoding', function () { assert.strictEqual(this.negotiator.encoding(['gzip']), 'gzip') assert.strictEqual(this.negotiator.encoding(['compress', 'identity']), 'identity') - assert.strictEqual(this.negotiator.encoding(['gzip', 'deflate'], ['deflate']), 'gzip') - assert.strictEqual(this.negotiator.encoding(['deflate', 'gzip'], ['deflate']), 'gzip') }) it('should return developer-preferred encodings', function () { - assert.strictEqual(this.negotiator.encoding(['gzip', 'deflate'], ['gzip']), 'gzip') - assert.strictEqual(this.negotiator.encoding(['deflate', 'gzip'], ['gzip']), 'gzip') - assert.strictEqual(this.negotiator.encoding(['gzip'], ['gzip']), 'gzip') + assert.strictEqual(this.negotiator.encoding(['gzip', 'deflate'], { preferred: ['gzip'] }), 'gzip') + assert.strictEqual(this.negotiator.encoding(['deflate', 'gzip'], { preferred: ['gzip'] }), 'gzip') + assert.strictEqual(this.negotiator.encoding(['gzip'], { preferred: ['gzip'] }), 'gzip') }) }) }) @@ -439,14 +437,12 @@ describe('negotiator.encodings(array)', function () { it('should return client-preferred encodings', function () { assert.deepEqual(this.negotiator.encodings(['gzip']), ['gzip']) assert.deepEqual(this.negotiator.encodings(['identity', 'gzip', 'compress']), ['gzip', 'identity', 'compress']) - assert.deepEqual(this.negotiator.encodings(['gzip', 'deflate'], ['deflate']), ['gzip', 'deflate']) - assert.deepEqual(this.negotiator.encodings(['deflate', 'gzip'], ['deflate']), ['gzip', 'deflate']) }) it('should return developer-preferred encodings', function () { - assert.deepEqual(this.negotiator.encodings(['gzip', 'deflate'], ['gzip']), ['gzip', 'deflate']) - assert.deepEqual(this.negotiator.encodings(['deflate', 'gzip'], ['gzip']), ['gzip', 'deflate']) - assert.deepEqual(this.negotiator.encodings(['gzip'], ['gzip']), ['gzip']) + assert.deepEqual(this.negotiator.encodings(['gzip', 'deflate'], { preferred: ['gzip'] }), ['gzip', 'deflate']) + assert.deepEqual(this.negotiator.encodings(['deflate', 'gzip'], { preferred: ['gzip'] }), ['gzip', 'deflate']) + assert.deepEqual(this.negotiator.encodings(['gzip'], { preferred: ['gzip'] }), ['gzip']) }) }) })