Skip to content

Commit

Permalink
Merge pull request #11 from dherman/integration-tests
Browse files Browse the repository at this point in the history
Basic integration tests
  • Loading branch information
dherman authored Nov 10, 2023
2 parents 3c44e28 + 9419c14 commit c0fc11d
Show file tree
Hide file tree
Showing 33 changed files with 674 additions and 139 deletions.
67 changes: 47 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
NODE_VERSION: 18.x

on:
push:
# Prevent duplicate runs of this workflow on our own internal PRs.
Expand All @@ -23,23 +26,47 @@ jobs:
fetch-depth: 0
- name: Check Bundles
shell: bash
run: |
echo "Checking that all bundled tools are up to date..."
dirty_workspaces=()
for input_workspace in `find src -type d -mindepth 1 -maxdepth 1 -not -name node_modules` ; do
output_workspace=$(echo $input_workspace | sed -e 's/^src/pkgs/')
input_mtime=$(git log -1 --format=%ct $input_workspace)
output_mtime=$(git log -1 --format=%ct $output_workspace)
if [[ $input_mtime -gt $output_mtime ]] ; then
echo "❌ $input_workspace has changed since $output_workspace was last generated"
dirty_workspaces+=($input_workspace)
fi
done
if [[ ${#dirty_workspaces[@]} -gt 0 ]] ; then
echo
echo '💡 Re-run `npm run bundle` on the following workspaces before committing:'
for workspace in ${dirty_workspaces[*]} ; do
echo " • $workspace"
done
exit 1
fi
run: ./test/lint/check-bundles.sh

integration:
name: Integration Tests
needs: [bundles]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Dependencies
shell: bash
run: npm ci --verbose
- name: Build
uses: neon-actions/[email protected]
with:
working-directory: ./pkgs/cargo-messages
target: linux-x64-gnu
node-version: ${{ env.NODE_VERSION }}
use-cross: false
npm-publish: false
github-release: false
- name: Start npm Proxy
shell: bash
working-directory: ./test/integration/proxy
timeout-minutes: 3
run: ./ci-proxy.sh
- name: Publish to npm Proxy
shell: bash
working-directory: ./test/integration/proxy
timeout-minutes: 3
run: ./publish.sh
# Since package integrity checksums may vary depending on what versions
# are available in the proxy registry, we don't put the lockfile for this
# test in source control. This means we have to use `npm i`, not `npm ci`.
- name: Setup test-sniff-bytes Integration Test
shell: bash
working-directory: test/integration/test-sniff-bytes
run: npm i || (cat ../proxy/proxy.log && exit 1)
- name: Run test-sniff-bytes Integration Test
shell: bash
working-directory: test/integration/test-sniff-bytes
run: npm test
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
members = [
"pkgs/cargo-messages"
]
exclude = [
"test/integration/sniff-bytes"
]
147 changes: 28 additions & 119 deletions pkgs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/integration/proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
htpasswd
storage
proxy.log
nohup.out
13 changes: 13 additions & 0 deletions test/integration/proxy/ci-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# This script is used by CI to start up the npm proxy.

CIPROXY=http://127.0.0.1:4873

# Boot the server in a background process.
nohup npx verdaccio --config ./config.yml --listen $CIPROXY &

# Wait for the server to begin listening for connections
( tail -F -n10 proxy.log & ) | fgrep -q $CIPROXY

cat proxy.log
15 changes: 15 additions & 0 deletions test/integration/proxy/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
storage: ./storage
auth:
htpasswd:
file: ./htpasswd
packages:
'@neon-rs/*':
access: $all
publish: $all
'@sniff-bytes/*':
access: $all
publish: $all
'@neon-integration-tests/*':
access: $all
publish: $all
log: { type: file, path: proxy.log, level: info }
52 changes: 52 additions & 0 deletions test/integration/proxy/local-proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# This script can be used for running the integration tests in local development.
# It starts up the npm proxy and manages it with the pm2 process manager.

cd $(dirname $0)/../../..
ROOT_DIR=$(pwd)
PROXY_DIR=${ROOT_DIR}/test/integration/proxy
LOCAL_PROXY=http://127.0.0.1:4873

cd ${PROXY_DIR}

if ! which pm2 >/dev/null ; then
echo -e 'usage: local-proxy.sh'
echo -e
echo -e 'error: The required tool `pm2` was not found. Please install it first by running:'
echo -e
echo -e ' $ npm i -g pm2'
echo -e
exit 1
fi

if pm2 describe neon-test-proxy >/dev/null 2>&1 ; then
echo -e 'usage: local-proxy.sh'
echo -e
echo -e 'error: There is already a pm2 app named `neon-test-proxy`. Please remove it first by running:'
echo -e
echo -e ' $ pm2 stop neon-test-proxy'
echo -e ' $ pm2 delete neon-test-proxy'
echo -e
exit 1
fi

rm -rf ./storage ./proxy.log

# Boot the server in a background process.
pm2 start verdaccio --name neon-test-proxy --no-autorestart -- --config ./config.yml --listen ${LOCAL_PROXY}

# Wait for the server to begin listening for connections
( tail -F -n10 ./proxy.log & ) | fgrep -q "${LOCAL_PROXY}"

cat ./proxy.log

echo
echo 'Proxy `neon-test-proxy` started. You can now control it using pm2:'
echo
echo ' # Stop the proxy server:'
echo ' $ pm2 stop neon-test-proxy'
echo
echo ' # Restart the proxy server:'
echo ' $ pm2 restart neon-test-proxy'
echo
Loading

0 comments on commit c0fc11d

Please sign in to comment.