Browse Source

migrate e2e tests to nodejs (#849)

resolves #848
remotes/origin/feat/support-install-latest
Gal Schlezinger 2 years ago committed by GitHub
parent
commit
bedb9555fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 136
      .github/workflows/rust.yml
  2. 269
      e2e/__snapshots__/aliases.test.ts.snap
  3. 284
      e2e/__snapshots__/basic.test.ts.snap
  4. 96
      e2e/__snapshots__/current.test.ts.snap
  5. 70
      e2e/__snapshots__/exec.test.ts.snap
  6. 28
      e2e/__snapshots__/existing-installation.test.ts.snap
  7. 32
      e2e/__snapshots__/latest-lts.test.ts.snap
  8. 127
      e2e/__snapshots__/log-level.test.ts.snap
  9. 67
      e2e/__snapshots__/multishell.test.ts.snap
  10. 32
      e2e/__snapshots__/nvmrc-lts.test.ts.snap
  11. 46
      e2e/__snapshots__/uninstall.test.ts.snap
  12. 129
      e2e/aliases.test.ts
  13. 93
      e2e/basic.test.ts
  14. 47
      e2e/current.test.ts
  15. 15
      e2e/describe.ts
  16. 42
      e2e/exec.test.ts
  17. 22
      e2e/existing-installation.test.ts
  18. 19
      e2e/latest-lts.test.ts
  19. 71
      e2e/log-level.test.ts
  20. 27
      e2e/multishell.test.ts
  21. 24
      e2e/nvmrc-lts.test.ts
  22. 3
      e2e/shellcode/get-stderr.ts
  23. 170
      e2e/shellcode/script.ts
  24. 12
      e2e/shellcode/shells/cmdCall.ts
  25. 32
      e2e/shellcode/shells/cmdEnv.ts
  26. 52
      e2e/shellcode/shells/expect-command-output.ts
  27. 100
      e2e/shellcode/shells/index.ts
  28. 24
      e2e/shellcode/shells/output-contains.ts
  29. 13
      e2e/shellcode/shells/redirect-output.ts
  30. 20
      e2e/shellcode/shells/sub-shell.ts
  31. 15
      e2e/shellcode/shells/types.ts
  32. 9
      e2e/shellcode/test-bin-dir.ts
  33. 9
      e2e/shellcode/test-cwd.ts
  34. 10
      e2e/shellcode/test-node-version.ts
  35. 15
      e2e/shellcode/test-tmp-dir.ts
  36. 38
      e2e/system-node.test.ts
  37. 29
      e2e/uninstall.test.ts
  38. 28
      package.json
  39. 2276
      pnpm-lock.yaml
  40. 2
      src/archive/zip.rs
  41. 2
      src/commands/env.rs
  42. 2
      src/commands/exec.rs
  43. 2
      src/commands/ls_local.rs
  44. 2
      src/commands/unalias.rs
  45. 4
      src/commands/use.rs
  46. 4
      tests/e2e.rs
  47. 28
      tests/feature_tests/aliases.rs
  48. 28
      tests/feature_tests/current.rs
  49. 254
      tests/feature_tests/mod.rs
  50. 17
      tests/feature_tests/snapshots/e2e__feature_tests__alias_system__Bash.snap
  51. 14
      tests/feature_tests/snapshots/e2e__feature_tests__alias_system__Fish.snap
  52. 15
      tests/feature_tests/snapshots/e2e__feature_tests__alias_system__PowerShell.snap
  53. 15
      tests/feature_tests/snapshots/e2e__feature_tests__alias_system__Zsh.snap
  54. 32
      tests/feature_tests/snapshots/e2e__feature_tests__aliases__Bash.snap
  55. 29
      tests/feature_tests/snapshots/e2e__feature_tests__aliases__Fish.snap
  56. 30
      tests/feature_tests/snapshots/e2e__feature_tests__aliases__PowerShell.snap
  57. 30
      tests/feature_tests/snapshots/e2e__feature_tests__aliases__Zsh.snap
  58. 14
      tests/feature_tests/snapshots/e2e__feature_tests__basic__Bash.snap
  59. 11
      tests/feature_tests/snapshots/e2e__feature_tests__basic__Fish.snap
  60. 12
      tests/feature_tests/snapshots/e2e__feature_tests__basic__PowerShell.snap
  61. 12
      tests/feature_tests/snapshots/e2e__feature_tests__basic__WinCmd.snap
  62. 12
      tests/feature_tests/snapshots/e2e__feature_tests__basic__Zsh.snap
  63. 32
      tests/feature_tests/snapshots/e2e__feature_tests__current__Bash.snap
  64. 29
      tests/feature_tests/snapshots/e2e__feature_tests__current__Fish.snap
  65. 30
      tests/feature_tests/snapshots/e2e__feature_tests__current__PowerShell.snap
  66. 33
      tests/feature_tests/snapshots/e2e__feature_tests__current__WinCmd.snap
  67. 30
      tests/feature_tests/snapshots/e2e__feature_tests__current__Zsh.snap
  68. 26
      tests/feature_tests/snapshots/e2e__feature_tests__exec__Bash.snap
  69. 23
      tests/feature_tests/snapshots/e2e__feature_tests__exec__Fish.snap
  70. 24
      tests/feature_tests/snapshots/e2e__feature_tests__exec__PowerShell.snap
  71. 26
      tests/feature_tests/snapshots/e2e__feature_tests__exec__WinCmd.snap
  72. 24
      tests/feature_tests/snapshots/e2e__feature_tests__exec__Zsh.snap
  73. 10
      tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__Bash.snap
  74. 7
      tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__Fish.snap
  75. 8
      tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__PowerShell.snap
  76. 8
      tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__Zsh.snap
  77. 11
      tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__Bash.snap
  78. 8
      tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__Fish.snap
  79. 9
      tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__PowerShell.snap
  80. 9
      tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__Zsh.snap
  81. 9
      tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__Bash.snap
  82. 6
      tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__Fish.snap
  83. 7
      tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__PowerShell.snap
  84. 6
      tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__WinCmd.snap
  85. 7
      tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__Zsh.snap
  86. 30
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__Bash.snap
  87. 27
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__Fish.snap
  88. 28
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__PowerShell.snap
  89. 28
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__Zsh.snap
  90. 22
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__Bash.snap
  91. 19
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__Fish.snap
  92. 20
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__PowerShell.snap
  93. 20
      tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__Zsh.snap
  94. 16
      tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__Bash.snap
  95. 13
      tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__Fish.snap
  96. 14
      tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__PowerShell.snap
  97. 14
      tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__WinCmd.snap
  98. 14
      tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__Zsh.snap
  99. 25
      tests/feature_tests/snapshots/e2e__feature_tests__multishell__Bash.snap
  100. 20
      tests/feature_tests/snapshots/e2e__feature_tests__multishell__Fish.snap
  101. Some files were not shown because too many files have changed in this diff Show More

136
.github/workflows/rust.yml

@ -6,6 +6,10 @@ on: @@ -6,6 +6,10 @@ on:
branches:
- master
concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true
jobs:
fmt:
runs-on: ubuntu-latest
@ -41,27 +45,7 @@ jobs: @@ -41,27 +45,7 @@ jobs:
- uses: Swatinem/rust-cache@v1
- uses: actions/checkout@v3
- name: Run tests
run: cargo test -- --skip=feature_tests
e2e_tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- name: Install Fish and Zsh using brew
if: "startsWith(matrix.os, 'macOS')"
run: brew install fish zsh
- name: Install Fish and Zsh using apt
if: "startsWith(matrix.os, 'ubuntu')"
run: sudo apt-get install -y fish zsh
- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- uses: Swatinem/rust-cache@v1
- uses: actions/checkout@v3
- name: Run tests
run: cargo test -- feature_tests
run: cargo test
build_release:
runs-on: windows-latest
@ -103,6 +87,116 @@ jobs: @@ -103,6 +87,116 @@ jobs:
name: fnm-macos
path: target/release/fnm
e2e_macos:
runs-on: macos-latest
needs: [build_macos_release]
name: "e2e/macos"
steps:
- name: install necessary shells
run: brew install fish zsh bash
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: fnm-macos
path: target/release
- name: mark binary as executable
run: chmod +x target/release/fnm
- uses: pnpm/action-setup@v2.2.2
with:
run_install: false
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'pnpm'
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install
- run: pnpm test
env:
FNM_TARGET_NAME: "release"
FORCE_COLOR: "1"
e2e_windows:
runs-on: windows-latest
needs: [build_release]
name: "e2e/windows"
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: fnm-windows
path: target/release
- uses: pnpm/action-setup@v2.2.2
with:
run_install: false
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'pnpm'
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install
- run: pnpm test
env:
FNM_TARGET_NAME: "release"
FORCE_COLOR: "1"
e2e_linux:
runs-on: ubuntu-latest
needs: [build_static_linux_binary]
name: "e2e/linux"
steps:
- name: install necessary shells
run: sudo apt-get update && sudo apt-get install -y fish zsh bash
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: fnm-linux
path: target/release
- name: mark binary as executable
run: chmod +x target/release/fnm
- uses: pnpm/action-setup@v2.2.2
with:
run_install: false
- uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'pnpm'
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- run: pnpm install
- run: pnpm test
env:
FNM_TARGET_NAME: "release"
FORCE_COLOR: "1"
build_static_linux_binary:
name: "Build static Linux binary"
runs-on: ubuntu-latest

269
e2e/__snapshots__/aliases.test.ts.snap

@ -0,0 +1,269 @@ @@ -0,0 +1,269 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash aliasing versions: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
((fnm ls) | grep 8.11.3 || (echo "Expected output to contain 8.11.3" && exit 1)) | grep oldie || (echo "Expected output to contain oldie" && exit 1)
((fnm ls) | grep 6.11.3 || (echo "Expected output to contain 6.11.3" && exit 1)) | grep older || (echo "Expected output to contain older" && exit 1)
fnm use older
if [ "$(node --version)" != "v6.11.3" ]; then
echo "Expected node version to be v6.11.3. Got $(node --version)"
exit 1
fi
fnm use oldie
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi
fnm use default
if [ "$(node --version)" != "v6.11.3" ]; then
echo "Expected node version to be v6.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Bash allows to install an lts if version missing: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm use --install-if-missing
(fnm ls) | grep lts-latest || (echo "Expected output to contain lts-latest" && exit 1)"
`;
exports[`Bash can alias the system node: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm alias system my_system
(fnm ls) | grep my_system || (echo "Expected output to contain my_system" && exit 1)
fnm alias system default
fnm alias my_system my_system2
(fnm ls) | grep my_system2 || (echo "Expected output to contain my_system2" && exit 1)
(fnm use my_system) | grep 'Bypassing fnm' || (echo "Expected output to contain 'Bypassing fnm'" && exit 1)
fnm unalias my_system
(fnm use my_system 2>&1) | grep 'Requested version my_system is not currently installed' || (echo "Expected output to contain 'Requested version my_system is not currently installed'" && exit 1)"
`;
exports[`Bash errors when alias is not found: Bash 1`] = `
"set -e
eval "$(fnm env --log-level=error)"
(fnm use 2>&1) | grep 'Requested version lts-latest is not' || (echo "Expected output to contain 'Requested version lts-latest is not'" && exit 1)"
`;
exports[`Bash unalias a version: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install 11.10.0
fnm install 8.11.3
fnm alias 8.11.3 version8
(fnm ls) | grep version8 || (echo "Expected output to contain version8" && exit 1)
fnm unalias version8
(fnm use version8 2>&1) | grep 'Requested version version8 is not currently installed' || (echo "Expected output to contain 'Requested version version8 is not currently installed'" && exit 1)"
`;
exports[`Bash unalias errors if alias not found: Bash 1`] = `
"set -e
eval "$(fnm env --log-level=error)"
(fnm unalias lts 2>&1) | grep 'Requested alias lts not found' || (echo "Expected output to contain 'Requested alias lts not found'" && exit 1)"
`;
exports[`Fish aliasing versions: Fish 1`] = `
"fnm env | source
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
begin; begin; fnm ls; end | grep 8.11.3; or echo "Expected output to contain 8.11.3" && exit 1; end | grep oldie; or echo "Expected output to contain oldie" && exit 1
begin; begin; fnm ls; end | grep 6.11.3; or echo "Expected output to contain 6.11.3" && exit 1; end | grep older; or echo "Expected output to contain older" && exit 1
fnm use older
set ____test____ (node --version)
if test "$____test____" != "v6.11.3"
echo "Expected node version to be v6.11.3. Got $____test____"
exit 1
end
fnm use oldie
set ____test____ (node --version)
if test "$____test____" != "v8.11.3"
echo "Expected node version to be v8.11.3. Got $____test____"
exit 1
end
fnm use default
set ____test____ (node --version)
if test "$____test____" != "v6.11.3"
echo "Expected node version to be v6.11.3. Got $____test____"
exit 1
end"
`;
exports[`Fish allows to install an lts if version missing: Fish 1`] = `
"fnm env | source
fnm use --install-if-missing
begin; fnm ls; end | grep lts-latest; or echo "Expected output to contain lts-latest" && exit 1"
`;
exports[`Fish can alias the system node: Fish 1`] = `
"fnm env | source
fnm alias system my_system
begin; fnm ls; end | grep my_system; or echo "Expected output to contain my_system" && exit 1
fnm alias system default
fnm alias my_system my_system2
begin; fnm ls; end | grep my_system2; or echo "Expected output to contain my_system2" && exit 1
begin; fnm use my_system; end | grep 'Bypassing fnm'; or echo "Expected output to contain 'Bypassing fnm'" && exit 1
fnm unalias my_system
begin; fnm use my_system 2>&1; end | grep 'Requested version my_system is not currently installed'; or echo "Expected output to contain 'Requested version my_system is not currently installed'" && exit 1"
`;
exports[`Fish errors when alias is not found: Fish 1`] = `
"fnm env --log-level=error | source
begin; fnm use 2>&1; end | grep 'Requested version lts-latest is not'; or echo "Expected output to contain 'Requested version lts-latest is not'" && exit 1"
`;
exports[`Fish unalias a version: Fish 1`] = `
"fnm env | source
fnm install 11.10.0
fnm install 8.11.3
fnm alias 8.11.3 version8
begin; fnm ls; end | grep version8; or echo "Expected output to contain version8" && exit 1
fnm unalias version8
begin; fnm use version8 2>&1; end | grep 'Requested version version8 is not currently installed'; or echo "Expected output to contain 'Requested version version8 is not currently installed'" && exit 1"
`;
exports[`Fish unalias errors if alias not found: Fish 1`] = `
"fnm env --log-level=error | source
begin; fnm unalias lts 2>&1; end | grep 'Requested alias lts not found'; or echo "Expected output to contain 'Requested alias lts not found'" && exit 1"
`;
exports[`PowerShell aliasing versions: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
$($__out__ = $($($__out__ = $(fnm ls | Select-String 8.11.3); if ($__out__ -eq $null) { exit 1 } else { $__out__ }) | Select-String oldie); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
$($__out__ = $($($__out__ = $(fnm ls | Select-String 6.11.3); if ($__out__ -eq $null) { exit 1 } else { $__out__ }) | Select-String older); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
fnm use older
if ( "$(node --version)" -ne "v6.11.3" ) { echo "Expected node version to be v6.11.3. Got $(node --version)"; exit 1 }
fnm use oldie
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }
fnm use default
if ( "$(node --version)" -ne "v6.11.3" ) { echo "Expected node version to be v6.11.3. Got $(node --version)"; exit 1 }"
`;
exports[`PowerShell allows to install an lts if version missing: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm use --install-if-missing
$($__out__ = $(fnm ls | Select-String lts-latest); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`PowerShell can alias the system node: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm alias system my_system
$($__out__ = $(fnm ls | Select-String my_system); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
fnm alias system default
fnm alias my_system my_system2
$($__out__ = $(fnm ls | Select-String my_system2); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
$($__out__ = $(fnm use my_system | Select-String 'Bypassing fnm'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
fnm unalias my_system
$($__out__ = $(fnm use my_system 2>&1 | Select-String 'Requested version my_system is not currently installed'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`PowerShell errors when alias is not found: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --log-level=error | Out-String | Invoke-Expression
$($__out__ = $(fnm use 2>&1 | Select-String 'Requested version lts-latest is not'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`PowerShell unalias a version: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install 11.10.0
fnm install 8.11.3
fnm alias 8.11.3 version8
$($__out__ = $(fnm ls | Select-String version8); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
fnm unalias version8
$($__out__ = $(fnm use version8 2>&1 | Select-String 'Requested version version8 is not currently installed'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`PowerShell unalias errors if alias not found: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --log-level=error | Out-String | Invoke-Expression
$($__out__ = $(fnm unalias lts 2>&1 | Select-String 'Requested alias lts not found'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`Zsh aliasing versions: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
((fnm ls) | grep 8.11.3 || (echo "Expected output to contain 8.11.3" && exit 1)) | grep oldie || (echo "Expected output to contain oldie" && exit 1)
((fnm ls) | grep 6.11.3 || (echo "Expected output to contain 6.11.3" && exit 1)) | grep older || (echo "Expected output to contain older" && exit 1)
fnm use older
if [ "$(node --version)" != "v6.11.3" ]; then
echo "Expected node version to be v6.11.3. Got $(node --version)"
exit 1
fi
fnm use oldie
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi
fnm use default
if [ "$(node --version)" != "v6.11.3" ]; then
echo "Expected node version to be v6.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Zsh allows to install an lts if version missing: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm use --install-if-missing
(fnm ls) | grep lts-latest || (echo "Expected output to contain lts-latest" && exit 1)"
`;
exports[`Zsh can alias the system node: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm alias system my_system
(fnm ls) | grep my_system || (echo "Expected output to contain my_system" && exit 1)
fnm alias system default
fnm alias my_system my_system2
(fnm ls) | grep my_system2 || (echo "Expected output to contain my_system2" && exit 1)
(fnm use my_system) | grep 'Bypassing fnm' || (echo "Expected output to contain 'Bypassing fnm'" && exit 1)
fnm unalias my_system
(fnm use my_system 2>&1) | grep 'Requested version my_system is not currently installed' || (echo "Expected output to contain 'Requested version my_system is not currently installed'" && exit 1)"
`;
exports[`Zsh errors when alias is not found: Zsh 1`] = `
"set -e
eval "$(fnm env --log-level=error)"
(fnm use 2>&1) | grep 'Requested version lts-latest is not' || (echo "Expected output to contain 'Requested version lts-latest is not'" && exit 1)"
`;
exports[`Zsh unalias a version: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install 11.10.0
fnm install 8.11.3
fnm alias 8.11.3 version8
(fnm ls) | grep version8 || (echo "Expected output to contain version8" && exit 1)
fnm unalias version8
(fnm use version8 2>&1) | grep 'Requested version version8 is not currently installed' || (echo "Expected output to contain 'Requested version version8 is not currently installed'" && exit 1)"
`;
exports[`Zsh unalias errors if alias not found: Zsh 1`] = `
"set -e
eval "$(fnm env --log-level=error)"
(fnm unalias lts 2>&1) | grep 'Requested alias lts not found' || (echo "Expected output to contain 'Requested alias lts not found'" && exit 1)"
`;

284
e2e/__snapshots__/basic.test.ts.snap

@ -0,0 +1,284 @@ @@ -0,0 +1,284 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash .node-version: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Bash .nvmrc: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Bash \`fnm ls\` with nothing installed: Bash 1`] = `
"set -e
eval "$(fnm env)"
if [ "$(fnm ls)" != "* system" ]; then
echo "Expected fnm ls to be * system. Got $(fnm ls)"
exit 1
fi"
`;
exports[`Bash basic usage: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
fnm use v8.11.3
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Bash resolves partial semver: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install 6
fnm use 6
if [ "$(node --version)" != "v6.17.1" ]; then
echo "Expected node version to be v6.17.1. Got $(node --version)"
exit 1
fi"
`;
exports[`Bash use on cd: Bash 1`] = `
"set -e
eval "$(fnm env --use-on-cd)"
fnm install v8.11.3
fnm install v12.22.12
cd subdir
if [ "$(node --version)" != "v12.22.12" ]; then
echo "Expected node version to be v12.22.12. Got $(node --version)"
exit 1
fi"
`;
exports[`Bash when .node-version and .nvmrc are in sync, it throws no error: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
if [ "$(node --version)" != "v11.10.0" ]; then
echo "Expected node version to be v11.10.0. Got $(node --version)"
exit 1
fi"
`;
exports[`Fish .node-version: Fish 1`] = `
"fnm env | source
fnm install
fnm use
set ____test____ (node --version)
if test "$____test____" != "v8.11.3"
echo "Expected node version to be v8.11.3. Got $____test____"
exit 1
end"
`;
exports[`Fish .nvmrc: Fish 1`] = `
"fnm env | source
fnm install
fnm use
set ____test____ (node --version)
if test "$____test____" != "v8.11.3"
echo "Expected node version to be v8.11.3. Got $____test____"
exit 1
end"
`;
exports[`Fish \`fnm ls\` with nothing installed: Fish 1`] = `
"fnm env | source
set ____test____ (fnm ls)
if test "$____test____" != "* system"
echo "Expected fnm ls to be * system. Got $____test____"
exit 1
end"
`;
exports[`Fish basic usage: Fish 1`] = `
"fnm env | source
fnm install v8.11.3
fnm use v8.11.3
set ____test____ (node --version)
if test "$____test____" != "v8.11.3"
echo "Expected node version to be v8.11.3. Got $____test____"
exit 1
end"
`;
exports[`Fish resolves partial semver: Fish 1`] = `
"fnm env | source
fnm install 6
fnm use 6
set ____test____ (node --version)
if test "$____test____" != "v6.17.1"
echo "Expected node version to be v6.17.1. Got $____test____"
exit 1
end"
`;
exports[`Fish use on cd: Fish 1`] = `
"fnm env --use-on-cd | source
fnm install v8.11.3
fnm install v12.22.12
cd subdir
set ____test____ (node --version)
if test "$____test____" != "v12.22.12"
echo "Expected node version to be v12.22.12. Got $____test____"
exit 1
end"
`;
exports[`Fish when .node-version and .nvmrc are in sync, it throws no error: Fish 1`] = `
"fnm env | source
fnm install
fnm use
set ____test____ (node --version)
if test "$____test____" != "v11.10.0"
echo "Expected node version to be v11.10.0. Got $____test____"
exit 1
end"
`;
exports[`PowerShell .node-version: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install
fnm use
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }"
`;
exports[`PowerShell .nvmrc: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install
fnm use
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }"
`;
exports[`PowerShell \`fnm ls\` with nothing installed: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
if ( "$(fnm ls)" -ne "* system" ) { echo "Expected fnm ls to be * system. Got $(fnm ls)"; exit 1 }"
`;
exports[`PowerShell basic usage: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install v8.11.3
fnm use v8.11.3
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }"
`;
exports[`PowerShell resolves partial semver: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install 6
fnm use 6
if ( "$(node --version)" -ne "v6.17.1" ) { echo "Expected node version to be v6.17.1. Got $(node --version)"; exit 1 }"
`;
exports[`PowerShell use on cd: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --use-on-cd | Out-String | Invoke-Expression
fnm install v8.11.3
fnm install v12.22.12
cd subdir
if ( "$(node --version)" -ne "v12.22.12" ) { echo "Expected node version to be v12.22.12. Got $(node --version)"; exit 1 }"
`;
exports[`PowerShell when .node-version and .nvmrc are in sync, it throws no error: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install
fnm use
if ( "$(node --version)" -ne "v11.10.0" ) { echo "Expected node version to be v11.10.0. Got $(node --version)"; exit 1 }"
`;
exports[`Zsh .node-version: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Zsh .nvmrc: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Zsh \`fnm ls\` with nothing installed: Zsh 1`] = `
"set -e
eval "$(fnm env)"
if [ "$(fnm ls)" != "* system" ]; then
echo "Expected fnm ls to be * system. Got $(fnm ls)"
exit 1
fi"
`;
exports[`Zsh basic usage: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
fnm use v8.11.3
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Zsh resolves partial semver: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install 6
fnm use 6
if [ "$(node --version)" != "v6.17.1" ]; then
echo "Expected node version to be v6.17.1. Got $(node --version)"
exit 1
fi"
`;
exports[`Zsh use on cd: Zsh 1`] = `
"set -e
eval "$(fnm env --use-on-cd)"
fnm install v8.11.3
fnm install v12.22.12
cd subdir
if [ "$(node --version)" != "v12.22.12" ]; then
echo "Expected node version to be v12.22.12. Got $(node --version)"
exit 1
fi"
`;
exports[`Zsh when .node-version and .nvmrc are in sync, it throws no error: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
if [ "$(node --version)" != "v11.10.0" ]; then
echo "Expected node version to be v11.10.0. Got $(node --version)"
exit 1
fi"
`;

96
e2e/__snapshots__/current.test.ts.snap

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash current returns the current Node.js version set in fnm: Bash 1`] = `
"set -e
eval "$(fnm env)"
if [ "$(fnm current)" != "none" ]; then
echo "Expected currently activated version to be none. Got $(fnm current)"
exit 1
fi
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if [ "$(fnm current)" != "v8.11.3" ]; then
echo "Expected currently activated version to be v8.11.3. Got $(fnm current)"
exit 1
fi
fnm use v10.10.0
if [ "$(fnm current)" != "v10.10.0" ]; then
echo "Expected currently activated version to be v10.10.0. Got $(fnm current)"
exit 1
fi
fnm use system
if [ "$(fnm current)" != "system" ]; then
echo "Expected currently activated version to be system. Got $(fnm current)"
exit 1
fi"
`;
exports[`Fish current returns the current Node.js version set in fnm: Fish 1`] = `
"fnm env | source
set ____test____ (fnm current)
if test "$____test____" != "none"
echo "Expected currently activated version to be none. Got $____test____"
exit 1
end
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
set ____test____ (fnm current)
if test "$____test____" != "v8.11.3"
echo "Expected currently activated version to be v8.11.3. Got $____test____"
exit 1
end
fnm use v10.10.0
set ____test____ (fnm current)
if test "$____test____" != "v10.10.0"
echo "Expected currently activated version to be v10.10.0. Got $____test____"
exit 1
end
fnm use system
set ____test____ (fnm current)
if test "$____test____" != "system"
echo "Expected currently activated version to be system. Got $____test____"
exit 1
end"
`;
exports[`PowerShell current returns the current Node.js version set in fnm: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
if ( "$(fnm current)" -ne "none" ) { echo "Expected currently activated version to be none. Got $(fnm current)"; exit 1 }
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if ( "$(fnm current)" -ne "v8.11.3" ) { echo "Expected currently activated version to be v8.11.3. Got $(fnm current)"; exit 1 }
fnm use v10.10.0
if ( "$(fnm current)" -ne "v10.10.0" ) { echo "Expected currently activated version to be v10.10.0. Got $(fnm current)"; exit 1 }
fnm use system
if ( "$(fnm current)" -ne "system" ) { echo "Expected currently activated version to be system. Got $(fnm current)"; exit 1 }"
`;
exports[`Zsh current returns the current Node.js version set in fnm: Zsh 1`] = `
"set -e
eval "$(fnm env)"
if [ "$(fnm current)" != "none" ]; then
echo "Expected currently activated version to be none. Got $(fnm current)"
exit 1
fi
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if [ "$(fnm current)" != "v8.11.3" ]; then
echo "Expected currently activated version to be v8.11.3. Got $(fnm current)"
exit 1
fi
fnm use v10.10.0
if [ "$(fnm current)" != "v10.10.0" ]; then
echo "Expected currently activated version to be v10.10.0. Got $(fnm current)"
exit 1
fi
fnm use system
if [ "$(fnm current)" != "system" ]; then
echo "Expected currently activated version to be system. Got $(fnm current)"
exit 1
fi"
`;

70
e2e/__snapshots__/exec.test.ts.snap

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash \`exec\` usage: Bash 1`] = `
"set -e
fnm install
fnm install v6.10.0
fnm install v10.10.0
if [ "$(fnm exec -- node -v)" != "v8.10.0" ]; then
echo "Expected version file exec to be v8.10.0. Got $(fnm exec -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=6 -- node -v)" != "v6.10.0" ]; then
echo "Expected exec:6 node -v to be v6.10.0. Got $(fnm exec --using=6 -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=10 -- node -v)" != "v10.10.0" ]; then
echo "Expected exec:6 node -v to be v10.10.0. Got $(fnm exec --using=10 -- node -v)"
exit 1
fi"
`;
exports[`Fish \`exec\` usage: Fish 1`] = `
"fnm install
fnm install v6.10.0
fnm install v10.10.0
set ____test____ (fnm exec -- node -v)
if test "$____test____" != "v8.10.0"
echo "Expected version file exec to be v8.10.0. Got $____test____"
exit 1
end
set ____test____ (fnm exec --using=6 -- node -v)
if test "$____test____" != "v6.10.0"
echo "Expected exec:6 node -v to be v6.10.0. Got $____test____"
exit 1
end
set ____test____ (fnm exec --using=10 -- node -v)
if test "$____test____" != "v10.10.0"
echo "Expected exec:6 node -v to be v10.10.0. Got $____test____"
exit 1
end"
`;
exports[`PowerShell \`exec\` usage: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm install
fnm install v6.10.0
fnm install v10.10.0
if ( "$(fnm exec -- node -v)" -ne "v8.10.0" ) { echo "Expected version file exec to be v8.10.0. Got $(fnm exec -- node -v)"; exit 1 }
if ( "$(fnm exec --using=6 -- node -v)" -ne "v6.10.0" ) { echo "Expected exec:6 node -v to be v6.10.0. Got $(fnm exec --using=6 -- node -v)"; exit 1 }
if ( "$(fnm exec --using=10 -- node -v)" -ne "v10.10.0" ) { echo "Expected exec:6 node -v to be v10.10.0. Got $(fnm exec --using=10 -- node -v)"; exit 1 }"
`;
exports[`Zsh \`exec\` usage: Zsh 1`] = `
"set -e
fnm install
fnm install v6.10.0
fnm install v10.10.0
if [ "$(fnm exec -- node -v)" != "v8.10.0" ]; then
echo "Expected version file exec to be v8.10.0. Got $(fnm exec -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=6 -- node -v)" != "v6.10.0" ]; then
echo "Expected exec:6 node -v to be v6.10.0. Got $(fnm exec --using=6 -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=10 -- node -v)" != "v10.10.0" ]; then
echo "Expected exec:6 node -v to be v10.10.0. Got $(fnm exec --using=10 -- node -v)"
exit 1
fi"
`;

28
e2e/__snapshots__/existing-installation.test.ts.snap

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash warns about an existing installation: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
(fnm install v8.11.3 2>&1) | grep 'already installed' || (echo "Expected output to contain 'already installed'" && exit 1)"
`;
exports[`Fish warns about an existing installation: Fish 1`] = `
"fnm env | source
fnm install v8.11.3
begin; fnm install v8.11.3 2>&1; end | grep 'already installed'; or echo "Expected output to contain 'already installed'" && exit 1"
`;
exports[`PowerShell warns about an existing installation: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install v8.11.3
$($__out__ = $(fnm install v8.11.3 2>&1 | Select-String 'already installed'); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`Zsh warns about an existing installation: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
(fnm install v8.11.3 2>&1) | grep 'already installed' || (echo "Expected output to contain 'already installed'" && exit 1)"
`;

32
e2e/__snapshots__/latest-lts.test.ts.snap

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash installs latest lts: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install --lts
(fnm ls) | grep lts-latest || (echo "Expected output to contain lts-latest" && exit 1)
fnm use 'lts/*'"
`;
exports[`Fish installs latest lts: Fish 1`] = `
"fnm env | source
fnm install --lts
begin; fnm ls; end | grep lts-latest; or echo "Expected output to contain lts-latest" && exit 1
fnm use 'lts/*'"
`;
exports[`PowerShell installs latest lts: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install --lts
$($__out__ = $(fnm ls | Select-String lts-latest); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
fnm use 'lts/*'"
`;
exports[`Zsh installs latest lts: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install --lts
(fnm ls) | grep lts-latest || (echo "Expected output to contain lts-latest" && exit 1)
fnm use 'lts/*'"
`;

127
e2e/__snapshots__/log-level.test.ts.snap

@ -0,0 +1,127 @@ @@ -0,0 +1,127 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash "quiet" log level: Bash 1`] = `
"set -e
eval "$(fnm env --log-level=quiet)"
if [ "$(fnm install v8.11.3)" != "" ]; then
echo "Expected fnm install to be . Got $(fnm install v8.11.3)"
exit 1
fi
if [ "$(fnm use v8.11.3)" != "" ]; then
echo "Expected fnm use to be . Got $(fnm use v8.11.3)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something)" != "" ]; then
echo "Expected fnm alias to be . Got $(fnm alias v8.11.3 something)"
exit 1
fi"
`;
exports[`Bash error log level: Bash 1`] = `
"set -e
eval "$(fnm env --log-level=error)"
if [ "$(fnm install v8.11.3)" != "" ]; then
echo "Expected fnm install to be . Got $(fnm install v8.11.3)"
exit 1
fi
if [ "$(fnm use v8.11.3)" != "" ]; then
echo "Expected fnm use to be . Got $(fnm use v8.11.3)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something)" != "" ]; then
echo "Expected fnm alias to be . Got $(fnm alias v8.11.3 something)"
exit 1
fi
(fnm alias abcd efg 2>&1) | grep "find requested version" || (echo "Expected output to contain "find requested version"" && exit 1)"
`;
exports[`Fish "quiet" log level: Fish 1`] = `
"fnm env --log-level=quiet | source
set ____test____ (fnm install v8.11.3)
if test "$____test____" != ""
echo "Expected fnm install to be . Got $____test____"
exit 1
end
set ____test____ (fnm use v8.11.3)
if test "$____test____" != ""
echo "Expected fnm use to be . Got $____test____"
exit 1
end
set ____test____ (fnm alias v8.11.3 something)
if test "$____test____" != ""
echo "Expected fnm alias to be . Got $____test____"
exit 1
end"
`;
exports[`Fish error log level: Fish 1`] = `
"fnm env --log-level=error | source
set ____test____ (fnm install v8.11.3)
if test "$____test____" != ""
echo "Expected fnm install to be . Got $____test____"
exit 1
end
set ____test____ (fnm use v8.11.3)
if test "$____test____" != ""
echo "Expected fnm use to be . Got $____test____"
exit 1
end
set ____test____ (fnm alias v8.11.3 something)
if test "$____test____" != ""
echo "Expected fnm alias to be . Got $____test____"
exit 1
end
begin; fnm alias abcd efg 2>&1; end | grep "find requested version"; or echo "Expected output to contain "find requested version"" && exit 1"
`;
exports[`PowerShell "quiet" log level: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --log-level=quiet | Out-String | Invoke-Expression
if ( "$(fnm install v8.11.3)" -ne "" ) { echo "Expected fnm install to be . Got $(fnm install v8.11.3)"; exit 1 }
if ( "$(fnm use v8.11.3)" -ne "" ) { echo "Expected fnm use to be . Got $(fnm use v8.11.3)"; exit 1 }
if ( "$(fnm alias v8.11.3 something)" -ne "" ) { echo "Expected fnm alias to be . Got $(fnm alias v8.11.3 something)"; exit 1 }"
`;
exports[`PowerShell error log level: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env --log-level=error | Out-String | Invoke-Expression
if ( "$(fnm install v8.11.3)" -ne "" ) { echo "Expected fnm install to be . Got $(fnm install v8.11.3)"; exit 1 }
if ( "$(fnm use v8.11.3)" -ne "" ) { echo "Expected fnm use to be . Got $(fnm use v8.11.3)"; exit 1 }
if ( "$(fnm alias v8.11.3 something)" -ne "" ) { echo "Expected fnm alias to be . Got $(fnm alias v8.11.3 something)"; exit 1 }
$($__out__ = $(fnm alias abcd efg 2>&1 | Select-String "find requested version"); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`Zsh "quiet" log level: Zsh 1`] = `
"set -e
eval "$(fnm env --log-level=quiet)"
if [ "$(fnm install v8.11.3)" != "" ]; then
echo "Expected fnm install to be . Got $(fnm install v8.11.3)"
exit 1
fi
if [ "$(fnm use v8.11.3)" != "" ]; then
echo "Expected fnm use to be . Got $(fnm use v8.11.3)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something)" != "" ]; then
echo "Expected fnm alias to be . Got $(fnm alias v8.11.3 something)"
exit 1
fi"
`;
exports[`Zsh error log level: Zsh 1`] = `
"set -e
eval "$(fnm env --log-level=error)"
if [ "$(fnm install v8.11.3)" != "" ]; then
echo "Expected fnm install to be . Got $(fnm install v8.11.3)"
exit 1
fi
if [ "$(fnm use v8.11.3)" != "" ]; then
echo "Expected fnm use to be . Got $(fnm use v8.11.3)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something)" != "" ]; then
echo "Expected fnm alias to be . Got $(fnm alias v8.11.3 something)"
exit 1
fi
(fnm alias abcd efg 2>&1) | grep "find requested version" || (echo "Expected output to contain "find requested version"" && exit 1)"
`;

67
e2e/__snapshots__/multishell.test.ts.snap

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash multishell changes don't affect parent: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
fnm install v11.9.0
echo 'set -e
eval "$(fnm env)"
fnm use v11
if [ "$(node --version)" != "v11.9.0" ]; then
echo "Expected node version to be v11.9.0. Got $(node --version)"
exit 1
fi' | bash
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;
exports[`Fish multishell changes don't affect parent: Fish 1`] = `
"fnm env | source
fnm install v8.11.3
fnm install v11.9.0
fish -c 'fnm env | source
fnm use v11
set ____test____ (node --version)
if test "$____test____" != "v11.9.0"
echo "Expected node version to be v11.9.0. Got $____test____"
exit 1
end'
set ____test____ (node --version)
if test "$____test____" != "v8.11.3"
echo "Expected node version to be v8.11.3. Got $____test____"
exit 1
end"
`;
exports[`PowerShell multishell changes don't affect parent: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install v8.11.3
fnm install v11.9.0
echo '$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm use v11
if ( "$(node --version)" -ne "v11.9.0" ) { echo "Expected node version to be v11.9.0. Got $(node --version)"; exit 1 }' | pwsh -NoProfile
if ( "$(node --version)" -ne "v8.11.3" ) { echo "Expected node version to be v8.11.3. Got $(node --version)"; exit 1 }"
`;
exports[`Zsh multishell changes don't affect parent: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install v8.11.3
fnm install v11.9.0
echo 'set -e
eval "$(fnm env)"
fnm use v11
if [ "$(node --version)" != "v11.9.0" ]; then
echo "Expected node version to be v11.9.0. Got $(node --version)"
exit 1
fi' | zsh
if [ "$(node --version)" != "v8.11.3" ]; then
echo "Expected node version to be v8.11.3. Got $(node --version)"
exit 1
fi"
`;

32
e2e/__snapshots__/nvmrc-lts.test.ts.snap

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash uses .nvmrc with lts definition: Bash 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
(fnm ls) | grep lts-dubnium || (echo "Expected output to contain lts-dubnium" && exit 1)"
`;
exports[`Fish uses .nvmrc with lts definition: Fish 1`] = `
"fnm env | source
fnm install
fnm use
begin; fnm ls; end | grep lts-dubnium; or echo "Expected output to contain lts-dubnium" && exit 1"
`;
exports[`PowerShell uses .nvmrc with lts definition: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install
fnm use
$($__out__ = $(fnm ls | Select-String lts-dubnium); if ($__out__ -eq $null) { exit 1 } else { $__out__ })"
`;
exports[`Zsh uses .nvmrc with lts definition: Zsh 1`] = `
"set -e
eval "$(fnm env)"
fnm install
fnm use
(fnm ls) | grep lts-dubnium || (echo "Expected output to contain lts-dubnium" && exit 1)"
`;

46
e2e/__snapshots__/uninstall.test.ts.snap

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Bash uninstalls a version: Bash 1`] = `
"set -e
fnm install 12.0.0
fnm alias 12.0.0 hello
((fnm ls) | grep v12.0.0 || (echo "Expected output to contain v12.0.0" && exit 1)) | grep hello || (echo "Expected output to contain hello" && exit 1)
fnm uninstall hello
if [ "$(fnm ls)" != "* system" ]; then
echo "Expected fnm ls to be * system. Got $(fnm ls)"
exit 1
fi"
`;
exports[`Fish uninstalls a version: Fish 1`] = `
"fnm install 12.0.0
fnm alias 12.0.0 hello
begin; begin; fnm ls; end | grep v12.0.0; or echo "Expected output to contain v12.0.0" && exit 1; end | grep hello; or echo "Expected output to contain hello" && exit 1
fnm uninstall hello
set ____test____ (fnm ls)
if test "$____test____" != "* system"
echo "Expected fnm ls to be * system. Got $____test____"
exit 1
end"
`;
exports[`PowerShell uninstalls a version: PowerShell 1`] = `
"$ErrorActionPreference = "Stop"
fnm install 12.0.0
fnm alias 12.0.0 hello
$($__out__ = $($($__out__ = $(fnm ls | Select-String v12.0.0); if ($__out__ -eq $null) { exit 1 } else { $__out__ }) | Select-String hello); if ($__out__ -eq $null) { exit 1 } else { $__out__ })
fnm uninstall hello
if ( "$(fnm ls)" -ne "* system" ) { echo "Expected fnm ls to be * system. Got $(fnm ls)"; exit 1 }"
`;
exports[`Zsh uninstalls a version: Zsh 1`] = `
"set -e
fnm install 12.0.0
fnm alias 12.0.0 hello
((fnm ls) | grep v12.0.0 || (echo "Expected output to contain v12.0.0" && exit 1)) | grep hello || (echo "Expected output to contain hello" && exit 1)
fnm uninstall hello
if [ "$(fnm ls)" != "* system" ]; then
echo "Expected fnm ls to be * system. Got $(fnm ls)"
exit 1
fi"
`;

129
e2e/aliases.test.ts

@ -0,0 +1,129 @@ @@ -0,0 +1,129 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import describe from "./describe"
import { writeFile } from "node:fs/promises"
import path from "node:path"
import testCwd from "./shellcode/test-cwd"
import getStderr from "./shellcode/get-stderr"
import testNodeVersion from "./shellcode/test-node-version"
for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test(`allows to install an lts if version missing`, async () => {
await writeFile(path.join(testCwd(), ".node-version"), "lts/*")
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["use", "--install-if-missing"]))
.then(
shell.scriptOutputContains(shell.call("fnm", ["ls"]), "lts-latest")
)
.takeSnapshot(shell)
.execute(shell)
})
test(`errors when alias is not found`, async () => {
await writeFile(path.join(testCwd(), ".node-version"), "lts/*")
await script(shell)
.then(shell.env({ logLevel: "error" }))
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["use"])),
"'Requested version lts-latest is not'"
)
)
.takeSnapshot(shell)
.execute(shell)
})
test(`unalias a version`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "11.10.0"]))
.then(shell.call("fnm", ["install", "8.11.3"]))
.then(shell.call("fnm", ["alias", "8.11.3", "version8"]))
.then(shell.scriptOutputContains(shell.call("fnm", ["ls"]), "version8"))
.then(shell.call("fnm", ["unalias", "version8"]))
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["use", "version8"])),
"'Requested version version8 is not currently installed'"
)
)
.takeSnapshot(shell)
.execute(shell)
})
test(`unalias errors if alias not found`, async () => {
await script(shell)
.then(shell.env({ logLevel: "error" }))
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["unalias", "lts"])),
"'Requested alias lts not found'"
)
)
.takeSnapshot(shell)
.execute(shell)
})
test(`can alias the system node`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["alias", "system", "my_system"]))
.then(
shell.scriptOutputContains(shell.call("fnm", ["ls"]), "my_system")
)
.then(shell.call("fnm", ["alias", "system", "default"]))
.then(shell.call("fnm", ["alias", "my_system", "my_system2"]))
.then(
shell.scriptOutputContains(shell.call("fnm", ["ls"]), "my_system2")
)
.then(
shell.scriptOutputContains(
shell.call("fnm", ["use", "my_system"]),
"'Bypassing fnm'"
)
)
.then(shell.call("fnm", ["unalias", "my_system"]))
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["use", "my_system"])),
"'Requested version my_system is not currently installed'"
)
)
.takeSnapshot(shell)
.execute(shell)
})
test(`aliasing versions`, async () => {
const installedVersions = shell.call("fnm", ["ls"])
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "6.11.3"]))
.then(shell.call("fnm", ["install", "8.11.3"]))
.then(shell.call("fnm", ["alias", "8.11", "oldie"]))
.then(shell.call("fnm", ["alias", "6", "older"]))
.then(shell.call("fnm", ["default", "older"]))
.then(
shell.scriptOutputContains(
shell.scriptOutputContains(installedVersions, "8.11.3"),
"oldie"
)
)
.then(
shell.scriptOutputContains(
shell.scriptOutputContains(installedVersions, "6.11.3"),
"older"
)
)
.then(shell.call("fnm", ["use", "older"]))
.then(testNodeVersion(shell, "v6.11.3"))
.then(shell.call("fnm", ["use", "oldie"]))
.then(testNodeVersion(shell, "v8.11.3"))
.then(shell.call("fnm", ["use", "default"]))
.then(testNodeVersion(shell, "v6.11.3"))
.takeSnapshot(shell)
.execute(shell)
})
})
}

93
e2e/basic.test.ts

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
import { writeFile, mkdir } from "node:fs/promises"
import { join } from "node:path"
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, WinCmd, Zsh } from "./shellcode/shells"
import testCwd from "./shellcode/test-cwd"
import testNodeVersion from "./shellcode/test-node-version"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) {
describe(shell, () => {
test(`basic usage`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(shell.call("fnm", ["use", "v8.11.3"]))
.then(testNodeVersion(shell, "v8.11.3"))
.takeSnapshot(shell)
.execute(shell)
})
test(`.nvmrc`, async () => {
await writeFile(join(testCwd(), ".nvmrc"), "v8.11.3")
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["use"]))
.then(testNodeVersion(shell, "v8.11.3"))
.takeSnapshot(shell)
.execute(shell)
})
test(`.node-version`, async () => {
await writeFile(join(testCwd(), ".node-version"), "v8.11.3")
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["use"]))
.then(testNodeVersion(shell, "v8.11.3"))
.takeSnapshot(shell)
.execute(shell)
})
test(`use on cd`, async () => {
await mkdir(join(testCwd(), "subdir"), { recursive: true })
await writeFile(join(testCwd(), "subdir", ".node-version"), "v12.22.12")
await script(shell)
.then(shell.env({ useOnCd: true }))
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(shell.call("fnm", ["install", "v12.22.12"]))
.then(shell.call("cd", ["subdir"]))
.then(testNodeVersion(shell, "v12.22.12"))
.takeSnapshot(shell)
.execute(shell)
})
test(`resolves partial semver`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "6"]))
.then(shell.call("fnm", ["use", "6"]))
.then(testNodeVersion(shell, "v6.17.1"))
.takeSnapshot(shell)
.execute(shell)
})
test("`fnm ls` with nothing installed", async () => {
await script(shell)
.then(shell.env({}))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["ls"]),
"* system",
"fnm ls"
)
)
.takeSnapshot(shell)
.execute(shell)
})
test(`when .node-version and .nvmrc are in sync, it throws no error`, async () => {
await writeFile(join(testCwd(), ".nvmrc"), "v11.10.0")
await writeFile(join(testCwd(), ".node-version"), "v11.10.0")
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["use"]))
.then(testNodeVersion(shell, "v11.10.0"))
.takeSnapshot(shell)
.execute(shell)
})
})
}

47
e2e/current.test.ts

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, WinCmd, Zsh } from "./shellcode/shells"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) {
describe(shell, () => {
test(`current returns the current Node.js version set in fnm`, async () => {
await script(shell)
.then(shell.env({}))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["current"]),
"none",
"currently activated version"
)
)
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(shell.call("fnm", ["install", "v10.10.0"]))
.then(shell.call("fnm", ["use", "v8.11.3"]))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["current"]),
"v8.11.3",
"currently activated version"
)
)
.then(shell.call("fnm", ["use", "v10.10.0"]))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["current"]),
"v10.10.0",
"currently activated version"
)
)
.then(shell.call("fnm", ["use", "system"]))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["current"]),
"system",
"currently activated version"
)
)
.takeSnapshot(shell)
.execute(shell)
})
})
}

15
e2e/describe.ts

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
import { WinCmd } from "./shellcode/shells"
import { Shell } from "./shellcode/shells/types"
export default function describe(
shell: Pick<Shell, "name">,
fn: () => void
): void {
if (shell === WinCmd) {
// wincmd tests do not work right now and I don't have a Windows machine to fix it
// maybe in the future when I have some time to spin a VM to check what's happening.
return globalThis.describe.skip("WinCmd", fn)
}
globalThis.describe(shell.name(), fn)
}

42
e2e/exec.test.ts

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, WinCmd, Zsh } from "./shellcode/shells"
import testCwd from "./shellcode/test-cwd"
import fs from "node:fs/promises"
import path from "node:path"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) {
describe(shell, () => {
test("`exec` usage", async () => {
await fs.writeFile(path.join(testCwd(), ".nvmrc"), "v8.10.0")
await script(shell)
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["install", "v6.10.0"]))
.then(shell.call("fnm", ["install", "v10.10.0"]))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["exec", "--", "node", "-v"]),
"v8.10.0",
"version file exec"
)
)
.then(
shell.hasCommandOutput(
shell.call("fnm", ["exec", "--using=6", "--", "node", "-v"]),
"v6.10.0",
"exec:6 node -v"
)
)
.then(
shell.hasCommandOutput(
shell.call("fnm", ["exec", "--using=10", "--", "node", "-v"]),
"v10.10.0",
"exec:6 node -v"
)
)
.takeSnapshot(shell)
.execute(shell)
})
})
}

22
e2e/existing-installation.test.ts

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
import getStderr from "./shellcode/get-stderr"
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test(`warns about an existing installation`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["install", "v8.11.3"])),
"'already installed'"
)
)
.takeSnapshot(shell)
.execute(shell)
})
})
}

19
e2e/latest-lts.test.ts

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test(`installs latest lts`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "--lts"]))
.then(
shell.scriptOutputContains(shell.call("fnm", ["ls"]), "lts-latest")
)
.then(shell.call("fnm", ["use", "'lts/*'"]))
.takeSnapshot(shell)
.execute(shell)
})
})
}

71
e2e/log-level.test.ts

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import describe from "./describe"
import getStderr from "./shellcode/get-stderr"
for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test(`"quiet" log level`, async () => {
await script(shell)
.then(shell.env({ logLevel: "quiet" }))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["install", "v8.11.3"]),
"",
"fnm install"
)
)
.then(
shell.hasCommandOutput(
shell.call("fnm", ["use", "v8.11.3"]),
"",
"fnm use"
)
)
.then(
shell.hasCommandOutput(
shell.call("fnm", ["alias", "v8.11.3", "something"]),
"",
"fnm alias"
)
)
.takeSnapshot(shell)
.execute(shell)
})
test("error log level", async () => {
await script(shell)
.then(shell.env({ logLevel: "error" }))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["install", "v8.11.3"]),
"",
"fnm install"
)
)
.then(
shell.hasCommandOutput(
shell.call("fnm", ["use", "v8.11.3"]),
"",
"fnm use"
)
)
.then(
shell.hasCommandOutput(
shell.call("fnm", ["alias", "v8.11.3", "something"]),
"",
"fnm alias"
)
)
.then(
shell.scriptOutputContains(
getStderr(shell.call("fnm", ["alias", "abcd", "efg"])),
`"find requested version"`
)
)
.takeSnapshot(shell)
.execute(shell)
})
})
}

27
e2e/multishell.test.ts

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import testNodeVersion from "./shellcode/test-node-version"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test(`multishell changes don't affect parent`, async () => {
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "v8.11.3"]))
.then(shell.call("fnm", ["install", "v11.9.0"]))
.then(
shell.inSubShell(
script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["use", "v11"]))
.then(testNodeVersion(shell, "v11.9.0"))
.asLine()
)
)
.then(testNodeVersion(shell, "v8.11.3"))
.takeSnapshot(shell)
.execute(shell)
})
})
}

24
e2e/nvmrc-lts.test.ts

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import fs from "node:fs/promises"
import path from "node:path"
import describe from "./describe"
import testCwd from "./shellcode/test-cwd"
for (const shell of [Bash, Fish, PowerShell, Zsh]) {
describe(shell, () => {
test(`uses .nvmrc with lts definition`, async () => {
await fs.writeFile(path.join(testCwd(), ".nvmrc"), `lts/dubnium`)
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install"]))
.then(shell.call("fnm", ["use"]))
.then(
shell.scriptOutputContains(shell.call("fnm", ["ls"]), "lts-dubnium")
)
.takeSnapshot(shell)
.execute(shell)
})
})
}

3
e2e/shellcode/get-stderr.ts

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
export default function getStderr(script: string): string {
return `${script} 2>&1`
}

170
e2e/shellcode/script.ts

@ -0,0 +1,170 @@ @@ -0,0 +1,170 @@
import { ScriptLine, Shell } from "./shells/types"
import execa from "execa"
import testTmpDir from "./test-tmp-dir"
import { Writable } from "node:stream"
import dedent from "ts-dedent"
import testCwd from "./test-cwd"
import path, { join } from "node:path"
import { writeFile } from "node:fs/promises"
import chalk from "chalk"
import testBinDir from "./test-bin-dir"
class Script {
constructor(
private readonly config: {
fnmDir: string
},
private readonly lines: ScriptLine[]
) {}
then(line: ScriptLine): Script {
return new Script(this.config, [...this.lines, line])
}
takeSnapshot(shell: Pick<Shell, "name">): this {
const script = this.lines.join("\n")
expect(script).toMatchSnapshot(shell.name())
return this
}
async execute(
shell: Pick<
Shell,
"binaryName" | "launchArgs" | "currentlySupported" | "forceFile"
>
): Promise<void> {
if (!shell.currentlySupported()) {
return
}
const args = [...shell.launchArgs()]
if (shell.forceFile) {
const filename = join(testTmpDir(), "script")
await writeFile(filename, [...this.lines, "exit 0"].join("\n"))
args.push(filename)
}
const child = execa(shell.binaryName(), args, {
stdio: [shell.forceFile ? "ignore" : "pipe", "pipe", "pipe"],
cwd: testCwd(),
env: {
...removeAllFnmEnvVars(process.env),
PATH: [testBinDir(), fnmTargetDir(), process.env.PATH]
.filter(Boolean)
.join(path.delimiter),
FNM_DIR: this.config.fnmDir,
},
extendEnv: false,
reject: false,
})
if (child.stdin) {
const childStdin = child.stdin
for (const line of this.lines) {
await write(childStdin, `${line}\n`)
}
await write(childStdin, "exit 0\n")
}
const { stdout, stderr } = streamOutputsAndBuffer(child)
const finished = await child
if (finished.failed) {
console.error(
dedent`
Script failed.
code ${finished.exitCode}
signal ${finished.signal}
stdout:
${padAllLines(stdout.join(""), 2)}
stderr:
${padAllLines(stderr.join(""), 2)}
`
)
throw new Error(
`Script failed on ${testCwd()} with code ${finished.exitCode}`
)
}
}
asLine(): ScriptLine {
return this.lines.join("\n")
}
}
function streamOutputsAndBuffer(child: execa.ExecaChildProcess) {
const stdout: string[] = []
const stderr: string[] = []
const testName = expect.getState().currentTestName ?? "unknown"
const testPath = expect.getState().testPath ?? "unknown"
const stdoutPrefix = chalk.yellow.dim(`[stdout] ${testPath}/${testName}: `)
const stderrPrefix = chalk.red.dim(`[stderr] ${testPath}/${testName}: `)
if (child.stdout) {
child.stdout.on("data", (data) => {
const line = data.toString().trim()
if (line) {
process.stdout.write(`${stdoutPrefix}${line}\n`)
}
stdout.push(data.toString())
})
}
if (child.stderr) {
child.stderr.on("data", (data) => {
const line = data.toString().trim()
if (line) {
process.stdout.write(`${stderrPrefix}${line}\n`)
}
stderr.push(data.toString())
})
}
return { stdout, stderr }
}
function padAllLines(text: string, padding: number): string {
return text
.split("\n")
.map((line) => " ".repeat(padding) + line)
.join("\n")
}
function write(writable: Writable, text: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
writable.write(text, (err) => {
if (err) return reject(err)
return resolve()
})
})
}
export function script(shell: Pick<Shell, "dieOnErrors">): Script {
const fnmDir = `${testTmpDir()}/fnm`
return new Script({ fnmDir }, shell.dieOnErrors ? [shell.dieOnErrors()] : [])
}
function removeAllFnmEnvVars(obj: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const result: NodeJS.ProcessEnv = {}
for (const [key, value] of Object.entries(obj)) {
if (!key.startsWith("FNM_")) {
result[key] = value
}
}
return result
}
function fnmTargetDir(): string {
return path.resolve(
__dirname,
`../../target/${process.env.FNM_TARGET_NAME ?? "debug"}`
)
}

12
e2e/shellcode/shells/cmdCall.ts

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
import { define, ScriptLine } from "./types"
export type HasCall = {
call: (binary: string, args: string[]) => ScriptLine
}
export const cmdCall = {
all: define<HasCall>({
call: (binary: string, args: string[]) =>
`${binary} ${args.join(" ")}` as ScriptLine,
}),
}

32
e2e/shellcode/shells/cmdEnv.ts

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
import { ScriptLine, define } from "./types"
type EnvConfig = { useOnCd: boolean; logLevel: string }
export type HasEnv = { env(cfg: Partial<EnvConfig>): ScriptLine }
function stringify(envConfig: Partial<EnvConfig> = {}) {
const { useOnCd, logLevel } = envConfig
return [
`fnm env`,
useOnCd && "--use-on-cd",
logLevel && `--log-level=${logLevel}`,
]
.filter(Boolean)
.join(" ")
}
export const cmdEnv = {
bash: define<HasEnv>({
env: (envConfig) => `eval "$(${stringify(envConfig)})"`,
}),
fish: define<HasEnv>({
env: (envConfig) => `${stringify(envConfig)} | source`,
}),
powershell: define<HasEnv>({
env: (envConfig) =>
`${stringify(envConfig)} | Out-String | Invoke-Expression`,
}),
wincmd: define<HasEnv>({
env: (envConfig) =>
`FOR /f "tokens=*" %i IN ('${stringify(envConfig)}') DO CALL %i`,
}),
}

52
e2e/shellcode/shells/expect-command-output.ts

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
import dedent from "ts-dedent"
import { define, ScriptLine } from "./types"
export type HasExpectCommandOutput = {
hasCommandOutput(
script: ScriptLine,
output: string,
message: string
): ScriptLine
}
export const cmdExpectCommandOutput = {
bash: define<HasExpectCommandOutput>({
hasCommandOutput(script, output, message) {
return dedent`
if [ "$(${script})" != "${output}" ]; then
echo "Expected ${message} to be ${output}. Got $(${script})"
exit 1
fi
`
},
}),
fish: define<HasExpectCommandOutput>({
hasCommandOutput(script, output, message) {
return dedent`
set ____test____ (${script})
if test "$____test____" != "${output}"
echo "Expected ${message} to be ${output}. Got $____test____"
exit 1
end
`
},
}),
powershell: define<HasExpectCommandOutput>({
hasCommandOutput(script, output, message) {
return dedent`
if ( "$(${script})" -ne "${output}" ) { echo "Expected ${message} to be ${output}. Got $(${script})"; exit 1 }
`
},
}),
wincmd: define<HasExpectCommandOutput>({
hasCommandOutput(script, output, message) {
return dedent`
${script} | findstr ${output}
if %errorlevel% neq 0 (
echo Expected ${message} to be ${output}
exit 1
)
`
},
}),
}

100
e2e/shellcode/shells/index.ts

@ -0,0 +1,100 @@ @@ -0,0 +1,100 @@
import { cmdCall } from "./cmdCall"
import { cmdEnv } from "./cmdEnv"
import { cmdExpectCommandOutput } from "./expect-command-output"
import { cmdHasOutputContains } from "./output-contains"
import { redirectOutput } from "./redirect-output"
import { cmdInSubShell } from "./sub-shell"
import { define, Shell } from "./types"
export const Bash = {
...define<Shell>({
binaryName: () => "bash",
currentlySupported: () => true,
name: () => "Bash",
launchArgs: () => ["-i"],
escapeText: (x) => x,
dieOnErrors: () => `set -e`,
}),
...cmdEnv.bash,
...cmdCall.all,
...redirectOutput.bash,
...cmdExpectCommandOutput.bash,
...cmdHasOutputContains.bash,
...cmdInSubShell.bash,
}
export const Zsh = {
...define<Shell>({
binaryName: () => "zsh",
currentlySupported: () => process.platform !== "win32",
name: () => "Zsh",
launchArgs: () => [],
escapeText: (x) => x,
dieOnErrors: () => `set -e`,
}),
...cmdEnv.bash,
...cmdCall.all,
...cmdExpectCommandOutput.bash,
...cmdHasOutputContains.bash,
...cmdInSubShell.zsh,
}
export const Fish = {
...define<Shell>({
binaryName: () => "fish",
currentlySupported: () => process.platform !== "win32",
name: () => "Fish",
launchArgs: () => [],
escapeText: (x) => x,
forceFile: true,
}),
...cmdEnv.fish,
...cmdCall.all,
...redirectOutput.bash,
...cmdExpectCommandOutput.fish,
...cmdHasOutputContains.fish,
...cmdInSubShell.fish,
}
export const PowerShell = {
...define<Shell>({
binaryName: () => {
if (process.platform === "win32") {
return "powershell.exe"
} else {
return "pwsh"
}
},
forceFile: true,
currentlySupported: () => true,
name: () => "PowerShell",
launchArgs: () => ["-NoProfile"],
escapeText: (x) => x,
dieOnErrors: () => `$ErrorActionPreference = "Stop"`,
}),
...cmdEnv.powershell,
...cmdCall.all,
...cmdExpectCommandOutput.powershell,
...cmdHasOutputContains.powershell,
...cmdInSubShell.powershell,
}
export const WinCmd = {
...define<Shell>({
binaryName: () => "cmd.exe",
currentlySupported: () => process.platform === "win32",
name: () => "Windows Command Prompt",
launchArgs: () => [],
escapeText: (str) =>
str
.replace(/\r/g, "")
.replace(/\n/g, "^\n\n")
.replace(/\%/g, "%%")
.replace(/\|/g, "^|")
.replace(/\(/g, "^(")
.replace(/\)/g, "^)"),
}),
...cmdEnv.wincmd,
...cmdCall.all,
...cmdExpectCommandOutput.wincmd,
}

24
e2e/shellcode/shells/output-contains.ts

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
import { define, ScriptLine } from "./types"
export type HasOutputContains = {
scriptOutputContains(script: ScriptLine, substring: string): ScriptLine
}
export const cmdHasOutputContains = {
bash: define<HasOutputContains>({
scriptOutputContains: (script, substring) => {
return `(${script}) | grep ${substring} || (echo "Expected output to contain ${substring}" && exit 1)`
},
}),
fish: define<HasOutputContains>({
scriptOutputContains: (script, substring) => {
return `begin; ${script}; end | grep ${substring}; or echo "Expected output to contain ${substring}" && exit 1`
},
}),
powershell: define<HasOutputContains>({
scriptOutputContains: (script, substring) => {
const inner: string = `${script} | Select-String ${substring}`
return `$($__out__ = $(${inner}); if ($__out__ -eq $null) { exit 1 } else { $__out__ })`
},
}),
}

13
e2e/shellcode/shells/redirect-output.ts

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
import { ScriptLine, define } from "./types"
type RedirectOutputOpts = { output: string }
export type HasRedirectOutput = {
redirectOutput(childCommand: ScriptLine, opts: RedirectOutputOpts): string
}
export const redirectOutput = {
bash: define<HasRedirectOutput>({
redirectOutput: (childCommand, opts) =>
`(${childCommand}) > ${opts.output}`,
}),
}

20
e2e/shellcode/shells/sub-shell.ts

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
import { ScriptLine, define } from "./types"
import quote from "shell-escape"
type HasInSubShell = { inSubShell: (script: ScriptLine) => ScriptLine }
export const cmdInSubShell = {
bash: define<HasInSubShell>({
inSubShell: (script) => `echo ${quote([script])} | bash`,
}),
zsh: define<HasInSubShell>({
inSubShell: (script) => `echo ${quote([script])} | zsh`,
}),
fish: define<HasInSubShell>({
inSubShell: (script) => `fish -c ${quote([script])}`,
}),
powershell: define<HasInSubShell>({
inSubShell: (script) =>
`echo '${script.replace(/'/g, "\\'")}' | pwsh -NoProfile`,
}),
}

15
e2e/shellcode/shells/types.ts

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
export type Shell = {
escapeText(str: string): string
binaryName(): string
currentlySupported(): boolean
name(): string
launchArgs(): string[]
dieOnErrors?(): string
forceFile?: true
}
export type ScriptLine = string
export function define<S>(s: S): S {
return s
}

9
e2e/shellcode/test-bin-dir.ts

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
import { mkdirSync } from "node:fs"
import path from "node:path"
import testTmpDir from "./test-tmp-dir"
export default function testBinDir() {
const dir = path.join(testTmpDir(), "bin")
mkdirSync(dir, { recursive: true })
return dir
}

9
e2e/shellcode/test-cwd.ts

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
import { mkdirSync } from "node:fs"
import path from "node:path"
import testTmpDir from "./test-tmp-dir"
export default function testCwd() {
const dir = path.join(testTmpDir(), "cwd")
mkdirSync(dir, { recursive: true })
return dir
}

10
e2e/shellcode/test-node-version.ts

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
import { HasCall } from "./shells/cmdCall"
import { ScriptLine } from "./shells/types"
import { HasExpectCommandOutput } from "./shells/expect-command-output"
export default function testNodeVersion<
S extends HasCall & HasExpectCommandOutput
>(shell: S, version: string): ScriptLine {
const nodeVersion = shell.call("node", ["--version"])
return shell.hasCommandOutput(nodeVersion, version, "node version")
}

15
e2e/shellcode/test-tmp-dir.ts

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
import { mkdirSync, rmSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
export default function testTmpDir(): string {
const testName = (expect.getState().currentTestName ?? "unknown")
.toLowerCase()
.replace(/[^a-z0-9]/gi, "_")
.replace(/_+/g, "_")
const tmpDir = join(tmpdir(), `shellcode/${testName}`)
mkdirSync(tmpDir, { recursive: true })
rmSync(join(tmpDir, "fnm/aliases"), { recursive: true, force: true })
return tmpDir
}

38
e2e/system-node.test.ts

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, WinCmd, Zsh } from "./shellcode/shells"
import fs from "node:fs/promises"
import path from "node:path"
import describe from "./describe"
import testNodeVersion from "./shellcode/test-node-version"
import testBinDir from "./shellcode/test-bin-dir"
for (const shell of [Bash, Fish, PowerShell, WinCmd, Zsh]) {
describe(shell, () => {
// latest bash breaks this as it seems. gotta find a solution.
const t = process.platform === "darwin" && shell === Bash ? test.skip : test
t(`switches to system node`, async () => {
const customNode = path.join(testBinDir(), "node")
if (
process.platform === "win32" &&
[WinCmd, PowerShell].includes(shell)
) {
await fs.writeFile(customNode + ".cmd", '@echo "custom node"')
} else {
await fs.writeFile(customNode, `#!/bin/bash\n\necho "custom"\n`)
// set executable
await fs.chmod(customNode, 0o766)
}
await script(shell)
.then(shell.env({}))
.then(shell.call("fnm", ["install", "v10.10.0"]))
.then(shell.call("fnm", ["use", "v10"]))
.then(testNodeVersion(shell, "v10.10.0"))
.then(shell.call("fnm", ["use", "system"]))
.then(testNodeVersion(shell, "custom"))
.execute(shell)
})
})
}

29
e2e/uninstall.test.ts

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
import { script } from "./shellcode/script"
import { Bash, Fish, PowerShell, Zsh } from "./shellcode/shells"
import describe from "./describe"
for (const shell of [Bash, Zsh, Fish, PowerShell]) {
describe(shell, () => {
test(`uninstalls a version`, async () => {
await script(shell)
.then(shell.call("fnm", ["install", "12.0.0"]))
.then(shell.call("fnm", ["alias", "12.0.0", "hello"]))
.then(
shell.scriptOutputContains(
shell.scriptOutputContains(shell.call("fnm", ["ls"]), "v12.0.0"),
"hello"
)
)
.then(shell.call("fnm", ["uninstall", "hello"]))
.then(
shell.hasCommandOutput(
shell.call("fnm", ["ls"]),
"* system",
"fnm ls"
)
)
.takeSnapshot(shell)
.execute(shell)
})
})
}

28
package.json

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
"packageManager": "pnpm@7.13.2",
"license": "GPLv3",
"scripts": {
"test": "jest --runInBand",
"version:prepare": "changeset version && ./.ci/prepare-version.js",
"generate-command-docs": "./.ci/print-command-docs.js"
},
@ -22,12 +23,37 @@ @@ -22,12 +23,37 @@
"devDependencies": {
"@changesets/cli": "2.25.0",
"@svitejs/changesets-changelog-github-compact": "0.1.1",
"@swc-node/jest": "^1.5.5",
"@swc/core": "^1.3.17",
"@types/jest": "^29.2.3",
"@types/node": "^18.11.9",
"@types/shell-escape": "^0.2.1",
"chalk": "4",
"cmd-ts": "0.11.0",
"execa": "5.1.1",
"jest": "^29.3.1",
"lerna-changelog": "2.2.0",
"p-retry": "^4",
"prettier": "2.7.1",
"pv": "1.0.1",
"shell-escape": "^0.2.0",
"svg-term-cli": "2.1.1",
"toml": "3.0.0"
"toml": "3.0.0",
"ts-dedent": "^2.2.0",
"typescript": "^4.8.4"
},
"prettier": {
"semi": false
},
"jest": {
"transform": {
"^.+\\.ts$": "@swc-node/jest"
},
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"js"
],
"testTimeout": 120000
}
}

2276
pnpm-lock.yaml

File diff suppressed because it is too large Load Diff

2
src/archive/zip.rs

@ -58,7 +58,7 @@ impl<R: Read> Extract for Zip<R> { @@ -58,7 +58,7 @@ impl<R: Read> Extract for Zip<R> {
);
if let Some(p) = outpath.parent() {
if !p.exists() {
fs::create_dir_all(&p)?;
fs::create_dir_all(p)?;
}
}
let mut outfile = fs::File::create(&outpath)?;

2
src/commands/env.rs

@ -61,7 +61,7 @@ impl Command for Env { @@ -61,7 +61,7 @@ impl Command for Env {
let shell: Box<dyn Shell> = self
.shell
.or_else(&infer_shell)
.or_else(infer_shell)
.ok_or(Error::CantInferShell)?;
let multishell_path = make_symlink(config)?;
let binary_path = if cfg!(windows) {

2
src/commands/exec.rs

@ -69,7 +69,7 @@ impl Cmd for Exec { @@ -69,7 +69,7 @@ impl Cmd for Exec {
.map_err(|source| Error::CantAddPathToEnvironment { source })?
};
let exit_status = Command::new(&binary)
let exit_status = Command::new(binary)
.args(arguments)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())

2
src/commands/ls_local.rs

@ -24,7 +24,7 @@ impl super::command::Command for LsLocal { @@ -24,7 +24,7 @@ impl super::command::Command for LsLocal {
for version in versions {
let version_aliases = match aliases_hash.get(&version.v_str()) {
None => "".into(),
None => String::new(),
Some(versions) => {
let version_string = versions
.iter()

2
src/commands/unalias.rs

@ -24,7 +24,7 @@ impl Command for Unalias { @@ -24,7 +24,7 @@ impl Command for Unalias {
requested_alias: self.requested_alias,
})?;
remove_symlink_dir(&requested_version.path())
remove_symlink_dir(requested_version.path())
.map_err(|source| Error::CantDeleteSymlink { source })?;
Ok(())

4
src/commands/use.rs

@ -150,8 +150,8 @@ fn install_new_version( @@ -150,8 +150,8 @@ fn install_new_version(
///
/// This way, we can create a symlink if it is missing.
fn replace_symlink(from: &std::path::Path, to: &std::path::Path) -> std::io::Result<()> {
let symlink_deletion_result = fs::remove_symlink_dir(&to);
match fs::symlink_dir(&from, &to) {
let symlink_deletion_result = fs::remove_symlink_dir(to);
match fs::symlink_dir(from, to) {
ok @ Ok(_) => ok,
err @ Err(_) => symlink_deletion_result.and(err),
}

4
tests/e2e.rs

@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
#[macro_use]
mod shellcode;
mod feature_tests;

28
tests/feature_tests/aliases.rs

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
use crate::shellcode::*;
fn installed_versions() -> Call {
Call::new("fnm", vec!["ls"])
}
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "6.11.3"]))
.then(Call::new("fnm", vec!["install", "8.11.3"]))
.then(Call::new("fnm", vec!["alias", "8.11", "oldie"]))
.then(Call::new("fnm", vec!["alias", "6", "older"]))
.then(Call::new("fnm", vec!["default", "older"]))
.then(OutputContains::new(
OutputContains::new(installed_versions(), "8.11.3"),
"oldie",
))
.then(OutputContains::new(
OutputContains::new(OutputContains::new(installed_versions(), "6.11.3"), "older"),
"default",
))
.then(Call::new("fnm", vec!["use", "older"]))
.then(test_node_version("v6.11.3"))
.then(Call::new("fnm", vec!["use", "oldie"]))
.then(test_node_version("v8.11.3"))
.then(Call::new("fnm", vec!["use", "default"]))
.then(test_node_version("v6.11.3"))
});

28
tests/feature_tests/current.rs

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
test_shell!(Bash, Zsh, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["current"]),
"none",
"currently activated version",
))
.then(Call::new("fnm", vec!["install", "v8.11.3"]))
.then(Call::new("fnm", vec!["install", "v10.10.0"]))
.then(Call::new("fnm", vec!["use", "v8.11.3"]))
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["current"]),
"v8.11.3",
"currently activated version",
))
.then(Call::new("fnm", vec!["use", "v10.10.0"]))
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["current"]),
"v10.10.0",
"currently activated version",
))
.then(Call::new("fnm", vec!["use", "system"]))
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["current"]),
"system",
"currently activated version",
))
});

254
tests/feature_tests/mod.rs

@ -1,254 +0,0 @@ @@ -1,254 +0,0 @@
mod aliases;
mod current;
mod uninstall;
use crate::shellcode::*;
mod basic {
test_shell!(Zsh, Bash, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "v8.11.3"]))
.then(Call::new("fnm", vec!["use", "v8.11.3"]))
.then(test_node_version("v8.11.3"))
});
}
mod nvmrc {
test_shell!(Zsh, Bash, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(WriteFile::new(".nvmrc", "v8.11.3"))
.then(Call::new("fnm", vec!["install"]))
.then(Call::new("fnm", vec!["use"]))
.then(test_node_version("v8.11.3"))
});
}
mod multishell {
test_shell!(Zsh, Bash, Fish, PowerShell; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "v8.11.3"]))
.then(Call::new("fnm", vec!["install", "v11.9.0"]))
.then(Call::new("fnm", vec!["use", "v8.11.3"]))
.then(SubShell::new(
DieOnErrors
.then(EvalFnmEnv::default())
.then(Call::new("fnm", vec!["use", "11"]))
.then(test_node_version("v11.9.0")),
))
.then(test_node_version("v8.11.3"))
});
}
mod use_on_cd_nvmrc {
test_shell!(Zsh, Bash, Fish, PowerShell; {
EvalFnmEnv::default()
.use_on_cd(true)
.then(Call::new("mkdir", vec!["inner_path"]))
.then(WriteFile::new("inner_path/.nvmrc", "v8.11.3"))
.then(Call::new("fnm", vec!["install", "v8.11.3"]))
.then(Call::new("cd", vec!["inner_path"]))
.then(test_node_version("v8.11.3"))
});
}
mod use_on_cd_dot_node_version {
test_shell!(Zsh, Bash, Fish, PowerShell; {
EvalFnmEnv::default()
.use_on_cd(true)
.then(Call::new("mkdir", vec!["inner_path"]))
.then(WriteFile::new("inner_path/.node-version", "v8.11.3"))
.then(Call::new("fnm", vec!["install", "v8.11.3"]))
.then(Call::new("cd", vec!["inner_path"]))
.then(test_node_version("v8.11.3"))
});
}
// mod node_dist_mirror {
// test_shell!(Zsh, Bash, Fish, PowerShell, {
// EvalFnmEnv::default()
// .node_dist_mirror(Some("https://npm.taobao.org/mirrors/node"))
// .then(Call::new("fnm", vec!["install", "v8.11.3"]))
// .then(Call::new("fnm", vec!["use", "v8.11.3"]))
// .then(test_node_version("v8.11.3"))
// });
// }
mod exec {
test_shell!(Zsh, Bash, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(WriteFile::new(".nvmrc", "v8.10.0"))
.then(Call::new("fnm", vec!["install"]))
.then(Call::new("fnm", vec!["install", "v6.10.0"]))
.then(Call::new("fnm", vec!["install", "v10.10.0"]))
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["exec", "--", "node", "-v"]),
"v8.10.0",
"version file exec",
))
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["exec", "--using=6", "--", "node", "-v"]),
"v6.10.0",
"exec:6 node -v",
))
.then(ExpectCommandOutput::new(
Call::new("fnm", vec!["exec", "--using=10", "--", "node", "-v"]),
"v10.10.0",
"exec:6 node -v",
))
});
}
mod existing_installation {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "v8.11.3"]))
.then(OutputContains::new(
IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["install", "v8.11.3"]))),
"already installed",
))
});
}
mod system_node {
test_shell!(Bash, Zsh, Fish, PowerShell; |path: &std::path::Path| {
use std::io::Write;
let custom_node_dir = path.join("bin");
std::fs::create_dir(&custom_node_dir).unwrap();
std::fs::write(custom_node_dir.join("node.cmd"), b"echo custom node").unwrap();
let mut f = std::fs::File::create(custom_node_dir.join("node")).unwrap();
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mut permissions = f.metadata().unwrap().permissions();
permissions.set_mode(0o766);
f.set_permissions(permissions).expect("Can't set file permissions");
}
writeln!(f, "#!/bin/sh").expect("Can't write file");
writeln!(f, r#"echo "custom node""#).expect("Can't write file");
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "10"]))
.then(Call::new("fnm", vec!["use", "10"]))
.then(Call::new("fnm", vec!["use", "system"]))
.then(test_node_version("custom node"))
});
}
mod use_nvmrc_lts {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(WriteFile::new(".nvmrc", "lts/dubnium"))
.then(Call::new("fnm", vec!["install"]))
.then(Call::new("fnm", vec!["use"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "lts-dubnium"))
});
}
mod partial_semver {
test_shell!(Bash, Zsh, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "6"])) // unsupported version, no new versions should be issued
.then(Call::new("fnm", vec!["use", "6"]))
.then(test_node_version("v6.17.1"))
});
}
mod log_level_quiet {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.log_level(Some("quiet"))
.then(ExpectCommandOutput::new(Call::new("fnm", vec!["install", "v8.11.3"]), "", "fnm install"))
.then(ExpectCommandOutput::new(Call::new("fnm", vec!["use", "v8.11.3"]), "", "fnm use"))
.then(ExpectCommandOutput::new(Call::new("fnm", vec!["alias", "v8.11.3", "something"]), "", "fnm alias"))
});
}
mod log_level_error {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.log_level(Some("error"))
.then(ExpectCommandOutput::new(Call::new("fnm", vec!["install", "v8.11.3"]).then(Call::new("echo", vec!["empty"])), "empty", "fnm install"))
.then(ExpectCommandOutput::new(Call::new("fnm", vec!["use", "v8.11.3"]).then(Call::new("echo", vec!["empty"])), "empty", "fnm use"))
.then(ExpectCommandOutput::new(Call::new("fnm", vec!["alias", "v8.11.3", "something"]).then(Call::new("echo", vec!["empty"])), "empty", "fnm alias"))
.then(OutputContains::new(IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["alias", "abcd", "efg"]))), "Can't find requested version"))
});
}
mod list_local_with_nothing_installed {
test_shell!(Bash, Zsh, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["ls"]))
});
}
mod latest_lts {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "--lts"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "lts-latest"))
.then(Call::new("fnm", vec!["use", "'lts/*'"]))
});
}
mod matching_dotfiles {
test_shell!(Bash, Zsh, Fish, PowerShell, WinCmd; {
EvalFnmEnv::default()
.then(WriteFile::new(".nvmrc", "11.10.0"))
.then(WriteFile::new(".node-version", "11.10.0"))
.then(Call::new("fnm", vec!["install"]))
.then(Call::new("fnm", vec!["use"]))
.then(test_node_version("v11.10.0"))
});
}
mod use_alias_install_if_missing {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(WriteFile::new(".node-version", "lts/*"))
.then(Call::new("fnm", vec!["use", "--install-if-missing"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "lts-latest"))
});
}
mod use_alias_not_installed {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.log_level(Some("error"))
.then(WriteFile::new(".node-version", "lts/*"))
.then(OutputContains::new(IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["use"]))),"Requested version lts-latest is not currently installed"))
});
}
mod unalias {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["install", "11.10.0"]))
.then(Call::new("fnm", vec!["install", "8.11.3"]))
.then(Call::new("fnm", vec!["alias", "8.11.3", "version8"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "version8"))
.then(Call::new("fnm", vec!["unalias", "version8"]))
.then(OutputContains::new(IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["use", "version8"]))), "Requested version version8 is not currently installed"))
});
}
mod unalias_error {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.log_level(Some("error"))
.then(OutputContains::new(IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["unalias", "lts"]))), "Requested alias lts not found"))
});
}
mod alias_system {
test_shell!(Bash, Zsh, Fish, PowerShell; {
EvalFnmEnv::default()
.then(Call::new("fnm", vec!["alias", "system", "my_system"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "my_system"))
.then(Call::new("fnm", vec!["alias", "system", "default"]))
.then(Call::new("fnm", vec!["alias", "my_system", "my_system2"]))
.then(OutputContains::new(Call::new("fnm", vec!["ls"]), "my_system2"))
.then(OutputContains::new(Call::new("fnm", vec!["use", "my_system"]), "Bypassing fnm"))
.then(Call::new("fnm", vec!["unalias", "my_system"]))
.then(OutputContains::new(IgnoreErrors::new(GetStderr::new(Call::new("fnm", vec!["use", "my_system"]))), "Requested version my_system is not currently installed"))
});
}

17
tests/feature_tests/snapshots/e2e__feature_tests__alias_system__Bash.snap

@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm alias system my_system
fnm ls | grep my_system
fnm alias system default
fnm alias my_system my_system2
fnm ls | grep my_system2
fnm use my_system | grep 'Bypassing fnm'
fnm unalias my_system
fnm use my_system 2>&1 | grep 'Requested version my_system is not currently installed'

14
tests/feature_tests/snapshots/e2e__feature_tests__alias_system__Fish.snap

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
fnm alias system my_system
fnm ls | grep my_system
fnm alias system default
fnm alias my_system my_system2
fnm ls | grep my_system2
fnm use my_system | grep 'Bypassing fnm'
fnm unalias my_system
fnm use my_system 2>&1 | grep 'Requested version my_system is not currently installed'

15
tests/feature_tests/snapshots/e2e__feature_tests__alias_system__PowerShell.snap

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm alias system my_system
$($__out__ = $(fnm ls | Select-String 'my_system'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })
fnm alias system default
fnm alias my_system my_system2
$($__out__ = $(fnm ls | Select-String 'my_system2'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })
$($__out__ = $(fnm use my_system | Select-String 'Bypassing fnm'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })
fnm unalias my_system
$($__out__ = $($($_tmp_err_action = $ErrorActionPreference;$ErrorActionPreference = "Continue";fnm use my_system 2>&1;$ErrorActionPreference = $_tmp_err_action) | Select-String 'Requested version my_system is not currently installed'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })

15
tests/feature_tests/snapshots/e2e__feature_tests__alias_system__Zsh.snap

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
fnm alias system my_system
fnm ls | grep my_system
fnm alias system default
fnm alias my_system my_system2
fnm ls | grep my_system2
fnm use my_system | grep 'Bypassing fnm'
fnm unalias my_system
fnm use my_system 2>&1 | grep 'Requested version my_system is not currently installed'

32
tests/feature_tests/snapshots/e2e__feature_tests__aliases__Bash.snap

@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
---
source: tests/feature_tests/aliases.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
fnm ls | grep 8.11.3 | grep oldie
fnm ls | grep 6.11.3 | grep older | grep default
fnm use older
if [ "$(node -v)" != "v6.11.3" ]; then
echo 'Expected Node version to be "v6.11.3", Got: '"$(node -v)"
exit 1
fi
fnm use oldie
if [ "$(node -v)" != "v8.11.3" ]; then
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)"
exit 1
fi
fnm use default
if [ "$(node -v)" != "v6.11.3" ]; then
echo 'Expected Node version to be "v6.11.3", Got: '"$(node -v)"
exit 1
fi

