-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch: improve output for FormData, Response, Request (#2955)
* fetch: improve output for FormData * fetch: improve output for Response * fetch: improve output for Request * fetch: improve output for Request * feat: repair code * feat: repair code * feat: repair code * fix: repair codes & tests * fix: repair tests & response & request class * Update response.js Co-authored-by: Khafra <maitken033380023@gmail.com> * fix: test repair --------- Co-authored-by: Mert Can Altin <mert.altin@trendyol.com> Co-authored-by: Khafra <maitken033380023@gmail.com>
- Loading branch information
1 parent
321763e
commit 2e11fc8
Showing
6 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict' | ||
|
||
const { FormData } = require('../../') | ||
const { inspect } = require('node:util') | ||
const { test } = require('node:test') | ||
const assert = require('node:assert') | ||
|
||
test('FormData class custom inspection', () => { | ||
const formData = new FormData() | ||
formData.append('username', 'john_doe') | ||
formData.append('email', 'john@example.com') | ||
|
||
const expectedOutput = 'FormData:\nusername: john_doe\nemail: john@example.com\n' | ||
|
||
assert.deepStrictEqual(inspect(formData), expectedOutput) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
const { describe, it } = require('node:test') | ||
const assert = require('assert') | ||
const util = require('util') | ||
const { Request } = require('../../') | ||
|
||
describe('Request custom inspection', () => { | ||
it('should return a custom inspect output', () => { | ||
const request = new Request('https://example.com/api', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
|
||
const inspectedOutput = util.inspect(request) | ||
|
||
const expectedOutput = '{\n method: \'POST\',\n url: \'https://example.com/api\',\n headers: Headers { \'Content-Type\': \'application/json\' },\n destination: \'\',\n referrer: \'about:client\',\n referrerPolicy: \'\',\n mode: \'cors\',\n credentials: \'same-origin\',\n cache: \'default\',\n redirect: \'follow\',\n integrity: \'\',\n keepalive: false,\n isReloadNavigation: false,\n isHistoryNavigation: false,\n signal: AbortSignal { aborted: false }\n}' | ||
assert.strictEqual(inspectedOutput, expectedOutput) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const { describe, it } = require('node:test') | ||
const assert = require('assert') | ||
const util = require('util') | ||
const { Response } = require('../../') | ||
|
||
describe('Response custom inspection', () => { | ||
it('should return a custom inspect output', () => { | ||
const response = new Response(null) | ||
const inspectedOutput = util.inspect(response, { | ||
depth: null, | ||
getters: true | ||
}) | ||
|
||
const expectedOutput = `Response { | ||
status: 200, | ||
statusText: '', | ||
headers: Headers {}, | ||
body: null, | ||
bodyUsed: false, | ||
ok: true, | ||
redirected: false, | ||
type: 'default', | ||
url: '' | ||
}` | ||
|
||
assert.strictEqual(inspectedOutput, expectedOutput) | ||
}) | ||
}) |