@@ -532,6 +532,38 @@ describe("pw-tools-core", () => {
532532 expect ( res . truncated ) . toBe ( true ) ;
533533 } ) ;
534534
535+ it ( "does not split a surrogate pair when truncating response body text" , async ( ) => {
536+ let responseHandler : ( ( resp : unknown ) => void ) | undefined ;
537+ const on = vi . fn ( ( event : string , handler : ( resp : unknown ) => void ) => {
538+ if ( event === "response" ) {
539+ responseHandler = handler ;
540+ }
541+ } ) ;
542+ const off = vi . fn ( ) ;
543+ setPwToolsCoreCurrentPage ( { on, off } ) ;
544+
545+ const p = mod . responseBodyViaPlaywright ( {
546+ cdpUrl : "http://127.0.0.1:18792" ,
547+ targetId : "T1" ,
548+ url : "**/emoji" ,
549+ timeoutMs : 1000 ,
550+ maxChars : 1 ,
551+ } ) ;
552+
553+ await Promise . resolve ( ) ;
554+ if ( ! responseHandler ) {
555+ throw new Error ( "expected Playwright response handler" ) ;
556+ }
557+ responseHandler ( {
558+ url : ( ) => "https://example.com/emoji" ,
559+ status : ( ) => 200 ,
560+ headers : ( ) => ( { "content-type" : "text/plain" } ) ,
561+ body : async ( ) => Buffer . from ( "🙂B" ) ,
562+ } ) ;
563+
564+ await expect ( p ) . resolves . toMatchObject ( { body : "" , truncated : true } ) ;
565+ } ) ;
566+
535567 it ( "preserves the prefix while bounding decode for a large response" , async ( ) => {
536568 let responseHandler : ( ( resp : unknown ) => void ) | undefined ;
537569 const on = vi . fn ( ( event : string , handler : ( resp : unknown ) => void ) => {
0 commit comments