29
tests/feature_tests/snapshots/e2e__feature_tests__aliases__Fish.snap

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
---
source: tests/feature_tests/aliases.rs
expression: "&source.trim()"
---
fnm env | source
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
fnm ls | grep 8.11.3 | grep oldie
fnm ls | grep 6.11.3 | grep older | grep default
fnm use older
if test (node -v) != "v6.11.3"
echo 'Expected Node version to be "v6.11.3", Got: '(node -v)
exit 1
end
fnm use oldie
if test (node -v) != "v8.11.3"
echo 'Expected Node version to be "v8.11.3", Got: '(node -v)
exit 1
end
fnm use default
if test (node -v) != "v6.11.3"
echo 'Expected Node version to be "v6.11.3", Got: '(node -v)
exit 1
end

30
tests/feature_tests/snapshots/e2e__feature_tests__aliases__PowerShell.snap

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
---
source: tests/feature_tests/aliases.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
$($__out__ = $($($__out__ = $(fnm ls | Select-String '8.11.3'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ }) | Select-String 'oldie'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })
$($__out__ = $($($__out__ = $($($__out__ = $(fnm ls | Select-String '6.11.3'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ }) | Select-String 'older'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ }) | Select-String 'default'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })
fnm use older
If ("$(node -v)" -ne "v6.11.3") {
Write-Output ('Expected Node version to be "v6.11.3", Got: ' + $(node -v))
exit 1
}
fnm use oldie
If ("$(node -v)" -ne "v8.11.3") {
Write-Output ('Expected Node version to be "v8.11.3", Got: ' + $(node -v))
exit 1
}
fnm use default
If ("$(node -v)" -ne "v6.11.3") {
Write-Output ('Expected Node version to be "v6.11.3", Got: ' + $(node -v))
exit 1
}

