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

Implemented NodeJS compatibility test. #128

Merged
merged 12 commits into from
Apr 4, 2018
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:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

22 seconds, awesome!

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
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lts_version=$(
    for lts in 4....

    done
)

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