Skip to content

Commit

Permalink
fix for "()" in test name
Browse files Browse the repository at this point in the history
  • Loading branch information
munderseth committed Sep 25, 2023
1 parent 6e1cd02 commit a0c9655
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Test
on:
push:
tags-ignore: ['v*']
paths-ignore:
- '**.md'
workflow_dispatch:
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Cypress XML Reporter

A JUnit XML reporter for Cypress that includes screenshots, videos, and logs.
A JUnit XML reporter for Cypress that includes **screenshots**, **videos**, and **logs** on test failures.

![CI](https://github.com/testspace-com/cypress-xml-reporter/actions/workflows/test.yml/badge.svg) [![npm](https://img.shields.io/npm/v/cypress-xml-reporter.svg?style=flat-square)](http://www.npmjs.com/package/cypress-xml-reporter)

This reporter works with [Testspace](https://testspace.com) to publish CI test results that include:

1. Captured screenshot of a test failure
2. Captured video for a suite with one or more failing tests
3. Logs generated using the [cypress terminal reporter](https://www.npmjs.com/package/cypress-terminal-report)
3. Logs generated using the [cypress terminal reporter](https://github.com/archfz/cypress-terminal-report)


## Installation
Expand All @@ -20,6 +20,7 @@ npm install cypress-xml-reporter --save-dev
Register the *plugin* in `cypress.config.js`:
```
module.exports = defineConfig({
video: true, // Cypress v13.x defaults to false
e2e: {
setupNodeEvents(on, config) {
require('cypress-xml-reporter/src/plugin') (on);
Expand All @@ -28,6 +29,8 @@ module.exports = defineConfig({
});
```

Note that Cypress [v13.x](https://docs.cypress.io/guides/references/changelog#13-0-0) defaults the `video` option to `false`. This option requires to be `true` to capture videos for test failures.

## Usage
Run Cypress with `cypress-xml-reporter`:

Expand All @@ -47,6 +50,8 @@ $ cypress run --reporter cypress_xml_reporter --reporter-options "resultsFolder=
Or using `cypress.config.js`:
```
module.exports = defineConfig({
video: true, // Cypress v13.x defaults to false
reporter: 'cypress-xml-reporter',
reporterOptions: {
resultsFolder: './path/location'
},
Expand All @@ -59,26 +64,25 @@ module.exports = defineConfig({
```

## Terminal Logging
To capture terminal output as log files the [Cypress terminal report](https://www.npmjs.com/package/cypress-terminal-report) package is supported:
To capture terminal output as log files the [Cypress terminal report](https://github.com/archfz/cypress-terminal-report) package is supported:

```
npm install cypress-terminal-report --save-dev
```
The package is required to be configured for [log specs in separate files](https://github.com/archfz/cypress-terminal-report#logging-to-files), setting the **type** format as `txt`.
The package is required to be configured for [log specs in separate files](https://github.com/archfz/cypress-terminal-report#logging-to-files), setting the **type** format as `txt`. And pass in the defined options (i.e. *logsOptions*) to the reporter plugin:

```
setupNodeEvents(on, config) {
video: true, // Cypress v13.x defaults to false
const logsOptions = {
outputRoot: config.projectRoot + '/cypress/',
outputTarget: {
'logs|txt': 'txt',
}
};
require('cypress-terminal-report/src/installLogsPrinter')(on, logsOptions);
require('cypress-xml-reporter/src/plugin') (on, logsOptions);
}
```

And pass in the defined options (i.e *logsOptions*) to the reporter plugin:
```
require('cypress-xml-reporter/src/plugin') (on, logsOptions);
```
Note that the terminal report requires an extra [installation](https://github.com/archfz/cypress-terminal-report#install) step to **register the log collector**.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cypress-xml-reporter",
"version": "1.0.0",
"version": "1.0.1",
"description": "A JUnit XML reporter for Cypress that includes screenshots, videos, and logs.",
"main": "src/reporter.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function createTestRecord(test, specRelativePath) {
case 'failed':
record['failure'] = {$: {message: test.err.message, type: test.err.name}, _: test.err.stack};
{
const UNSAFE_REGEX = /[^ A-Za-z0-9._-]/g;
const UNSAFE_REGEX = /[^ A-Za-z0-9.()_-]/g;
let imageBasename = testFullName.replaceAll(UNSAFE_REGEX, '').substring(0, 242)+' (failed).png';
let imageFile = path.join(config.screenshotsFolder, specRelativePath, imageBasename);
if (fs.existsSync(imageFile)) {
Expand Down

0 comments on commit a0c9655

Please sign in to comment.