Refactoring with many duplicates using Bash
Use a function with a parameter for the variable part to eliminate duplication:

post_report() {
  local result=$1
  curl -X POST -H 'Content-type: application/json' \
      --data '{"text":"Tests '"$result"' for Platform: '"$PLATFORM"'\nEnvironment: '"$ENVIRONMENT"'"}' \
      https://hooks.slack.com/services/rr/qq/pp
}

if ! npm test
then
  echo &gt;&amp;2 "Testing failed"
  post_report failed
  exit 1
else
  echo "Tests passed" 
  post_report passed
fi