30
tests/feature_tests/snapshots/e2e__feature_tests__aliases__Zsh.snap

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
---
source: tests/feature_tests/aliases.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
fnm install 6.11.3
fnm install 8.11.3
fnm alias 8.11 oldie
fnm alias 6 older
fnm default older
fnm ls | grep 8.11.3 | grep oldie
fnm ls | grep 6.11.3 | grep older | grep default
fnm use older
if [ "$(node -v)" != "v6.11.3" ]; then
echo 'Expected Node version to be "v6.11.3", Got: '"$(node -v)"
exit 1
fi
fnm use oldie
if [ "$(node -v)" != "v8.11.3" ]; then
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)"
exit 1
fi
fnm use default
if [ "$(node -v)" != "v6.11.3" ]; then
echo 'Expected Node version to be "v6.11.3", Got: '"$(node -v)"
exit 1
fi

14
tests/feature_tests/snapshots/e2e__feature_tests__basic__Bash.snap

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm install v8.11.3
fnm use v8.11.3
if [ "$(node -v)" != "v8.11.3" ]; then
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)"
exit 1
fi

11
tests/feature_tests/snapshots/e2e__feature_tests__basic__Fish.snap

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
fnm install v8.11.3
fnm use v8.11.3
if test (node -v) != "v8.11.3"
echo 'Expected Node version to be "v8.11.3", Got: '(node -v)
exit 1
end

