question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configurations for using a custom JSON Formatter

See original GitHub issue

Current behavior

JSON Formatter is required to be installed by anyone who wishes to use the reporting functionality. This adds an additional installation step / dependency to any machine running tests. It also seems to tightly couple JSON generation with the preprocessor.

Desired behavior

A way to add a custom JSON formatter other than the required Standalone executable one.

This could be a configuration option that would allow the user to only generate the .ndjson file before running their own formatting process once the preprocessor has finished?

After reading the docs I did try to achieve this with json.args: [“custom-formatter.js”] but couldn’t find supporting documentation for that option. I also ran into the ENOENT issue from the FAQ (where the Standalone Cucumber JSON Formatter is being searched for, even with the formatter variable set in package.json).

I used many variations of the config “json.enabled” “json.args”, “json.formatter”, “json.output” options but was unable to get a .ndjson without triggering the search for the standalone formatter executable. EG: "json": { "enabled": true, "args": ["cucumber-report-json-formatter.js"], "output": "cucumber-report.json" }

"json": { "enabled": true, "args": ["cucumber-report-json-formatter.js"], "formatter": "/formatter/", "output": "cucumber-report.json" } etc…

Versions

  • Cypress version: 10.3.0
  • Preprocessor version: 11.4.0
  • Node version: 14.19.3

Checklist

  • I’ve read the FAQ.
  • I’ve read Instructions for logging issues.
  • I’m not using cypress-cucumber-preprocessor@4.3.1 (package name has changed and it is no longer the most recent version, see #689).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
michaelsc93commented, Jul 7, 2022

Thanks @badeball I got it working.

For anyone in future, I am using the npm package cucumber-json-report-formatter (https://github.com/Vitalizzzer/cucumber-json-report-formatter) to avoid the .exe installation.

With that package, I wrote a short script to operate the formatter (report-formatter.js):

const Formatter = require('cucumber-json-report-formatter').Formatter;

const formatter = new Formatter();
const sourceFile = "./cucumber-messages.ndjson"
const outputFile = "./formatted-json/cucumber-report.json"

formatter.parseCucumberJson(sourceFile, outputFile);

And then with configuration:

  "cypress-cucumber-preprocessor": {
    "stepDefinitions": [
      "cypress/stepDefinitions/*.steps.js"
    ],
    "json": {
      "enabled": true,
      "formatter": "node",
      "args": ["report-formatter.js"],
      "output": "formatted-json/latestFormatProcess.log"
    }
  }

Final step is a command to run my html report which is user preference.

Thanks again!

1reaction
badeballcommented, Jul 7, 2022

There’s a lot of things to address here…

If you only require the NDJSON output, you can simply configure { "messages": { "enabled": true } } and that’s it. Then you have a NDJSON file, without the need of external dependencies.

Configuring { "json": { "formatter": "/formatter/" } } is never correct, because you have no executable named /formatter/ on your system (I checked).

If you want to process the NDJSON using a custom JS-script, you can configure { "json": { "enabled": true, "formatter": "node", "args": ["cucumber-report-json-formatter.js"] } }.

Edit: You can probably also create an executable script with a shebang and configure something like { "json": { "enabled": true, "formatter": "./cucumber-report-json-formatter.js" } }.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
Read more >
JSON editing in Visual Studio Code
Editing JSON with Visual Studio Code. JSON is a data format that is common in configuration files like package.json or project.json .
Read more >
Using a custom JSON formatter for Web API 2 - Stack Overflow
The following is the code for the JSON.Net formatter: config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/ ...
Read more >
Using multiple JSON serialization settings in ASP.NET Core
There are formatters for different formats, based on the content type: one for JSON, one for XML, one for plain text, etc. For...
Read more >
DJANGO LOGGING #2. JSON FORMATTING AND CUSTOM ...
JSON FORMATTING AND CUSTOM HANDLERS ... Andrey Ivanov - Python Use my discount link for OKEX crypto exchange: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found