#!/usr/bin/env bash
#
# Replaces certain "uncontrollable" properties with fixed values
# This allows for comparison of documents without expecting these
# properties to be equal
#
set -euf -o pipefail

jq ".[].elements[]?.before[]?.result.duration = 99" | \
jq ".[].elements[]?.before[]?.result.error_message = \"some before hook error\"" | \
jq ".[].elements[]?.before[]?.match.location = \"some_before_hook.xyz\"" |

jq ".[].elements[]?.steps[]?.result.duration = 99" | \
jq ".[].elements[]?.steps[]?.result.error_message = \"some stepdef error\"" | \
jq ".[].elements[]?.steps[]?.match.location |=
  if test(\"(.*.feature:[^:]+)\") then
    match(\"(.*.feature:[^:]+)\").captures[0].string
  else
    \"some_stepdef.xyz\"
  end" | \
jq ".[].elements[]?.after[]?.result.duration = 99" | \
jq ".[].elements[]?.after[]?.result.error_message = \"some after hook error\"" | \
jq ".[].elements[]?.after[]?.match.location = \"some_after_hook.xyz\"" | \

jq "."