12
tests/feature_tests/snapshots/e2e__feature_tests__basic__PowerShell.snap

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install v8.11.3
fnm use v8.11.3
If ("$(node -v)" -ne "v8.11.3") {
Write-Output ('Expected Node version to be "v8.11.3", Got: ' + $(node -v))
exit 1
}

12
tests/feature_tests/snapshots/e2e__feature_tests__basic__WinCmd.snap

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
FOR /f "tokens=*" %i IN ('fnm env') DO CALL %i
fnm install v8.11.3
fnm use v8.11.3
node -v | findstr v8.11.3
if %errorlevel% neq 0 (
echo Node version does not match "v8.11.3"
exit 1
)

12
tests/feature_tests/snapshots/e2e__feature_tests__basic__Zsh.snap

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
fnm install v8.11.3
fnm use v8.11.3
if [ "$(node -v)" != "v8.11.3" ]; then
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)"
exit 1
fi

32
tests/feature_tests/snapshots/e2e__feature_tests__current__Bash.snap

@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
---
source: tests/feature_tests/current.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
if [ "$(fnm current)" != "none" ]; then
echo 'Expected currently activated version to be "none", Got: '"$(fnm current)"
exit 1
fi
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if [ "$(fnm current)" != "v8.11.3" ]; then
echo 'Expected currently activated version to be "v8.11.3", Got: '"$(fnm current)"
exit 1
fi
fnm use v10.10.0
if [ "$(fnm current)" != "v10.10.0" ]; then
echo 'Expected currently activated version to be "v10.10.0", Got: '"$(fnm current)"
exit 1
fi
fnm use system
if [ "$(fnm current)" != "system" ]; then
echo 'Expected currently activated version to be "system", Got: '"$(fnm current)"
exit 1
fi

