Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save namikingsoft/1905d8bd7f3b2cdb24cd36be24354709 to your computer and use it in GitHub Desktop.
Save namikingsoft/1905d8bd7f3b2cdb24cd36be24354709 to your computer and use it in GitHub Desktop.
Testcafe report of json to xunit for split by timings on CircleCI
#!/bin/sh -eu
#
# Testcafe report of json to xunit for split by timings on CircleCI
#
# refs.
# https://github.com/DevExpress/testcafe-reporter-xunit
# https://github.com/DevExpress/testcafe-reporter-json
#
# required packages:
# base64
# jq
#
# usage:
# ```bash
# sh <(curl --silent -L https://gist.githubusercontent.com/namikingsoft/1905d8bd7f3b2cdb24cd36be24354709/raw/testcafe-report-json-to-xunit-for-timings.sh) \
# < /path/to/result-input.json \
# > path/to/result-output.xml
# ```
#
# test:
# ```bash
# diff \
# <(curl --silent -L https://gist.githubusercontent.com/namikingsoft/1905d8bd7f3b2cdb24cd36be24354709/raw/zzz-sample-report-output.xml) \
# <(curl --silent -L https://gist.githubusercontent.com/namikingsoft/1905d8bd7f3b2cdb24cd36be24354709/raw/zzz-sample-report-input.json \
# | sh <(curl --silent -L https://gist.githubusercontent.com/namikingsoft/1905d8bd7f3b2cdb24cd36be24354709/raw/testcafe-report-json-to-xunit-for-timings.sh)
# )
# ```
input_json="$(cat -)"
timestamp="$(printf "%s" "$input_json" | jq -r .startTime)"
total="$(printf "%s" "$input_json" | jq -r .total)"
skipped="$(printf "%s" "$input_json" | jq -r .skipped)"
failures="$(printf "%s" "$input_json" | jq -r '.total - .passed - .skipped')"
total_time="$(printf "%s" "$input_json" | jq -r '.fixtures | map(.tests[].durationMs) | add / 1000')"
echo "<testsuite name=\"TestCafe\" tests=\"${total}\" failures=\"${failures}\" skipped=\"${skipped}\" errors=\"0\" time=\"${total_time}\" timestamp=\"${timestamp}\">"
fixtures_json_base64="$(printf "%s" "$input_json" | jq -r '.fixtures[] | @base64')"
for row_fixture in $fixtures_json_base64; do
filepath="$(echo "$row_fixture" | base64 --decode | jq -r .path | sed -e "s|^$(pwd)\/||")"
tests_json_base64="$(echo "$row_fixture" | base64 --decode | jq -r '.tests[] | @base64')"
for row_test in $tests_json_base64; do
name="$(echo "$row_test" | base64 --decode | jq -r .name)"
time="$(echo "$row_test" | base64 --decode | jq -r '.durationMs / 1000')"
echo "<testcase classname=\"${filepath}\" file=\"${filepath}\" name=\"${name}\" time=\"${time}\">"
errs_json_base64="$(echo "$row_test" | base64 --decode | jq -r '.errs[] | @base64')"
for row_err in $errs_json_base64; do
err="$(echo "$row_err" | base64 --decode)"
echo "<failure><![CDATA[\n${err}\n]]></failure>"
done
echo "</testcase>"
done
done
echo "</testsuite>"
{
"startTime": "2019-12-17T08:34:16.344Z",
"endTime": "2019-12-17T08:41:14.352Z",
"userAgents": [
"Chrome 79.0.3945.79 / Linux 0.0"
],
"passed": 3,
"total": 4,
"skipped": 0,
"fixtures": [
{
"name": "Fixture 1",
"path": "/path/to/fixture1.e2e.js",
"tests": [
{
"name": "Test 1",
"errs": [],
"durationMs": 31051,
"screenshotPath": null,
"skipped": false
},
{
"name": "Test 2",
"errs": [],
"durationMs": 6259,
"screenshotPath": null,
"skipped": false
}
]
},
{
"name": "Fixture 2",
"path": "/path/to/fixture2.e2e.js",
"tests": [
{
"name": "Test 1",
"errs": [
"The specified selector does not match any element in the DOM tree.\n\n > | Something Stack Traces"
],
"durationMs": 5350,
"screenshotPath": null,
"skipped": false
},
{
"name": "Test 2",
"errs": [],
"durationMs": 6259,
"screenshotPath": null,
"skipped": false
}
]
}
],
"warnings": []
}
<testsuite name="TestCafe" tests="4" failures="1" skipped="0" errors="0" time="48.919" timestamp="2019-12-17T08:34:16.344Z">
<testcase classname="/path/to/fixture1.e2e.js" file="/path/to/fixture1.e2e.js" name="Test 1" time="31.051">
</testcase>
<testcase classname="/path/to/fixture1.e2e.js" file="/path/to/fixture1.e2e.js" name="Test 2" time="6.259">
</testcase>
<testcase classname="/path/to/fixture2.e2e.js" file="/path/to/fixture2.e2e.js" name="Test 1" time="5.35">
<failure><![CDATA[
The specified selector does not match any element in the DOM tree.
> | Something Stack Traces
]]></failure>
</testcase>
<testcase classname="/path/to/fixture2.e2e.js" file="/path/to/fixture2.e2e.js" name="Test 2" time="6.259">
</testcase>
</testsuite>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment