Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,21 @@ debuggerPlugin(on: Cypress.PluginEvents, config: Cypress.PluginConfig, options?:
```

- `on` - [`Cypress.PluginEvents`](https://docs.cypress.io/guides/references/configuration#setupNodeEvents) `setupNodeEvents` method first argument
- `on` - [`Cypress.PluginConfig`](https://docs.cypress.io/guides/references/configuration#setupNodeEvents) `setupNodeEvents` method second argument
- `config` - [`Cypress.PluginConfig`](https://docs.cypress.io/guides/references/configuration#setupNodeEvents) `setupNodeEvents` method second argument
- `options` - [`PluginOptions`](./packages/plugin/src/types.ts):
- `meta: Record<string, unknown>`: an optional field that is added to the `TestExecutionResult` as `pluginMeta`
- `callback: (path: string, data: TestExecutionResult`: a callback function that will be called after each test
- `targetDirectory: string`: the path to the reports directory. Default is `dump`
- `failedTestsOnly: boolean`: whether to generate debug traces for failed tests only, default is `false`
- `filenameFn: (ctx: RunContextData) => string`: a function used to generate the filename of each test. By default, the filename is created using `spec_test_attempt` template.

```typescript
interface RunContextData {
spec: string;
test: string[];
retryAttempt: number;
}
```

Example:

Expand All @@ -126,6 +135,7 @@ module.exports = defineConfig({
console.log({ path, data });
},
targetDirectory: 'cypress/e2e/reports',
filenameFn: ({ spec }) => `${spec}_${Date.now()}`,
});
},
},
Expand Down
27 changes: 24 additions & 3 deletions packages/plugin/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ import {
import { createDir, readFile, removeDir, removeFile, writeFile } from './fs';
import { PluginOptions, TestExecutionResult } from './types';

type CreateDumpFileOptions = {
dumpDir: string;
filename: string;
};

const harDir = 'dump_har';

const createDumpFile = (data: TestExecutionResult, dumpDir: string): string => {
const createDumpFile = (
data: TestExecutionResult,
{ dumpDir, filename }: CreateDumpFileOptions
): string => {
createDir(dumpDir);
const resultsPath = path.join(dumpDir, `${data.id}.raw.json`);
const resultsPath = path.join(dumpDir, `${filename}.json`);
writeFile(resultsPath, JSON.stringify(data, null, 2));
return resultsPath;
};
Expand Down Expand Up @@ -74,7 +82,20 @@ function install(
? options.targetDirectory
: 'dump';

const resultsFilePath = createDumpFile(dumpData, dumpDir);
let filename = `${dumpData.meta.spec}_${dumpData.meta.test.join(' > ')}_${
dumpData.meta.retryAttempt + 1
}`;
if (typeof options?.filenameFn === 'function') {
const result = options.filenameFn(dumpData.meta);
if (typeof result === 'string') {
filename = result;
}
}

const resultsFilePath = createDumpFile(dumpData, {
dumpDir,
filename,
});

if (options && options.callback) {
options.callback(resultsFilePath, dumpData);
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ export type PluginOptions = {
targetDirectory?: string;
failedTestsOnly?: boolean;
callback?: (path: string, result: TestExecutionResult) => void;
filenameFn?: (ctx: RunContextData) => string;
};