title: How do I check result of `npm run test` in bash conditional statement
body: <p>I have a deploy script I only want to run if my test is successful but believe there is an issue with my conditional statement <code>if [ "$VALID" ]</code></p>
  
  <pre><code>#!/bin/bash
  
  # install dependencies
  echo 'INSTALLING YARN'
  npm install yarn -g
  
  echo "INSTALLING DEPENDENCIES"
  yarn install
  
  echo "TESTING"
  VALID="$(npm test)"
  
  if [ "$VALID" ]
      then    
  
      # ZIP up the code
      echo 'INSTALLING ZIP'
      apt-get update
      echo "y" | apt-get install zip
  
      echo 'ZIPPING'
      zip -r ./Lambda-Image-Compression.zip index.js node_modules
  
      # install aws cli so we can deploy code
      echo 'INSTALLING PIP'
      # echo "y" | apt-get install python-pip
      echo "y" | apt-get install python-pip python-dev build-essential 
      echo "y" | pip install --upgrade pip 
      # echo "y" | sudo pip install --upgrade virtualenv 
  
      echo 'INSTALLING AWSCLI'
      pip install awscli
  
      # Copy config file to root so AWS config &amp; credentials are set
      echo 'MAKING AWS CREDENTIALS'
      CREDENTIALS="[default]
      aws_access_key_id = $AWS_ACCESS_KEY_ID
      aws_secret_access_key = $AWS_SECRET_ACCESS_KEY"
  
      touch .aws/credentials
      "$CREDENTIALS" &gt; .aws/credentials
  
      echo "MOVING AWS CONFIG"
      cp -R .aws ~/.
  
      # Upload to AWS
      echo 'UPDATING LAMBDA FUNCTION'
      aws lambda update-function-code \
      --function-name resizeHandler \
      --zip-file fileb://Lambda-Image-Compression.zip \
      --region ap-southeast-2
  
  fi
  </code></pre>
  
  <p>My test result if successful looks like: </p>
  
  <pre><code>&gt; Lambda-Image-Compression@1.0.0 test 
  &gt; mocha
  
    myLambda
  RUNNING OPTIMSATION
  download
  downloadImage: 69.381ms
  End of step null
      ✓ Should move testImage.png from srcBucket to dstBucket and return true (286ms)
  
  
    1 passing (299ms)
  </code></pre>
  
  <p>Failure shows the following:</p>
  
  <pre><code>TEST RESULT:
  
  &gt; Lambda-Image-Compression@1.0.0 test
  &gt; mocha
  
    myLambda
  RUNNING OPTIMSATION
  download
      1) Should move testImage.png from srcBucket to dstBucket and return true
  
  
    0 passing (22ms)
    1 failing
  
    1) myLambda Should move testImage.png from srcBucket to dstBucket and return true:
       ReferenceError: s3 is not defined
        at download (index.js:32:4)
        at nextTask (node_modules/async/dist/async.js:5273:14)
        at Object.waterfall (node_modules/async/dist/async.js:5283:5)
        at exports.handler (index.js:24:8)
        at error (node_modules/lambda-tester/lib/runner.js:151:25)
        at Promise.resolve.then (node_modules/lambda-tester/lib/runner.js:138:24)
  </code></pre>