diff --git a/features/step_definitions/report_server_steps.ts b/features/step_definitions/report_server_steps.ts index 78c91b870..588ceabcf 100644 --- a/features/step_definitions/report_server_steps.ts +++ b/features/step_definitions/report_server_steps.ts @@ -1,5 +1,6 @@ import { URL } from 'node:url' import assert from 'node:assert' +import { gunzipSync } from 'node:zlib' import { expect } from 'chai' import { Given, Then, DataTable } from '../..' import { World } from '../support/world' @@ -30,7 +31,7 @@ Then( .map((row) => row[0]) const receivedBodies = await this.reportServer.stop() - const ndjson = receivedBodies.toString('utf-8').trim() + const ndjson = gunzipSync(receivedBodies).toString('utf-8').trim() if (ndjson === '') assert.fail('Server received nothing') const receivedMessageTypes = ndjson diff --git a/src/publish/publish_plugin.ts b/src/publish/publish_plugin.ts index 3ed29d756..2b2a3fabb 100644 --- a/src/publish/publish_plugin.ts +++ b/src/publish/publish_plugin.ts @@ -1,9 +1,11 @@ import { Writable } from 'node:stream' +import { pipeline } from 'node:stream/promises' import { stripVTControlCharacters } from 'node:util' import { mkdtemp, stat } from 'node:fs/promises' import path from 'node:path' import { tmpdir } from 'node:os' import { createReadStream, createWriteStream } from 'node:fs' +import { createGzip } from 'node:zlib' import { supportsColor } from 'supports-color' import hasAnsi from 'has-ansi' import { InternalPlugin } from '../plugin' @@ -44,22 +46,32 @@ export const publishPlugin: InternalPlugin = { const uploadUrl = touchResponse.headers.get('Location') const tempDir = await mkdtemp(path.join(tmpdir(), `cucumber-js-publish-`)) - const tempFilePath = path.join(tempDir, 'envelopes.ndjson') - const tempFileStream = createWriteStream(tempFilePath, { - encoding: 'utf-8', - }) - on('message', (value) => tempFileStream.write(JSON.stringify(value) + '\n')) + const tempFilePath = path.join(tempDir, 'envelopes.jsonl.gz') + const writeStream = createGzip() + const finishedWriting = pipeline( + writeStream, + createWriteStream(tempFilePath) + ) + on('message', (value) => writeStream.write(JSON.stringify(value) + '\n')) return () => { return new Promise((resolve) => { - tempFileStream.end(async () => { + writeStream.end(async () => { + await finishedWriting const stats = await stat(tempFilePath) + const contentLength = stats.size.toString() + logger.debug( + 'Uploading envelopes to Cucumber Reports with content length:', + contentLength + ) const uploadResponse = await fetch(uploadUrl, { method: 'PUT', headers: { - 'Content-Length': stats.size.toString(), + 'Content-Type': 'application/jsonl', + 'Content-Encoding': 'gzip', + 'Content-Length': contentLength, }, - body: createReadStream(tempFilePath, { encoding: 'utf-8' }), + body: createReadStream(tempFilePath), duplex: 'half', }) if (uploadResponse.ok) { @@ -72,7 +84,7 @@ export const publishPlugin: InternalPlugin = { new URL(uploadUrl).origin } with status ${uploadResponse.status}` ) - logger.debug(uploadResponse) + logger.debug(await uploadResponse.text()) } resolve() })