Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber.

## [Unreleased]
### Changed
- Compress report content with gzip before publishing ([#2687](https://github.com/cucumber/cucumber-js/pull/2687))

## [12.3.0] - 2025-12-01
### Added
Expand Down
3 changes: 2 additions & 1 deletion features/step_definitions/report_server_steps.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions src/publish/publish_plugin.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -44,22 +46,32 @@ export const publishPlugin: InternalPlugin<IPublishConfig | false> = {

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<void>((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) {
Expand All @@ -72,7 +84,7 @@ export const publishPlugin: InternalPlugin<IPublishConfig | false> = {
new URL(uploadUrl).origin
} with status ${uploadResponse.status}`
)
logger.debug(uploadResponse)
logger.debug(await uploadResponse.text())
}
resolve()
})
Expand Down