|
2 | 2 |
|
3 | 3 | (require 'js-comint) |
4 | 4 | (require 'ert) |
| 5 | +(require 'el-mock) |
5 | 6 |
|
6 | 7 | (defun js-comint-test-buffer-matches (regex) |
7 | 8 | "Search the js-comint buffer for the given regular expression. |
@@ -122,3 +123,49 @@ reduce((prev, curr) => prev + curr, 0);" "^9$"))) |
122 | 123 | (with-environment-variables (("NODE_REPL_MODE" "strict")) |
123 | 124 | ;; global variables are not allowed in strict mode |
124 | 125 | (js-comint-test-output-matches "foo = 5;" "Uncaught ReferenceError.*"))) |
| 126 | + |
| 127 | +(ert-deftest js-comint-select-node-version/test-no-nvm () |
| 128 | + "Should error if nvm is missing." |
| 129 | + (let ((original-command-value js-comint-program-command)) |
| 130 | + (with-mock |
| 131 | + (mock (require 'nvm) => (error "Cannot open nvm")) |
| 132 | + (should-error (js-comint-select-node-version)) |
| 133 | + (should-not js-use-nvm) |
| 134 | + (should (equal js-comint-program-command |
| 135 | + original-command-value))))) |
| 136 | + |
| 137 | +(ert-deftest js-comint-select-node-version/test-with-arg () |
| 138 | + "Should set program-command when called non-interactively." |
| 139 | + (let ((original-command-value js-comint-program-command) |
| 140 | + (original-use-jvm-value js-use-nvm) |
| 141 | + (original-nvm-version js-nvm-current-version)) |
| 142 | + (unwind-protect |
| 143 | + (with-mock |
| 144 | + (mock (require 'nvm)) |
| 145 | + (mock (nvm--find-exact-version-for "foo") => '("foo-1.2" "some_path")) |
| 146 | + (js-comint-select-node-version "foo") |
| 147 | + (should js-use-nvm) |
| 148 | + (should (equal js-comint-program-command |
| 149 | + "some_path/bin/node")) |
| 150 | + (should (equal js-nvm-current-version |
| 151 | + '("foo-1.2" "some_path")))) |
| 152 | + (setq js-comint-program-command original-command-value |
| 153 | + js-use-nvm original-use-jvm-value |
| 154 | + js-nvm-current-version original-nvm-version)))) |
| 155 | + |
| 156 | +(ert-deftest js-comint-select-node-version/test-optional-arg () |
| 157 | + "Should set program-command when called with no arg." |
| 158 | + (let ((original-command-value js-comint-program-command) |
| 159 | + (original-use-jvm-value js-use-nvm) |
| 160 | + (original-nvm-version js-nvm-current-version)) |
| 161 | + (unwind-protect |
| 162 | + (with-mock |
| 163 | + (mock (require 'nvm)) |
| 164 | + (mock (js-comint-list-nvm-versions *) => "foo") |
| 165 | + (mock (nvm--find-exact-version-for "foo") => '("foo-1.2" "some_path")) |
| 166 | + (js-comint-select-node-version) |
| 167 | + (should (equal js-comint-program-command |
| 168 | + "some_path/bin/node"))) |
| 169 | + (setq js-comint-program-command original-command-value |
| 170 | + js-use-nvm original-use-jvm-value |
| 171 | + js-nvm-current-version original-nvm-version)))) |
0 commit comments