@@ -2,6 +2,7 @@ import { expect, AssertionError } from 'chai';
22import sinon , { SinonStub } from 'sinon' ;
33import { execFileSync } from 'child_process' ;
44import http from 'http' ;
5+ import path from 'path' ;
56import { PassThrough } from 'stream' ;
67import { AddressInfo } from 'net' ;
78import Int64 from 'node-int64' ;
@@ -812,11 +813,13 @@ describe('CloudFetchResultHandler', () => {
812813
813814 it ( 'handles late body errors without application error handlers or unhandled rejections' , function ( ) {
814815 this . timeout ( 15000 ) ;
816+ const repoRoot = path . resolve ( __dirname , '../../..' ) ;
817+ const handlerPath = path . join ( repoRoot , 'lib/result/CloudFetchResultHandler' ) ;
815818 const script = `
816819 const assert = require('assert').strict;
817820 const { PassThrough } = require('stream');
818821 const { Response } = require('node-fetch');
819- const Handler = require('./lib/result/CloudFetchResultHandler' ).default;
822+ const Handler = require(${ JSON . stringify ( handlerPath ) } ).default;
820823 (async () => {
821824 const body = new PassThrough();
822825 const response = new Response(body);
@@ -839,8 +842,8 @@ describe('CloudFetchResultHandler', () => {
839842 ` ;
840843 const output = execFileSync (
841844 process . execPath ,
842- [ '--unhandled-rejections=strict' , '--require' , 'ts-node/register' , '-e' , script ] ,
843- { cwd : process . cwd ( ) , encoding : 'utf8' , timeout : 10000 , stdio : 'pipe' } ,
845+ [ '--unhandled-rejections=strict' , '--require' , require . resolve ( 'ts-node/register' ) , '-e' , script ] ,
846+ { cwd : repoRoot , encoding : 'utf8' , timeout : 10000 , stdio : 'pipe' } ,
844847 ) ;
845848 expect ( output ) . to . eq ( 'late body error handled\n' ) ;
846849 } ) ;
@@ -936,6 +939,7 @@ describe('CloudFetchResultHandler', () => {
936939 expect ( buffer . firstCall . thisValue . body ) . to . have . property ( 'pipe' ) . that . is . a ( 'function' ) ;
937940 expect ( buffer . firstCall . thisValue . body . listenerCount ( 'data' ) ) . to . eq ( 0 ) ;
938941 expect ( buffer . firstCall . thisValue . body . listenerCount ( 'end' ) ) . to . eq ( 0 ) ;
942+ expect ( buffer . firstCall . thisValue . body . listenerCount ( 'error' ) ) . to . eq ( 1 ) ;
939943 const downloaded = await buffer . firstCall . returnValue ;
940944 expect ( downloaded ) . to . deep . eq ( body ) ;
941945 expect ( downloaded . length ) . to . be . lt ( Buffer . poolSize >>> 1 ) ;
0 commit comments