Skip to content

Commit 57d65fe

Browse files
committed
fix bugs and add tests for nodenv
1 parent ef8d2a2 commit 57d65fe

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

jobs/js/node/nodenv_example.groovy

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import org.dsty.js.node.NodeEnv
99
LogClient log = new LogClient()
1010

1111
node() {
12-
// Ignore this line its for catching CPS issues.
13-
String cps = sh(script: '#!/bin/bash\nset +x; > /dev/null 2>&1\necho Test for CPS issue', returnStdout: true)
1412

1513
log.info('Lets install the latest version of nodenv.')
1614

@@ -31,14 +29,13 @@ node() {
3129

3230
node.runCommand('-v')
3331

34-
log.info('You can also specify the version in the .node-version file:')
35-
3632
String nodeVersion = '''\
3733
17.9.1
3834
'''
39-
println nodeVersion
4035

41-
log.info('Then that can be used by nodenv to automaticly install the correct version of node.')
36+
log.info('You can also specify the version in the .node-version file')
37+
38+
log.info("Lets create a .node-version file with version ${nodeVersion}")
4239

4340
Path ws = Path.workspace()
4441

@@ -48,12 +45,12 @@ node() {
4845

4946
nodeVersionFile.write(nodeVersion)
5047

48+
sh("cat ${nodeVersionFile}")
49+
5150
node = nodenv.install()
5251

5352
node.runCommand('-v')
5453

5554
}
5655

57-
// Ignore this line its for catching CPS issues.
58-
cps = sh(script: '#!/bin/bash\nset +x; > /dev/null 2>&1\necho Test for CPS issue', returnStdout: true)
5956
}

src/org/dsty/js/node/NodeEnv.groovy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,16 @@ class NodeEnv implements Serializable {
317317

318318
// Install nodenv
319319
final Installer installer = new Installer()
320-
installer.install()
320+
321+
try {
322+
installer.install()
323+
} catch(ExecutionException ex) {
324+
325+
if (!ex.stdErr.contains('All done!')) {
326+
throw new Exception("Failed to install nodenv.", ex)
327+
}
328+
}
329+
321330

322331
String binName = installer.getBinName()
323332

@@ -331,7 +340,7 @@ class NodeEnv implements Serializable {
331340

332341
if (!this.@nodenvInstallDir) {
333342

334-
final Path installPath = Path.jenkinsHome().child('./.nodenv')
343+
final Path installPath = Path.userHome().child('./.nodenv')
335344

336345
this.nodenvInstallDir = installPath
337346
}

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_test(job_path: str) -> str:
8282

8383
cmd = f"run_job {job_path}"
8484

85-
exitcode, raw_output = container.exec_run(cmd, user="root")
85+
exitcode, raw_output = container.exec_run(cmd)
8686

8787
output = raw_output.decode("utf-8")
8888

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from tests.conftest import Container
4+
5+
6+
@pytest.fixture()
7+
def job_folder():
8+
return "js/node"
9+
10+
11+
def test_nodenv_example(container: Container, job_folder):
12+
13+
_ = container(f"{job_folder}/nodenv_example.groovy")
14+
15+
16+
def test_node_example(container: Container, job_folder):
17+
18+
_ = container(f"{job_folder}/node_example.groovy")
19+
20+
21+
def test_npm_example(container: Container, job_folder):
22+
23+
_ = container(f"{job_folder}/npm_example.groovy")

0 commit comments

Comments
 (0)