Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>query</artifactId>
<version>[14.3.0,15.0.0)</version>
<version>[14.4.0,15.0.0)</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package io.cucumber.prettyformatter;

import io.cucumber.messages.types.Envelope;
import io.cucumber.messages.types.UndefinedParameterType;
import io.cucumber.query.Repository;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static io.cucumber.query.Repository.RepositoryFeature.INCLUDE_GHERKIN_DOCUMENTS;
import static io.cucumber.query.Repository.RepositoryFeature.INCLUDE_HOOKS;
import static io.cucumber.query.Repository.RepositoryFeature.INCLUDE_STEP_DEFINITIONS;
import static io.cucumber.query.Repository.RepositoryFeature.INCLUDE_SUGGESTIONS;
import static io.cucumber.query.Repository.RepositoryFeature.INCLUDE_UNDEFINED_PARAMETER_TYPES;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -28,8 +25,8 @@ public final class MessagesToSummaryWriter implements AutoCloseable {
.feature(INCLUDE_HOOKS, true)
.feature(INCLUDE_GHERKIN_DOCUMENTS, true)
.feature(INCLUDE_SUGGESTIONS, true)
.feature(INCLUDE_UNDEFINED_PARAMETER_TYPES, true)
.build();
private final List<UndefinedParameterType> undefinedParameterTypes = new ArrayList<>();
private final OutputStream out;
private final Theme theme;
private final Function<String, String> uriFormatter;
Expand All @@ -56,7 +53,6 @@ public void write(Envelope envelope) throws IOException {
throw new IOException("Stream closed");
}
repository.update(envelope);
envelope.getUndefinedParameterType().ifPresent(undefinedParameterTypes::add);
}


Expand All @@ -71,7 +67,7 @@ public void close() {
return;
}

try (SummaryReportWriter writer = new SummaryReportWriter(out, theme, uriFormatter, repository, undefinedParameterTypes)){
try (SummaryReportWriter writer = new SummaryReportWriter(out, theme, uriFormatter, repository)){
writer.printSummary();
} finally {
streamClosed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,18 @@ final class SummaryReportWriter implements AutoCloseable {
private final SourceReferenceFormatter sourceReferenceFormatter;
private final Query query;
private final PrintWriter out;
private final List<UndefinedParameterType> undefinedParameterTypes;

SummaryReportWriter(
OutputStream out,
Theme theme,
Function<String, String> uriFormatter,
Repository data,
List<UndefinedParameterType> undefinedParameterTypes
Repository data
) {
this.theme = requireNonNull(theme);
this.out = createPrintWriter(requireNonNull(out));
this.uriFormatter = requireNonNull(uriFormatter);
this.sourceReferenceFormatter = new SourceReferenceFormatter(uriFormatter);
this.query = new Query(requireNonNull(data));
this.undefinedParameterTypes = requireNonNull(undefinedParameterTypes);
}

private static PrintWriter createPrintWriter(OutputStream out) {
Expand Down Expand Up @@ -224,7 +221,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 All @@ -238,7 +235,7 @@ private String formatLocationComment(Pickle pickle) {

private String formatLocationComment(Hook hook) {
return sourceReferenceFormatter.format(hook.getSourceReference())
.map(comment -> theme.style(LOCATION, "#" + comment))
.map(comment -> theme.style(LOCATION, "# " + comment))
.map(comment -> " " + comment)
.orElse("");
}
Expand All @@ -248,7 +245,7 @@ private void printNonPassingTestRun() {
.ifPresent(exception -> {
out.println(theme.style(STEP, FAILED, firstLetterCapitalizedName(FAILED) + " test run:"));
ExceptionFormatter formatter = new ExceptionFormatter(7, theme, FAILED);
out.println(formatter.format(exception));
formatter.format(exception).ifPresent(out::println);
});
}

Expand All @@ -260,7 +257,6 @@ private Optional<Exception> findTestRunWithException() {


private void printTestRunCount() {
// TODO: No coverage?
findTestRunWithException()
// Only print stats if the test run failed with exception, avoid clutter
.map(exception -> {
Expand Down Expand Up @@ -335,6 +331,7 @@ private static String formatDuration(Duration duration) {
}

private void printUnknownParameterTypes() {
List<UndefinedParameterType> undefinedParameterTypes = this.query.findAllUndefinedParameterTypes();
if (undefinedParameterTypes.isEmpty()) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions javascript/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"loader": "ts-node/esm",
"require": "ts-node/register",
"extension": ["ts"],
"recursive": true
}
}
41 changes: 30 additions & 11 deletions javascript/package-lock.json

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

6 changes: 4 additions & 2 deletions javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@cucumber/pretty-formatter",
"version": "2.4.1",
"type": "module",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
Expand All @@ -22,7 +21,8 @@
"prepublishOnly": "tsc --build tsconfig.build.json"
},
"dependencies": {
"@cucumber/query": "^14.0.0"
"@cucumber/query": "14.6.0",
"luxon": "^3.7.2"
},
"peerDependencies": {
"@cucumber/messages": "*"
Expand All @@ -33,7 +33,9 @@
"@eslint/compat": "^1.3.1",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.30.1",
"@tsconfig/recommended": "^1.0.13",
"@types/chai": "^5.0.0",
"@types/luxon": "^3.7.1",
"@types/mocha": "^10.0.6",
"@types/node": "22.19.1",
"@typescript-eslint/eslint-plugin": "8.48.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'
import { CUCUMBER_THEME } from './theme'
import type { Options, Theme } from './types'

const DEMO_THEME: Theme = {
attachment: 'blue',
Expand Down Expand Up @@ -59,11 +60,9 @@ 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'),
cwd: path.join(__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
4 changes: 2 additions & 2 deletions javascript/src/PrettyPrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import {
pad,
STEP_ARGUMENT_INDENT_LENGTH,
unstyled,
} from './helpers.js'
import type { Options } from './types.js'
} from './helpers'
import type { Options } from './types'

export class PrettyPrinter {
private readonly println: (content?: string) => void
Expand Down
Loading