Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private static String formatAttempt(TestCaseStarted testCaseStarted) {
if (attempt == 0) {
return "";
}
return ", after " + attempt + " attempts";
return ", after " + (attempt + 1) + " attempts";
}

private String formatLocationComment(Pickle pickle) {
Expand Down
26 changes: 22 additions & 4 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"prepublishOnly": "tsc --build tsconfig.build.json"
},
"dependencies": {
"@cucumber/query": "^14.0.0"
"@cucumber/query": "14.3.0",
"luxon": "^3.7.2"
},
"peerDependencies": {
"@cucumber/messages": "*"
Expand All @@ -34,6 +35,7 @@
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.30.1",
"@types/chai": "^5.0.0",
"@types/luxon": "^3.7.1",
"@types/mocha": "^10.0.6",
"@types/node": "22.18.6",
"@typescript-eslint/eslint-plugin": "8.44.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { Envelope, TestStepResultStatus } from '@cucumber/messages'
import { expect } from 'chai'
import { globbySync } from 'globby'

import type { Options, Theme } from './index.js'
import formatter, { CUCUMBER_THEME } from './index.js'
import { PrettyPrinter } from './PrettyPrinter.js'
import { CUCUMBER_THEME } from './theme.js'
import type { Options, Theme } from './types.js'

const DEMO_THEME: Theme = {
attachment: 'blue',
Expand Down Expand Up @@ -59,9 +60,7 @@ const DEMO_THEME: Theme = {
tag: ['yellow', 'bold'],
}

describe('Acceptance Tests', async function () {
this.timeout(10_000)

describe('PrettyPrinter', async () => {
const ndjsonFiles = globbySync(`*.ndjson`, {
cwd: path.join(import.meta.dirname, '..', '..', 'testdata', 'src'),
absolute: true,
Expand Down Expand Up @@ -143,26 +142,27 @@ describe('Acceptance Tests', async function () {
const [suiteName] = path.basename(ndjsonFile).split('.')

it(suiteName, async () => {
let emit: (message: Envelope) => void
let content = ''
formatter.formatter({
options,
stream: fakeStream,
on(type, handler) {
emit = handler
},
write: (chunk) => {
const printer = new PrettyPrinter(
fakeStream,
(chunk) => {
content += chunk
},
})
{
attachments: true,
featuresAndRules: true,
theme: CUCUMBER_THEME,
...options,
}
)

await pipeline(
fs.createReadStream(ndjsonFile, { encoding: 'utf-8' }),
new NdjsonToMessageStream(),
new Writable({
objectMode: true,
write(envelope: Envelope, _: BufferEncoding, callback) {
emit(envelope)
printer.update(envelope)
callback()
},
})
Expand Down
103 changes: 103 additions & 0 deletions javascript/src/ProgressPrinter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import fs from 'node:fs'
import * as path from 'node:path'
import { Writable } from 'node:stream'
import { pipeline } from 'node:stream/promises'

import { NdjsonToMessageStream } from '@cucumber/message-streams'
import { Envelope, TestStepResultStatus } from '@cucumber/messages'
import { expect } from 'chai'
import { globbySync } from 'globby'

import { ProgressPrinter } from './ProgressPrinter.js'
import { CUCUMBER_THEME } from './theme.js'
import type { Options } from './types.js'

describe('ProgressPrinter', async () => {
const ndjsonFiles = globbySync(`*.ndjson`, {
cwd: path.join(import.meta.dirname, '..', '..', 'testdata', 'src'),
absolute: true,
})

const variants: ReadonlyArray<{ name: string; options: Options }> = [
{
name: 'cucumber',
options: {
attachments: true,
featuresAndRules: true,
theme: CUCUMBER_THEME,
},
},
{
name: 'plain',
options: {
attachments: true,
featuresAndRules: true,
theme: {
status: {
icon: {
[TestStepResultStatus.AMBIGUOUS]: '✘',
[TestStepResultStatus.FAILED]: '✘',
[TestStepResultStatus.PASSED]: '✔',
[TestStepResultStatus.PENDING]: '■',
[TestStepResultStatus.SKIPPED]: '↷',
[TestStepResultStatus.UNDEFINED]: '■',
[TestStepResultStatus.UNKNOWN]: ' ',
},
},
},
},
},
]

// just enough so Node.js internals consider it a color-supporting stream
const fakeStream = {
_writableState: {},
isTTY: true,
getColorDepth: () => 3,
} as unknown as NodeJS.WritableStream

for (const { name, options } of variants) {
describe(name, () => {
for (const ndjsonFile of ndjsonFiles) {
const [suiteName] = path.basename(ndjsonFile).split('.')

it(suiteName, async () => {
let content = ''
const printer = new ProgressPrinter(
fakeStream,
(chunk) => {
content += chunk
},
{
attachments: true,
featuresAndRules: true,
theme: CUCUMBER_THEME,
...options,
}
)

await pipeline(
fs.createReadStream(ndjsonFile, { encoding: 'utf-8' }),
new NdjsonToMessageStream(),
new Writable({
objectMode: true,
write(envelope: Envelope, _: BufferEncoding, callback) {
printer.update(envelope)
callback()
},
})
)

const expectedOutput = fs.readFileSync(
ndjsonFile.replace('.ndjson', `.${name}.progress.log`),
{
encoding: 'utf-8',
}
)

expect(content).to.eq(expectedOutput)
})
}
})
}
})
43 changes: 43 additions & 0 deletions javascript/src/ProgressPrinter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Envelope } from '@cucumber/messages'
import { Query } from '@cucumber/query'

import { formatStatusCharacter } from './helpers.js'
import type { Options } from './types.js'

export class ProgressPrinter {
private readonly query: Query = new Query()

constructor(
private readonly stream: NodeJS.WritableStream,
private readonly print: (content: string) => void,
private readonly options: Required<Options>
) {}

update(message: Envelope) {
this.query.update(message)

if (message.testStepFinished) {
this.print(
formatStatusCharacter(
message.testStepFinished.testStepResult.status,
this.options.theme,
this.stream
)
)
}

if (message.testRunHookFinished) {
this.print(
formatStatusCharacter(
message.testRunHookFinished.result.status,
this.options.theme,
this.stream
)
)
}

if (message.testRunFinished) {
this.print('\n')
}
}
}
Loading
Loading