Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Implemented NodeJS compatibility test. (#128)
Browse files Browse the repository at this point in the history
* Implemented NodeJS compatibility test.

* Moved compatibility testing scripts to `tools/nodejs_compatibility_checker`

* Implemented quick compatibility checking.

* Updated CircleCI config to use quick compatibility checking.

* Improved compatibility test failure detection.

* Improved compatibility test reporting.

* Fixed code style for compatibility test scripts.

* Fixed code style for "test_compatibility_setup.sh".

* Implement NodeJS compatibility test
  • Loading branch information
RazzM13 authored and martysweet committed Apr 4, 2018
1 parent 78f61fe commit c995eda
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ jobs:
- run:
name: test
command: npm test
- run:
name: compatibility test setup
command: bash tools/nodejs_compatibility_checker/test_compatibility_setup.sh --quick
- restore_cache:
key: compatibility-test-cache-{{ checksum "nodes_available.log" }}
- run:
name: compatibility test environment cache generation
command: bash tools/nodejs_compatibility_checker/test_compatibility_cache.sh
- save_cache:
key: compatibility-test-cache-{{ checksum "nodes_available.log" }}
paths:
- ~/.envirius/envs/
- run:
name: compatibility test
command: bash tools/nodejs_compatibility_checker/test_compatibility.sh
- run:
name: package for debug
command: npm pack
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Versioning](http://semver.org/spec/v2.0.0.html).
### Changed
- Merge PR #124, adding the `--verbose` flag and returning exit code `1` on a fatal exception or parsing error

### Added
- Merge PR #128, implement NodeJS compatibility test in CI/CD

## [1.5.1] - 2018-03-12
### Added
- Merge PR #113, adding a Spanish translation for README.md
Expand Down
37 changes: 37 additions & 0 deletions tools/nodejs_compatibility_checker/test_compatibility.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
[ ! -e ~/.envirius/nv ] && echo 'Error: envirius is not installed!' && exit 1
[ ! -e nodes_available.log ] && echo 'Error: no environments available!' && exit 1

export TERM="dumb"
source ~/.envirius/nv
node_versions=$(cat nodes_available.log)

# Run the tests on all available versions
for version in ${node_versions}; do
echo "Testing node-${version}!";
nv activate --same-shell "node-${version}"
npm test >"test_node_${version}.log" 2>&1
if [ $? -eq 0 ]; then
echo "PASSED"
echo ${version} >> nodes_passed.log
else
echo "FAILED"
fi
nv deactivate
done

# Determine failed versions and display the test-run
failed=$(comm -23 <(sort nodes_available.log) <(sort nodes_passed.log))
if [ -z "${failed}" ]; then
echo "Build is compatible with all major node versions!"
exit 0
fi

echo "Build is incompatible with the following node versions:"
echo "${failed}"
for version in ${failed}; do
echo "***Started test-run for ${version}***";
cat "test_node_${version}.log";
echo "***Finished test-run for ${version}***";
done
exit 1
13 changes: 13 additions & 0 deletions tools/nodejs_compatibility_checker/test_compatibility_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
[ ! -e ~/.envirius/nv ] && echo 'Error: envirius is not installed!' && exit 1
[ ! -e nodes_available.log ] && echo 'Error: no environments available!' && exit 1

export TERM="dumb"
source ~/.envirius/nv
node_versions=$(cat nodes_available.log)

# Cache NodeJS environments
for version in ${node_versions}; do
echo "Adding NodeJS ${version} into environment cache!" && \
nv mk "node-${version}" --node-prebuilt=${version}
done
36 changes: 36 additions & 0 deletions tools/nodejs_compatibility_checker/test_compatibility_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
export TERM="dumb"

# Install envirius
git clone --depth 1 https://github.com/ekalinin/envirius.git && \
cd envirius && \
make install && \
cd .. && \
source ~/.envirius/nv

if [ $? -ne 0 ]; then
echo "Unable to install envirius!"
exit 1
fi

# Determine available node versions
node_versions=$(nv ls-versions --node-prebuilt | sed 's/\s/\n/g' | grep -E '^[1-9]')
if [ -z "${node_versions}" ]; then
echo "Unable to determine node versions!"
exit 1
fi

# Quick check
if [ "$1" == "--quick" ]; then
lts_versions=$(
for lts in 4 6 8 9; do
echo "${node_versions}" | grep -E "^${lts}" | tail -1
done
)
node_versions=${lts_versions}
fi

# Dump available versions to file
for version in ${node_versions}; do
echo ${version} >> nodes_available.log
done

0 comments on commit c995eda

Please sign in to comment.