Last active
August 3, 2016 23:58
-
-
Save mathewdgardner/ca53a988f5cb1b537789e86a86bfb562 to your computer and use it in GitHub Desktop.
Testing multiple major versions of NPM modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# $0 - Required module name | |
# $1 - Optional minimum version | |
module=$1 | |
# Assert we have a module to install | |
: ${module:?} | |
# Get the range of versions to test against | |
read minVersion headVersion <<< $( | |
cat package.json \ | |
| grep "\"$module\"" \ | |
| cut -d '"' -f 4 \ | |
| sed 's/\^//; s/~//; s/>//; s/<//; s/=//; s/[[:space:]]//' \ | |
| cut -d '.' -f 1 \ | |
| sort -n | |
) | |
# Use given minimum version to test against | |
if [ ! -z "$2" ]; then | |
minVersion=$2 | |
fi | |
# Assert we have a current version to test against and reset to | |
: ${headVersion:?} | |
# Assert we have a minimum version to test against | |
: ${minVersion:?} | |
# Do the work | |
for((version=$headVersion; version >= $minVersion; version--)) do | |
# Install specific version to test against | |
npm install $module@$version | |
# Get installed version from disk | |
installedVersion=$( | |
npm ls $module --depth 0 /dev/null \ | |
| grep $module \ | |
| cut -d '@' -f 2 \ | |
| cut -d '.' -f 1 | |
) | |
# Assert that the version we want to test was actually installed | |
if [ "$version" -ne "$installedVersion" ]; then exit 1; fi | |
# Run tests | |
docker-compose run comm_disrupted npm run test | |
done | |
# Reset to version from package.json | |
npm install $module@$headVersion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment