Skip to content

Commit

Permalink
Merge pull request #10 from cypress-io/fix-incorrect-filename
Browse files Browse the repository at this point in the history
fix(filenames): ensure correct filename is exported regardless of nesting. add version tag to readme.
  • Loading branch information
jordanpowell88 authored Apr 25, 2022
2 parents c4db029 + 7ab95f7 commit 45d2892
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @cypress/chrome-recorder

[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/cypress-io/cypress-chrome-recorder) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

This repo provides tools to export Cypress Tests from Google Chrome DevTools' Recordings

Expand All @@ -12,7 +12,7 @@ $ npm install -g @cypress/chrome-recorder

## Usage

### CLI
### Via CLI

To use the interactive CLI, run:

Expand All @@ -28,9 +28,17 @@ If you prefer to enter paths via the CLI, you can run:
$ npx @cypress/chrome-recorder <relative path to target test file or directory>
```

**_ Note: _** Currently the output will be written to `cypress/integration`. If you do not have that folder, create it or install Cypress by running `yarn add -D cypress` or `npm install --save-dev cypress` in your project.
### CLI Options

| Option | Description |
| ----------- | --------------------------------------------------------- |
| -f, --force | Bypass Git safety checks and force exporter to run |
| -d, --dry | Dry run (no changes are made to files) |
| -p, --print | Print transformed files to stdout, useful for development |

**Note:** Currently the output will be written to `cypress/integration`. If you do not have that folder, create it or install Cypress by running `yarn add -D cypress` or `npm install --save-dev cypress` in your project.

### Import
### Via Import

```js
import { cypressStringifyChromeRecording } from '@cypress/chrome-recorder';
Expand All @@ -42,14 +50,6 @@ const stringifiedContent = await cypressStringifyChromeRecording(
return stringifiedContent;
```

### CLI Options

| Option | Description |
| ----------- | --------------------------------------------------------- |
| -f, --force | Bypass Git safety checks and force exporter to run |
| -d, --dry | Dry run (no changes are made to files) |
| -p, --print | Print transformed files to stdout, useful for development |

## License

[![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/cypress-io/cypress-chrome-recorder/blob/master/LICENSE)
Expand Down
7 changes: 6 additions & 1 deletion src/cli/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ export async function runTransforms({
return;
}

const testName = file.split('/')[1].replace('.json', '');
const fileName = file.split('/').pop();
const testName = fileName ? fileName.replace('.json', '') : undefined;

if (dry) {
console.log(stringifiedFile);
} else if (!testName) {
console.log(
chalk.red('No file or folder was found to export. Please try again.')
);
} else {
try {
fs.writeFileSync(
Expand Down

0 comments on commit 45d2892

Please sign in to comment.