1+ import { spawnSync } from "node:child_process" ;
12import process from "node:process" ;
23import { expect , test } from "@jest/globals" ;
3-
44import {
55 collectDotnetInfo ,
66 collectGccInfo ,
@@ -10,9 +10,10 @@ import {
1010 collectPythonInfo ,
1111 collectRustInfo ,
1212 getBranch ,
13+ getNvmToolDirectory ,
14+ getOrInstallNvmTool ,
1315 getOriginUrl ,
1416 isNvmAvailable ,
15- isNvmToolAvailable ,
1617 isSdkmanAvailable ,
1718 isSdkmanToolAvailable ,
1819 listFiles ,
@@ -43,8 +44,30 @@ test("sdkman tests", () => {
4344} ) ;
4445
4546test ( "nvm tests" , ( ) => {
46- if ( process . env ?. SDKMAN_VERSION ) {
47- expect ( isNvmAvailable ( ) ) . toBeTruthy ( ) ;
48- expect ( isNvmToolAvailable ( "22" ) ) . toBeTruthy ( ) ;
47+ if ( process . env ?. NVM_DIR ) {
48+ if ( isNvmAvailable ( ) ) {
49+ // try to remove nodejs 14 before testing below
50+ const removeNode14 = spawnSync (
51+ process . env . SHELL || "bash" ,
52+ [ "-i" , "-c" , `"nvm uninstall 14"` ] ,
53+ {
54+ encoding : "utf-8" ,
55+ shell : process . env . SHELL || true ,
56+ } ,
57+ ) ;
58+
59+ // expected to be run in CircleCi, where node version is 22.8.0
60+ // as defined in our Dockerfile
61+ expect ( getNvmToolDirectory ( 22 ) ) . toBeTruthy ( ) ;
62+ expect ( getNvmToolDirectory ( 14 ) ) . toBeFalsy ( ) ;
63+
64+ // now we install nvm tool for a specific verison
65+ expect ( getOrInstallNvmTool ( 14 ) ) . toBeTruthy ( ) ;
66+ expect ( getNvmToolDirectory ( 14 ) ) . toBeTruthy ( ) ;
67+ } else {
68+ // if this test is failing it would be due to an error in isNvmAvailable()
69+ expect ( getNvmToolDirectory ( 22 ) ) . toBeFalsy ( ) ;
70+ expect ( getOrInstallNvmTool ( 14 ) ) . toBeFalsy ( ) ;
71+ }
4972 }
5073} ) ;
0 commit comments