29
tests/feature_tests/snapshots/e2e__feature_tests__current__Fish.snap

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
---
source: tests/feature_tests/current.rs
expression: "&source.trim()"
---
fnm env | source
if test (fnm current) != "none"
echo 'Expected currently activated version to be "none", Got: '(fnm current)
exit 1
end
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if test (fnm current) != "v8.11.3"
echo 'Expected currently activated version to be "v8.11.3", Got: '(fnm current)
exit 1
end
fnm use v10.10.0
if test (fnm current) != "v10.10.0"
echo 'Expected currently activated version to be "v10.10.0", Got: '(fnm current)
exit 1
end
fnm use system
if test (fnm current) != "system"
echo 'Expected currently activated version to be "system", Got: '(fnm current)
exit 1
end

30
tests/feature_tests/snapshots/e2e__feature_tests__current__PowerShell.snap

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
---
source: tests/feature_tests/current.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
If ("$(fnm current)" -ne "none") {
Write-Output ('Expected currently activated version to be "none", Got: ' + $(fnm current))
exit 1
}
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
If ("$(fnm current)" -ne "v8.11.3") {
Write-Output ('Expected currently activated version to be "v8.11.3", Got: ' + $(fnm current))
exit 1
}
fnm use v10.10.0
If ("$(fnm current)" -ne "v10.10.0") {
Write-Output ('Expected currently activated version to be "v10.10.0", Got: ' + $(fnm current))
exit 1
}
fnm use system
If ("$(fnm current)" -ne "system") {
Write-Output ('Expected currently activated version to be "system", Got: ' + $(fnm current))
exit 1
}

