mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: API response to string (#10364)
This commit is contained in:
parent
32bc83d322
commit
08a7470b0a
@ -47,7 +47,7 @@ export class ConsoleMessage extends ChannelOwner<channels.ConsoleMessageChannel,
|
||||
return this._initializer.location;
|
||||
}
|
||||
|
||||
[(util.inspect as any).custom]() {
|
||||
[util.inspect.custom]() {
|
||||
return this.text();
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import * as mime from 'mime';
|
||||
import * as util from 'util';
|
||||
import { Serializable } from '../../types/structs';
|
||||
import * as api from '../../types/types';
|
||||
import { HeadersArray } from '../common/types';
|
||||
@ -272,6 +273,11 @@ export class APIResponse implements api.APIResponse {
|
||||
});
|
||||
}
|
||||
|
||||
[util.inspect.custom]() {
|
||||
const headers = this.headersArray().map(({ name, value }) => ` ${name}: ${value}`);
|
||||
return `APIResponse: ${this.status()} ${this.statusText()}\n${headers.join('\n')}`;
|
||||
}
|
||||
|
||||
_fetchUid(): string {
|
||||
return this._initializer.fetchUid;
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ export class Locator implements api.Locator {
|
||||
});
|
||||
}
|
||||
|
||||
[(util.inspect as any).custom]() {
|
||||
[util.inspect.custom]() {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import http from 'http';
|
||||
import * as util from 'util';
|
||||
import { getPlaywrightVersion } from 'playwright-core/lib/utils/utils';
|
||||
import { expect, playwrightTest as it } from './config/browserTest';
|
||||
|
||||
@ -294,3 +295,18 @@ it(`should accept already serialized data as Buffer when content-type is applica
|
||||
expect(body.toString()).toEqual(value);
|
||||
await request.dispose();
|
||||
});
|
||||
|
||||
it(`should have nice toString`, async ({ playwright, server }) => {
|
||||
const request = await playwright.request.newContext();
|
||||
const response = await request.post(server.EMPTY_PAGE, {
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
data: 'My post data'
|
||||
});
|
||||
const str = response[util.inspect.custom]();
|
||||
expect(str).toContain('APIResponse: 200 OK');
|
||||
for (const { name, value } of response.headersArray())
|
||||
expect(str).toContain(` ${name}: ${value}`);
|
||||
await request.dispose();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user