From 0ad41dd1c2f7fcf299c9dac32ef82b328934f458 Mon Sep 17 00:00:00 2001 From: Reetik Rajan Date: Sat, 5 Oct 2024 11:32:56 +0530 Subject: [PATCH] test for 'nvm use lts' to show actionable error --- ...nning 'nvm use lts' shows actionable error | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/slow/nvm use/Running 'nvm use lts' shows actionable error diff --git a/test/slow/nvm use/Running 'nvm use lts' shows actionable error b/test/slow/nvm use/Running 'nvm use lts' shows actionable error new file mode 100644 index 0000000..0f766b6 --- /dev/null +++ b/test/slow/nvm use/Running 'nvm use lts' shows actionable error @@ -0,0 +1,19 @@ +#!/bin/sh + +set -ex + +die () { echo "$@" ; exit 1; } + +\. ../../../nvm.sh + +# Deactivate any active node version +nvm deactivate >/dev/null 2>&1 || die 'deactivate failed' + +# Attempt to use 'lts' without '--' and capture the error message +ERROR_OUTPUT=$(nvm use lts 2>&1) || true + +EXPECTED_ERROR="You need to run \`nvm install --lts\` to install and \`nvm use --lts\` to use it." + +# Check if the error message matches the expected output +echo "$ERROR_OUTPUT" | grep -q "$EXPECTED_ERROR" \ + || die "Expected error message not found. Got: $ERROR_OUTPUT" \ No newline at end of file