33
tests/feature_tests/snapshots/e2e__feature_tests__current__WinCmd.snap

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
---
source: tests/feature_tests/current.rs
expression: "&source.trim()"
---
FOR /f "tokens=*" %i IN ('fnm env') DO CALL %i
fnm current | findstr none
if %errorlevel% neq 0 (
echo currently activated version does not match "none"
exit 1
)
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
fnm current | findstr v8.11.3
if %errorlevel% neq 0 (
echo currently activated version does not match "v8.11.3"
exit 1
)
fnm use v10.10.0
fnm current | findstr v10.10.0
if %errorlevel% neq 0 (
echo currently activated version does not match "v10.10.0"
exit 1
)
fnm use system
fnm current | findstr system
if %errorlevel% neq 0 (
echo currently activated version does not match "system"
exit 1
)

30
tests/feature_tests/snapshots/e2e__feature_tests__current__Zsh.snap

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
---
source: tests/feature_tests/current.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
if [ "$(fnm current)" != "none" ]; then
echo 'Expected currently activated version to be "none", Got: '"$(fnm current)"
exit 1
fi
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if [ "$(fnm current)" != "v8.11.3" ]; then
echo 'Expected currently activated version to be "v8.11.3", Got: '"$(fnm current)"
exit 1
fi
fnm use v10.10.0
if [ "$(fnm current)" != "v10.10.0" ]; then
echo 'Expected currently activated version to be "v10.10.0", Got: '"$(fnm current)"
exit 1
fi
fnm use system
if [ "$(fnm current)" != "system" ]; then
echo 'Expected currently activated version to be "system", Got: '"$(fnm current)"
exit 1
fi

