11import { Writable } from 'node:stream'
2+ import { pipeline } from 'node:stream/promises'
23import { stripVTControlCharacters } from 'node:util'
34import { mkdtemp , stat } from 'node:fs/promises'
45import path from 'node:path'
56import { tmpdir } from 'node:os'
67import { createReadStream , createWriteStream } from 'node:fs'
8+ import { createGzip } from 'node:zlib'
79import { supportsColor } from 'supports-color'
810import hasAnsi from 'has-ansi'
911import { InternalPlugin } from '../plugin'
@@ -44,22 +46,32 @@ export const publishPlugin: InternalPlugin<IPublishConfig | false> = {
4446
4547 const uploadUrl = touchResponse . headers . get ( 'Location' )
4648 const tempDir = await mkdtemp ( path . join ( tmpdir ( ) , `cucumber-js-publish-` ) )
47- const tempFilePath = path . join ( tempDir , 'envelopes.ndjson' )
48- const tempFileStream = createWriteStream ( tempFilePath , {
49- encoding : 'utf-8' ,
50- } )
51- on ( 'message' , ( value ) => tempFileStream . write ( JSON . stringify ( value ) + '\n' ) )
49+ const tempFilePath = path . join ( tempDir , 'envelopes.jsonl.gz' )
50+ const writeStream = createGzip ( )
51+ const finishedWriting = pipeline (
52+ writeStream ,
53+ createWriteStream ( tempFilePath )
54+ )
55+ on ( 'message' , ( value ) => writeStream . write ( JSON . stringify ( value ) + '\n' ) )
5256
5357 return ( ) => {
5458 return new Promise < void > ( ( resolve ) => {
55- tempFileStream . end ( async ( ) => {
59+ writeStream . end ( async ( ) => {
60+ await finishedWriting
5661 const stats = await stat ( tempFilePath )
62+ const contentLength = stats . size . toString ( )
63+ logger . debug (
64+ 'Uploading envelopes to Cucumber Reports with content length:' ,
65+ contentLength
66+ )
5767 const uploadResponse = await fetch ( uploadUrl , {
5868 method : 'PUT' ,
5969 headers : {
60- 'Content-Length' : stats . size . toString ( ) ,
70+ 'Content-Type' : 'application/jsonl' ,
71+ 'Content-Encoding' : 'gzip' ,
72+ 'Content-Length' : contentLength ,
6173 } ,
62- body : createReadStream ( tempFilePath , { encoding : 'utf-8' } ) ,
74+ body : createReadStream ( tempFilePath ) ,
6375 duplex : 'half' ,
6476 } )
6577 if ( uploadResponse . ok ) {
@@ -72,7 +84,7 @@ export const publishPlugin: InternalPlugin<IPublishConfig | false> = {
7284 new URL ( uploadUrl ) . origin
7385 } with status ${ uploadResponse . status } `
7486 )
75- logger . debug ( uploadResponse )
87+ logger . debug ( await uploadResponse . text ( ) )
7688 }
7789 resolve ( )
7890 } )
0 commit comments