Skip to content

Commit 230d1a5

Browse files
cosmithclaude
andcommitted
feat: add path-prefix option to convert command
Playwright and other test runners may output paths relative to their config directory, but split patterns use repo-root paths. The path-prefix option allows prepending a prefix to all file paths during conversion so they match the split pattern. Example: --path-prefix "frontends/apps/e2e/" converts "tests/foo.spec.ts" to "frontends/apps/e2e/tests/foo.spec.ts" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5d0ce25 commit 230d1a5

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ inputs:
3232
to:
3333
description: 'Timing JSON file to write (for convert)'
3434
required: false
35+
path-prefix:
36+
description: 'Prefix to prepend to file paths (for convert) - use to match paths with split pattern'
37+
required: false
3538
# merge inputs
3639
prefix:
3740
description: 'Prefix to match timing JSON files (for merge)'
@@ -101,7 +104,8 @@ runs:
101104
run: |
102105
bun run ${{ github.action_path }}/index.ts convert \
103106
--from "${{ inputs.from }}" \
104-
--to "${{ inputs.to }}"
107+
--to "${{ inputs.to }}" \
108+
${{ inputs.path-prefix != '' && format('--path-prefix "{0}"', inputs.path-prefix) || '' }}
105109
106110
- name: Run merge
107111
if: inputs.command == 'merge'

bun.lockb

-472 Bytes
Binary file not shown.

index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const { positionals, values } = parseArgs({
1919
to: {
2020
type: "string",
2121
},
22+
["path-prefix"]: {
23+
type: "string",
24+
},
2225
// merge options
2326
["timings-file"]: {
2427
type: "string",
@@ -78,10 +81,13 @@ fairsplice convert
7881
Convert JUnit XML to timing JSON (for a single worker).
7982
8083
Required options:
81-
--from <file> JUnit XML file to read
82-
--to <file> Timing JSON file to write
84+
--from <file> JUnit XML file to read
85+
--to <file> Timing JSON file to write
86+
87+
Optional:
88+
--path-prefix <prefix> Prefix to prepend to all file paths (e.g., "src/tests/")
8389
84-
Example: fairsplice convert --from junit.xml --to timing.json
90+
Example: fairsplice convert --from junit.xml --to timing.json --path-prefix "frontends/apps/e2e/"
8591
8692
8793
fairsplice merge
@@ -125,7 +131,7 @@ if (command === "split") {
125131
);
126132
process.exit(1);
127133
}
128-
await convert({ from: values.from, to: values.to });
134+
await convert({ from: values.from, to: values.to, pathPrefix: values["path-prefix"] });
129135
process.exit(0);
130136
} else if (command === "merge") {
131137
if (!values["timings-file"] || !values.prefix) {

src/commands/convert.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { parseJunit } from "../lib/junit";
33
export async function convert({
44
from,
55
to,
6+
pathPrefix,
67
}: {
78
from: string;
89
to: string;
10+
pathPrefix?: string;
911
}) {
1012
// check if input file exists
1113
const junitXmlFile = Bun.file(from);
@@ -27,10 +29,12 @@ export async function convert({
2729
if (testCase.file.includes("..")) {
2830
continue;
2931
}
30-
if (!timingByFile[testCase.file]) {
31-
timingByFile[testCase.file] = 0;
32+
// Apply path prefix if provided
33+
const filePath = pathPrefix ? `${pathPrefix}${testCase.file}` : testCase.file;
34+
if (!timingByFile[filePath]) {
35+
timingByFile[filePath] = 0;
3236
}
33-
timingByFile[testCase.file] += testCase.time;
37+
timingByFile[filePath] += testCase.time;
3438
}
3539

3640
// convert to ms

0 commit comments

Comments
 (0)