26
tests/feature_tests/snapshots/e2e__feature_tests__exec__Bash.snap

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
echo v8.10.0 > .nvmrc
fnm install
fnm install v6.10.0
fnm install v10.10.0
if [ "$(fnm exec -- node -v)" != "v8.10.0" ]; then
echo 'Expected version file exec to be "v8.10.0", Got: '"$(fnm exec -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=6 -- node -v)" != "v6.10.0" ]; then
echo 'Expected exec:6 node -v to be "v6.10.0", Got: '"$(fnm exec --using=6 -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=10 -- node -v)" != "v10.10.0" ]; then
echo 'Expected exec:6 node -v to be "v10.10.0", Got: '"$(fnm exec --using=10 -- node -v)"
exit 1
fi

23
tests/feature_tests/snapshots/e2e__feature_tests__exec__Fish.snap

@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
echo v8.10.0 > .nvmrc
fnm install
fnm install v6.10.0
fnm install v10.10.0
if test (fnm exec -- node -v) != "v8.10.0"
echo 'Expected version file exec to be "v8.10.0", Got: '(fnm exec -- node -v)
exit 1
end
if test (fnm exec --using=6 -- node -v) != "v6.10.0"
echo 'Expected exec:6 node -v to be "v6.10.0", Got: '(fnm exec --using=6 -- node -v)
exit 1
end
if test (fnm exec --using=10 -- node -v) != "v10.10.0"
echo 'Expected exec:6 node -v to be "v10.10.0", Got: '(fnm exec --using=10 -- node -v)
exit 1
end

