[skip ci] refactoring npm by nvm, ClojureScriptKtTest left Todo, Tests successful

This commit is contained in:
Mirco 2025-01-31 18:20:52 +01:00
parent 5e70cad41c
commit e990478faa
3 changed files with 27 additions and 26 deletions
src
main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure
test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure

View file

@ -2,38 +2,38 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure
import org.domaindrivenarchitecture.provs.framework.core.Prov
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.addTextToFile
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.createFile
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.userHome
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalledCheckCommand
import java.io.File
fun Prov.installNpmByNvm(): ProvResult = task {
if (!isPackageInstalledCheckCommand("npm")) {
//Node-Version-Manager from https://github.com/nvm-sh/nvm
val versNvm = "0.40.1"
cmd("sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$versNvm/install.sh | bash")
val version = "0.40.1"
cmd("sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$version/install.sh | bash")
cmd("chmod 755 .nvm/nvm.sh")
addTextToFile("\n##### NVM #####\n", File("~/.bashrc"))
addTextToFile("""export NVM_DIR="${"\$HOME/.nvm"}" """ + "\n", File("~/.bashrc"))
addTextToFile("""[ -s "${"\$NVM_DIR/nvm.sh"}" ] && \. "${"\$NVM_DIR/nvm.sh"}" """ + "\n", File("~/.bashrc"))
addTextToFile("""[ -s "${"\$NVM_DIR/bash_completion"}" ] && \. "${"\$NVM_DIR/bash_completion"}" """ + "\n", File("~/.bashrc"))
configureBashForUser()
createFile("~/.bashrc.d/npmbynvm.sh", """export NVM_DIR="${userHome()}.nvm" """ + "\n"
+ """[ -s "${"\$NVM_DIR/nvm.sh"}" ] && \. "${"\$NVM_DIR/nvm.sh"}" """ + "\n")
cmd(". .nvm/nvm.sh && nvm install --lts")
//to be discussed, sourcing in docker test container, separtely?
val nvmRes = cmd(". .nvm/nvm.sh && nvm --version").toString()
if (versNvm == nvmRes) {
println("NVM version $versNvm")
addResultToEval(ProvResult(true, out = "SUCCESS: NVM version $versNvm installed !!"))
if (version == nvmRes) {
println("NVM version $version")
addResultToEval(ProvResult(true, out = "SUCCESS: NVM version $version installed !!"))
} else {
println("FAIL: NVM version $versNvm is not installed !!")
addResultToEval(ProvResult(true, out = "FAIL: NVM version $versNvm is not installed !!"))
println("FAIL: NVM version $version is not installed !!")
addResultToEval(ProvResult(true, out = "FAIL: NVM version $version is not installed !!"))
}
cmd(". .nvm/nvm.sh && node -v")
cmd(". .nvm/nvm.sh && npm --version")
} else {
ProvResult(true, out = "npm already installed")
} else {
addResultToEval(ProvResult(true, out = "npm already installed"))
}

View file

@ -1,6 +1,5 @@
package org.domaindrivenarchitecture.provs.desktop.infrastructure
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.junit.jupiter.api.Assertions.assertTrue
@ -12,14 +11,18 @@ internal class ClojureScriptKtTest {
// given
val prov = defaultTestContainer()
//Todo:
// To be discussed, should init container, but not available for prov.installShadowCljs() !!
// Howto work in addition prov.a() + prov.b()?
prov.installNpmByNvm()
// when
val res = prov.installShadowCljs()
val res2 = prov.installShadowCljs() // check if it can be run twice successfully
// check if it can be run twice successfully
val res01 = prov.installShadowCljs()
val res02 = prov.installShadowCljs()
// then
assertTrue(res.success)
assertTrue(res2.success)
assertTrue(res01.success)
assertTrue(res02.success)
}
}

View file

@ -3,20 +3,18 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
internal class NpmByNvmKtTest {
internal class NVMnpmKtTest {
@Test
@ContainerTest
fun installNVMnpm() {
// given
val container = defaultTestContainer(ContainerStartMode.CREATE_NEW_KILL_EXISTING)
container.aptInstall("curl")
// when
val res01 = container.installNpmByNvm()
//test repeatability
val res02 = container.installNpmByNvm()
// then
assertTrue(res01.success)