#!/usr/bin/env bats # adopt's helpers that don't need a server: rewriting the PM2 config, and finding the install's # own data files. Run with `npm run test:scripts`. setup() { # shellcheck source=../lib/common.sh source "$BATS_TEST_DIRNAME/../lib/common.sh" # shellcheck source=../lib/adopt.sh source "$BATS_TEST_DIRNAME/../lib/adopt.sh" TMP="$BATS_TEST_TMPDIR" } @test "rewrite_ecosystem points absolute paths at the new app folder" { run rewrite_ecosystem /var/www/hope-events /var/www/sites/hope/events/apps/events <<'EOF' module.exports = { apps: [ { name: 'hope-events-backend', cwd: '/var/www/hope-events/backend', script: 'src/index.js' }, { name: 'hope-events-frontend', cwd: "/var/www/hope-events/frontend", script: 'npm', args: 'start -- -p 3000' }, { name: 'x', cwd: `/var/www/hope-events`, out_file: '/var/www/hope-events2/log' }, ] }; EOF [[ "$output" == *"cwd: '/var/www/sites/hope/events/apps/events/backend'"* ]] [[ "$output" == *'cwd: "/var/www/sites/hope/events/apps/events/frontend"'* ]] [[ "$output" == *'cwd: `/var/www/sites/hope/events/apps/events`'* ]] # A different folder that only starts the same isn't touched. [[ "$output" == *"'/var/www/hope-events2/log'"* ]] [[ "$output" == *"name: 'hope-events-backend'"* ]] } @test "rewrite_ecosystem leaves __dirname configs alone" { input="$(cat "$BATS_TEST_DIRNAME/../../apps/events/ecosystem.config.example.js")" run rewrite_ecosystem /var/www/hope-events /var/www/sites/hope/events/apps/events <<< "$input" [ "$output" = "$input" ] } @test "rewrite_ecosystem copes with dots and other characters in paths" { run rewrite_ecosystem /opt/hope.events /srv/a\&b <<'EOF' cwd: '/opt/hope.events/backend', other: '/opt/hopexevents/backend' EOF [ "$output" = "cwd: '/srv/a&b/backend', other: '/opt/hopexevents/backend'" ] } @test "ignored_files_in lists the install's own data files, not tracked ones" { git init -q "$TMP/old" cd "$TMP/old" mkdir -p backend/data printf 'backend/data/banner.json\n' > .gitignore echo '{}' > backend/data/defaults.json git add . && git -c user.name=t -c user.email=t@t commit -q -m one echo '{}' > backend/data/banner.json run ignored_files_in "$TMP/old" backend/data [ "$output" = "backend/data/banner.json" ] }