24
tests/feature_tests/snapshots/e2e__feature_tests__exec__PowerShell.snap

@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
echo 'v8.10.0' > '.nvmrc'
fnm install
fnm install v6.10.0
fnm install v10.10.0
If ("$(fnm exec -- node -v)" -ne "v8.10.0") {
Write-Output ('Expected version file exec to be "v8.10.0", Got: ' + $(fnm exec -- node -v))
exit 1
}
If ("$(fnm exec --using=6 -- node -v)" -ne "v6.10.0") {
Write-Output ('Expected exec:6 node -v to be "v6.10.0", Got: ' + $(fnm exec --using=6 -- node -v))
exit 1
}
If ("$(fnm exec --using=10 -- node -v)" -ne "v10.10.0") {
Write-Output ('Expected exec:6 node -v to be "v10.10.0", Got: ' + $(fnm exec --using=10 -- node -v))
exit 1
}

26
tests/feature_tests/snapshots/e2e__feature_tests__exec__WinCmd.snap

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
FOR /f "tokens=*" %i IN ('fnm env') DO CALL %i
echo v8.10.0 > .nvmrc
fnm install
fnm install v6.10.0
fnm install v10.10.0
fnm exec -- node -v | findstr v8.10.0
if %errorlevel% neq 0 (
echo version file exec does not match "v8.10.0"
exit 1
)
fnm exec --using=6 -- node -v | findstr v6.10.0
if %errorlevel% neq 0 (
echo exec:6 node -v does not match "v6.10.0"
exit 1
)
fnm exec --using=10 -- node -v | findstr v10.10.0
if %errorlevel% neq 0 (
echo exec:6 node -v does not match "v10.10.0"
exit 1
)

24
tests/feature_tests/snapshots/e2e__feature_tests__exec__Zsh.snap

@ -1,24 +0,0 @@ @@ -1,24 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
echo v8.10.0 > .nvmrc
fnm install
fnm install v6.10.0
fnm install v10.10.0
if [ "$(fnm exec -- node -v)" != "v8.10.0" ]; then
echo 'Expected version file exec to be "v8.10.0", Got: '"$(fnm exec -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=6 -- node -v)" != "v6.10.0" ]; then
echo 'Expected exec:6 node -v to be "v6.10.0", Got: '"$(fnm exec --using=6 -- node -v)"
exit 1
fi
if [ "$(fnm exec --using=10 -- node -v)" != "v10.10.0" ]; then
echo 'Expected exec:6 node -v to be "v10.10.0", Got: '"$(fnm exec --using=10 -- node -v)"
exit 1
fi

10
tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__Bash.snap

@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm install v8.11.3
fnm install v8.11.3 2>&1 | grep 'already installed'

7
tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__Fish.snap

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
fnm install v8.11.3
fnm install v8.11.3 2>&1 | grep 'already installed'

8
tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__PowerShell.snap

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install v8.11.3
$($__out__ = $($($_tmp_err_action = $ErrorActionPreference;$ErrorActionPreference = "Continue";fnm install v8.11.3 2>&1;$ErrorActionPreference = $_tmp_err_action) | Select-String 'already installed'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })

8
tests/feature_tests/snapshots/e2e__feature_tests__existing_installation__Zsh.snap

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
fnm install v8.11.3
fnm install v8.11.3 2>&1 | grep 'already installed'

11
tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__Bash.snap

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm install --lts
fnm ls | grep lts-latest
fnm use 'lts/*'

8
tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__Fish.snap

@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
fnm install --lts
fnm ls | grep lts-latest
fnm use 'lts/*'

9
tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__PowerShell.snap

@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm install --lts
$($__out__ = $(fnm ls | Select-String 'lts-latest'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })
fnm use 'lts/*'

9
tests/feature_tests/snapshots/e2e__feature_tests__latest_lts__Zsh.snap

@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
fnm install --lts
fnm ls | grep lts-latest
fnm use 'lts/*'

9
tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__Bash.snap

@ -1,9 +0,0 @@ @@ -1,9 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm ls

6
tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__Fish.snap

@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
fnm ls

7
tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__PowerShell.snap

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
fnm ls

6
tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__WinCmd.snap

@ -1,6 +0,0 @@ @@ -1,6 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
FOR /f "tokens=*" %i IN ('fnm env') DO CALL %i
fnm ls

7
tests/feature_tests/snapshots/e2e__feature_tests__list_local_with_nothing_installed__Zsh.snap

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
fnm ls

30
tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__Bash.snap

@ -1,30 +0,0 @@ @@ -1,30 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm --log-level='error' env)"
if [ "$(fnm install v8.11.3
echo empty)" != "empty" ]; then
echo 'Expected fnm install to be "empty", Got: '"$(fnm install v8.11.3
echo empty)"
exit 1
fi
if [ "$(fnm use v8.11.3
echo empty)" != "empty" ]; then
echo 'Expected fnm use to be "empty", Got: '"$(fnm use v8.11.3
echo empty)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something
echo empty)" != "empty" ]; then
echo 'Expected fnm alias to be "empty", Got: '"$(fnm alias v8.11.3 something
echo empty)"
exit 1
fi
fnm alias abcd efg 2>&1 | grep 'Can'\''t find requested version'

27
tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__Fish.snap

@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm --log-level='error' env | source
if test (fnm install v8.11.3
echo empty) != "empty"
echo 'Expected fnm install to be "empty", Got: '(fnm install v8.11.3
echo empty)
exit 1
end
if test (fnm use v8.11.3
echo empty) != "empty"
echo 'Expected fnm use to be "empty", Got: '(fnm use v8.11.3
echo empty)
exit 1
end
if test (fnm alias v8.11.3 something
echo empty) != "empty"
echo 'Expected fnm alias to be "empty", Got: '(fnm alias v8.11.3 something
echo empty)
exit 1
end
fnm alias abcd efg 2>&1 | grep 'Can'\''t find requested version'

28
tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__PowerShell.snap

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm --log-level='error' env | Out-String | Invoke-Expression
If ("$(fnm install v8.11.3
echo empty)" -ne "empty") {
Write-Output ('Expected fnm install to be "empty", Got: ' + $(fnm install v8.11.3
echo empty))
exit 1
}
If ("$(fnm use v8.11.3
echo empty)" -ne "empty") {
Write-Output ('Expected fnm use to be "empty", Got: ' + $(fnm use v8.11.3
echo empty))
exit 1
}
If ("$(fnm alias v8.11.3 something
echo empty)" -ne "empty") {
Write-Output ('Expected fnm alias to be "empty", Got: ' + $(fnm alias v8.11.3 something
echo empty))
exit 1
}
$($__out__ = $($($_tmp_err_action = $ErrorActionPreference;$ErrorActionPreference = "Continue";fnm alias abcd efg 2>&1;$ErrorActionPreference = $_tmp_err_action) | Select-String 'Can''t find requested version'); echo $__out__; if ($__out__ -eq $null){ exit 1 } else { $__out__ })

28
tests/feature_tests/snapshots/e2e__feature_tests__log_level_error__Zsh.snap

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm --log-level='error' env)"
if [ "$(fnm install v8.11.3
echo empty)" != "empty" ]; then
echo 'Expected fnm install to be "empty", Got: '"$(fnm install v8.11.3
echo empty)"
exit 1
fi
if [ "$(fnm use v8.11.3
echo empty)" != "empty" ]; then
echo 'Expected fnm use to be "empty", Got: '"$(fnm use v8.11.3
echo empty)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something
echo empty)" != "empty" ]; then
echo 'Expected fnm alias to be "empty", Got: '"$(fnm alias v8.11.3 something
echo empty)"
exit 1
fi
fnm alias abcd efg 2>&1 | grep 'Can'\''t find requested version'

22
tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__Bash.snap

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm --log-level='quiet' env)"
if [ "$(fnm install v8.11.3)" != "" ]; then
echo 'Expected fnm install to be "", Got: '"$(fnm install v8.11.3)"
exit 1
fi
if [ "$(fnm use v8.11.3)" != "" ]; then
echo 'Expected fnm use to be "", Got: '"$(fnm use v8.11.3)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something)" != "" ]; then
echo 'Expected fnm alias to be "", Got: '"$(fnm alias v8.11.3 something)"
exit 1
fi

19
tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__Fish.snap

@ -1,19 +0,0 @@ @@ -1,19 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm --log-level='quiet' env | source
if test (fnm install v8.11.3) != ""
echo 'Expected fnm install to be "", Got: '(fnm install v8.11.3)
exit 1
end
if test (fnm use v8.11.3) != ""
echo 'Expected fnm use to be "", Got: '(fnm use v8.11.3)
exit 1
end
if test (fnm alias v8.11.3 something) != ""
echo 'Expected fnm alias to be "", Got: '(fnm alias v8.11.3 something)
exit 1
end

20
tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__PowerShell.snap

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm --log-level='quiet' env | Out-String | Invoke-Expression
If ("$(fnm install v8.11.3)" -ne "") {
Write-Output ('Expected fnm install to be "", Got: ' + $(fnm install v8.11.3))
exit 1
}
If ("$(fnm use v8.11.3)" -ne "") {
Write-Output ('Expected fnm use to be "", Got: ' + $(fnm use v8.11.3))
exit 1
}
If ("$(fnm alias v8.11.3 something)" -ne "") {
Write-Output ('Expected fnm alias to be "", Got: ' + $(fnm alias v8.11.3 something))
exit 1
}

20
tests/feature_tests/snapshots/e2e__feature_tests__log_level_quiet__Zsh.snap

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm --log-level='quiet' env)"
if [ "$(fnm install v8.11.3)" != "" ]; then
echo 'Expected fnm install to be "", Got: '"$(fnm install v8.11.3)"
exit 1
fi
if [ "$(fnm use v8.11.3)" != "" ]; then
echo 'Expected fnm use to be "", Got: '"$(fnm use v8.11.3)"
exit 1
fi
if [ "$(fnm alias v8.11.3 something)" != "" ]; then
echo 'Expected fnm alias to be "", Got: '"$(fnm alias v8.11.3 something)"
exit 1
fi

16
tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__Bash.snap

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
echo 11.10.0 > .nvmrc
echo 11.10.0 > .node-version
fnm install
fnm use
if [ "$(node -v)" != "v11.10.0" ]; then
echo 'Expected Node version to be "v11.10.0", Got: '"$(node -v)"
exit 1
fi

13
tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__Fish.snap

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
echo 11.10.0 > .nvmrc
echo 11.10.0 > .node-version
fnm install
fnm use
if test (node -v) != "v11.10.0"
echo 'Expected Node version to be "v11.10.0", Got: '(node -v)
exit 1
end

14
tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__PowerShell.snap

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
$ErrorActionPreference = "Stop"
fnm env | Out-String | Invoke-Expression
echo '11.10.0' > '.nvmrc'
echo '11.10.0' > '.node-version'
fnm install
fnm use
If ("$(node -v)" -ne "v11.10.0") {
Write-Output ('Expected Node version to be "v11.10.0", Got: ' + $(node -v))
exit 1
}

14
tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__WinCmd.snap

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
FOR /f "tokens=*" %i IN ('fnm env') DO CALL %i
echo 11.10.0 > .nvmrc
echo 11.10.0 > .node-version
fnm install
fnm use
node -v | findstr v11.10.0
if %errorlevel% neq 0 (
echo Node version does not match "v11.10.0"
exit 1
)

14
tests/feature_tests/snapshots/e2e__feature_tests__matching_dotfiles__Zsh.snap

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
eval "$(fnm env)"
echo 11.10.0 > .nvmrc
echo 11.10.0 > .node-version
fnm install
fnm use
if [ "$(node -v)" != "v11.10.0" ]; then
echo 'Expected Node version to be "v11.10.0", Got: '"$(node -v)"
exit 1
fi

25
tests/feature_tests/snapshots/e2e__feature_tests__multishell__Bash.snap

@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm install v8.11.3
fnm install v11.9.0
fnm use v8.11.3
echo 'set -e
shopt -s expand_aliases
eval "$(fnm env)"
fnm use 11
if [ "$(node -v)" '\!'= "v11.9.0" ]; then
echo '\''Expected Node version to be "v11.9.0", Got: '\''"$(node -v)"
exit 1
fi
' | bash
if [ "$(node -v)" != "v8.11.3" ]; then
echo 'Expected Node version to be "v8.11.3", Got: '"$(node -v)"
exit 1
fi

20
tests/feature_tests/snapshots/e2e__feature_tests__multishell__Fish.snap

@ -1,20 +0,0 @@ @@ -1,20 +0,0 @@
---
source: tests/feature_tests/mod.rs
expression: "&source.trim()"
---
fnm env | source
fnm install v8.11.3
fnm install v11.9.0
fnm use v8.11.3
fish -c '
fnm env | source
fnm use 11
if test (node -v) '\!'= "v11.9.0"
echo '\''Expected Node version to be "v11.9.0", Got: '\''(node -v)
exit 1
end
'
if test (node -v) != "v8.11.3"
echo 'Expected Node version to be "v8.11.3", Got: '(node -v)
exit 1
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save