Skip to content

Commit ca673bf

Browse files
authored
Compress report content with gzip before publishing (#2687)
1 parent 6a3647d commit ca673bf

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber.
99

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

1214
## [12.3.0] - 2025-12-01
1315
### Added

features/step_definitions/report_server_steps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { URL } from 'node:url'
22
import assert from 'node:assert'
3+
import { gunzipSync } from 'node:zlib'
34
import { expect } from 'chai'
45
import { Given, Then, DataTable } from '../..'
56
import { World } from '../support/world'
@@ -30,7 +31,7 @@ Then(
3031
.map((row) => row[0])
3132

3233
const receivedBodies = await this.reportServer.stop()
33-
const ndjson = receivedBodies.toString('utf-8').trim()
34+
const ndjson = gunzipSync(receivedBodies).toString('utf-8').trim()
3435
if (ndjson === '') assert.fail('Server received nothing')
3536

3637
const receivedMessageTypes = ndjson

src/publish/publish_plugin.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Writable } from 'node:stream'
2+
import { pipeline } from 'node:stream/promises'
23
import { stripVTControlCharacters } from 'node:util'
34
import { mkdtemp, stat } from 'node:fs/promises'
45
import path from 'node:path'
56
import { tmpdir } from 'node:os'
67
import { createReadStream, createWriteStream } from 'node:fs'
8+
import { createGzip } from 'node:zlib'
79
import { supportsColor } from 'supports-color'
810
import hasAnsi from 'has-ansi'
911
import { 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

Comments
 (0)