#!/usr/bin/env bash

set -eou pipefail

WORKSPACE_ROOT="$(cargo metadata --format-version 1 | jq -r .workspace_root)"
cd "${WORKSPACE_ROOT}"

export RUST_BACKTRACE="full"

cargo llvm-cov clean --profraw-only --workspace

# no need to report as we can get all usage rolled together after the fact.
echo "Running tests with grpc"
time cargo llvm-cov nextest --no-fail-fast --no-report --profile ci --workspace --exclude xmtpv3 --exclude bindings_node --exclude bindings_wasm
echo "Running tests with http"
time cargo llvm-cov nextest --no-fail-fast --no-report --profile ci --workspace --exclude xmtpv3 --exclude bindings_node --exclude bindings_wasm --exclude xmtp_api_grpc --exclude xmtp_api_d14n --features http-api

mkdir -p coverage
rm -rf coverage/*

echo "Generating coverage report"
time cargo llvm-cov report --output-path coverage/lcov --lcov
echo "Generating coverage report html"
time cargo llvm-cov report --output-dir coverage/ --html
