Skip to content

Commit

Permalink
fix merge CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 2, 2024
1 parent 6054653 commit b314912
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,9 @@ npx playwright test --shard=1/3
npx playwright test --shard=2/3
npx playwright test --shard=3/3
```
There are 3 reports will be generated. Using `merge(reportDataList, options)` API to merge all reports into one.
There are 3 reports will be generated.

### Using `merge` API to merge all reports into one
> Note: One more suite level "shard" will be added, its title will be the machine hostname, and the summary will be restated. All attachments will be copied to the merged output directory.
```js
import { merge } from 'monocart-reporter';
Expand All @@ -1033,8 +1035,6 @@ await merge(reportDataList, {
}
});
```
see example [merge.js](https://github.com/cenfun/monocart-reporter-examples/blob/main/scripts/merge.js)

> Note: The coverage reports will be merged automatically if we specify the `raw` report in coverage options:
```js
// global coverage options
Expand All @@ -1045,6 +1045,19 @@ coverage: {
]
}
```
see example [merge.js](https://github.com/cenfun/monocart-reporter-examples/blob/main/scripts/merge.js)

### Using `merge` CLI
```sh
npx monocart merge path-to/shard*/index.json
# -o --outputFile
npx monocart merge path-to/shard*/index.json -o merged-reports/index.html
# -c --config
npx monocart merge path-to/shard*/index.json -c mr.config.js
```


## onEnd Hook
The `onEnd` function will be executed after report generated. Arguments:
Expand Down
13 changes: 12 additions & 1 deletion lib/merge-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const initDataList = (reportDataList) => {
}

// for finding attachments
data.jsonDir = path.dirname(item);
data.jsonDir = Util.relativePath(path.dirname(item));

list.push(data);
Util.logInfo(`report data loaded: ${item}`);
Expand All @@ -54,6 +54,17 @@ const initDataList = (reportDataList) => {
return;
}

// sort list

list.sort((a, b) => {
if (a.jsonDir > b.jsonDir) {
return 1;
}
return -1;
});

// console.log(list.map((it) => it.jsonDir));

return list;
};

Expand Down

0 comments on commit b314912

Please sign in to comment.