From c69500bb854a50d67d5de29290e9dfaa9d96f3bc Mon Sep 17 00:00:00 2001 From: Roman Yakubuk Date: Thu, 28 Mar 2019 12:48:30 +0300 Subject: [PATCH 1/3] Change default statusText for Response --- fetch.js | 2 +- test/test.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/fetch.js b/fetch.js index 018bbb36..a6fd1f69 100644 --- a/fetch.js +++ b/fetch.js @@ -391,7 +391,7 @@ export function Response(bodyInit, options) { this.type = 'default' this.status = options.status === undefined ? 200 : options.status this.ok = this.status >= 200 && this.status < 300 - this.statusText = 'statusText' in options ? options.statusText : 'OK' + this.statusText = 'statusText' in options ? options.statusText : '' this.headers = new Headers(options.headers) this.url = options.url || '' this._initBody(bodyInit) diff --git a/test/test.js b/test/test.js index 1bebef88..0cb7105d 100644 --- a/test/test.js +++ b/test/test.js @@ -123,6 +123,8 @@ exercise.forEach(function(exerciseMode) { var nativeEdge = /Edge\//.test(navigator.userAgent) && exerciseMode === 'native' var firefox = navigator.userAgent.match(/Firefox\/(\d+)/) var brokenFF = firefox && firefox[1] <= 56 && exerciseMode === 'native' + var emptyDefaultStatusText = + exerciseMode !== 'native' || (exerciseMode === 'native' && (Chrome || (firefox && firefox[1] >= 67))) var polyfillFirefox = firefox && exerciseMode === 'polyfill' var omitSafari = Safari && exerciseMode === 'native' && navigator.userAgent.match(/Version\/(\d+\.\d+)/)[1] <= '11.1' @@ -584,20 +586,61 @@ exercise.forEach(function(exerciseMode) { // https://fetch.spec.whatwg.org/#response-class suite('Response', function() { - test('default status is 200 OK', function() { + featureDependent(test, emptyDefaultStatusText, "default status is 200 ''", function() { var res = new Response() assert.equal(res.status, 200) - assert.equal(res.statusText, 'OK') + assert.equal(res.statusText, '') assert.isTrue(res.ok) }) - test('default status is 200 OK when an explicit undefined status code is passed', function() { - var res = new Response('', {status: undefined}) + featureDependent( + test, + emptyDefaultStatusText, + "default status is 200 '' when an explicit undefined status code is passed", + function() { + var res = new Response('', {status: undefined}) + assert.equal(res.status, 200) + assert.equal(res.statusText, '') + assert.isTrue(res.ok) + } + ) + featureDependent(test, !emptyDefaultStatusText, 'default status is 200 OK', function() { + var res = new Response() assert.equal(res.status, 200) assert.equal(res.statusText, 'OK') assert.isTrue(res.ok) }) + featureDependent( + test, + !emptyDefaultStatusText, + 'default status is 200 OK when an explicit undefined status code is passed', + function() { + var res = new Response('', {status: undefined}) + assert.equal(res.status, 200) + assert.equal(res.statusText, 'OK') + assert.isTrue(res.ok) + } + ) + featureDependent(test, exerciseMode !== 'native', "default status is 200 ''", function() { + var res = new Response() + assert.equal(res.status, 200) + assert.equal(res.statusText, '') + assert.isTrue(res.ok) + }) + + featureDependent( + test, + exerciseMode !== 'native', + "default status is 200 '' when an explicit undefined status code is passed", + function() { + var res = new Response('', {status: undefined}) + assert.equal(res.status, 200) + assert.equal(res.statusText, '') + assert.isTrue(res.ok) + } + ) + testBodyExtract(function(body) { return new Response(body) }) From 50669a58a7bfc7a4f5e4fd00f1354274b4780504 Mon Sep 17 00:00:00 2001 From: Roman Yakubuk Date: Tue, 9 Apr 2019 12:38:29 +0300 Subject: [PATCH 2/3] Cleanup test descriptions. Remove redundant tests. --- test/test.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/test/test.js b/test/test.js index 0cb7105d..85a5f7fa 100644 --- a/test/test.js +++ b/test/test.js @@ -586,7 +586,7 @@ exercise.forEach(function(exerciseMode) { // https://fetch.spec.whatwg.org/#response-class suite('Response', function() { - featureDependent(test, emptyDefaultStatusText, "default status is 200 ''", function() { + featureDependent(test, emptyDefaultStatusText, 'default status is 200', function() { var res = new Response() assert.equal(res.status, 200) assert.equal(res.statusText, '') @@ -596,7 +596,7 @@ exercise.forEach(function(exerciseMode) { featureDependent( test, emptyDefaultStatusText, - "default status is 200 '' when an explicit undefined status code is passed", + 'default status is 200 when an explicit undefined status code is passed', function() { var res = new Response('', {status: undefined}) assert.equal(res.status, 200) @@ -622,24 +622,6 @@ exercise.forEach(function(exerciseMode) { assert.isTrue(res.ok) } ) - featureDependent(test, exerciseMode !== 'native', "default status is 200 ''", function() { - var res = new Response() - assert.equal(res.status, 200) - assert.equal(res.statusText, '') - assert.isTrue(res.ok) - }) - - featureDependent( - test, - exerciseMode !== 'native', - "default status is 200 '' when an explicit undefined status code is passed", - function() { - var res = new Response('', {status: undefined}) - assert.equal(res.status, 200) - assert.equal(res.statusText, '') - assert.isTrue(res.ok) - } - ) testBodyExtract(function(body) { return new Response(body) From 7b4da95ee308215ce83804f9fefc2e5b16e684de Mon Sep 17 00:00:00 2001 From: Roman Yakubuk Date: Thu, 11 Apr 2019 09:51:51 +0300 Subject: [PATCH 3/3] Remove checking old behavior for statusText default value --- test/test.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/test.js b/test/test.js index 85a5f7fa..ad2e9046 100644 --- a/test/test.js +++ b/test/test.js @@ -604,24 +604,6 @@ exercise.forEach(function(exerciseMode) { assert.isTrue(res.ok) } ) - featureDependent(test, !emptyDefaultStatusText, 'default status is 200 OK', function() { - var res = new Response() - assert.equal(res.status, 200) - assert.equal(res.statusText, 'OK') - assert.isTrue(res.ok) - }) - - featureDependent( - test, - !emptyDefaultStatusText, - 'default status is 200 OK when an explicit undefined status code is passed', - function() { - var res = new Response('', {status: undefined}) - assert.equal(res.status, 200) - assert.equal(res.statusText, 'OK') - assert.isTrue(res.ok) - } - ) testBodyExtract(function(body) { return new Response(body)