Skip to content

Commit 38cd3df

Browse files
Fix: nvm tests in envcontext.test.js (#1362)
* remove npm tests as no longer valid Signed-off-by: Aryan Rajoria <[email protected]> * run lint Signed-off-by: Aryan Rajoria <[email protected]> * add testcases Signed-off-by: Aryan Rajoria <[email protected]> * remove console log Signed-off-by: Aryan Rajoria <[email protected]> * fix typo Signed-off-by: Aryan Rajoria <[email protected]> * bump to 10.9.9 Signed-off-by: Aryan Rajoria <[email protected]> * bump to 10.9.9 jsr.json Signed-off-by: Aryan Rajoria <[email protected]> * remove empty pregen.test.js Signed-off-by: Aryan Rajoria <[email protected]> * fix issues pointed out by eslint Signed-off-by: Aryan Rajoria <[email protected]> --------- Signed-off-by: Aryan Rajoria <[email protected]>
1 parent f1a60cd commit 38cd3df

File tree

8 files changed

+41
-19
lines changed

8 files changed

+41
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Sections include:
5555
## Installing
5656

5757
```shell
58-
npm install -g @cyclonedx/[email protected].8
58+
npm install -g @cyclonedx/[email protected].9
5959
```
6060

6161
If you are a [Homebrew][homebrew-homepage] user, you can also install [cdxgen][homebrew-cdxgen] via:
@@ -403,7 +403,7 @@ To generate test public/private key pairs, you can run cdxgen by passing the arg
403403
Use the bundled `cdx-verify` command, which supports verifying a single signature added at the bom level.
404404

405405
```shell
406-
npm install -g @cyclonedx/[email protected].8
406+
npm install -g @cyclonedx/[email protected].9
407407
cdx-verify -i bom.json --public-key public.key
408408
```
409409

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cyclonedx/cdxgen",
3-
"version": "10.9.8",
3+
"version": "10.9.9",
44
"exports": "./index.js",
55
"compilerOptions": {
66
"allowJs": true,

docs/CLI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ flowchart LR
2121
## Installing
2222

2323
```shell
24-
sudo npm install -g @cyclonedx/[email protected].8
24+
sudo npm install -g @cyclonedx/[email protected].9
2525
```
2626

2727
If you are a [Homebrew](https://brew.sh/) user, you can also install [cdxgen](https://formulae.brew.sh/formula/cdxgen) via:

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cdxgen is available as an npm package, container image, and single application e
99
## Installation
1010

1111
```shell
12-
sudo npm install -g @cyclonedx/[email protected].8
12+
sudo npm install -g @cyclonedx/[email protected].9
1313
```
1414

1515
If you are a [Homebrew](https://brew.sh/) user, you can also install [cdxgen](https://formulae.brew.sh/formula/cdxgen) via:
@@ -63,7 +63,7 @@ cdxgen -t c -o bom.json
6363
## Installation
6464

6565
```shell
66-
sudo npm install -g @cyclonedx/[email protected].8
66+
sudo npm install -g @cyclonedx/[email protected].9
6767
```
6868

6969
## Usage
@@ -237,7 +237,7 @@ To generate test public/private key pairs, you can run cdxgen by passing the arg
237237
Use the bundled `cdx-verify` command, which supports verifying a single signature added at the bom level.
238238

239239
```shell
240-
npm install -g @cyclonedx/[email protected].8
240+
npm install -g @cyclonedx/[email protected].9
241241
cdx-verify -i bom.json --public-key public.key
242242
```
243243

envcontext.test.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { spawnSync } from "node:child_process";
12
import process from "node:process";
23
import { expect, test } from "@jest/globals";
3-
44
import {
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

4546
test("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
});

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cyclonedx/cdxgen",
3-
"version": "10.9.8",
3+
"version": "10.9.9",
44
"exports": "./index.js",
55
"include": ["*.js", "bin/**", "data/**", "types/**"],
66
"exclude": ["test/", "docs/", "contrib/", "ci/", "tools_config/"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cyclonedx/cdxgen",
3-
"version": "10.9.8",
3+
"version": "10.9.9",
44
"description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
55
"homepage": "https://github.com/cyclonedx/cdxgen",
66
"author": "Prabhu Subramanian <[email protected]>",

pregen.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { spawn, spawnSync } from "node:child_process";
1+
import { spawnSync } from "node:child_process";
22
import { mkdtempSync, readdirSync } from "node:fs";
33
import { arch, platform, tmpdir } from "node:os";
44
import { delimiter, join } from "node:path";
55
import {
66
SDKMAN_TOOL_ALIASES,
7-
getNvmToolDirectory,
87
getOrInstallNvmTool,
98
installSdkmanTool,
109
isNvmAvailable,
@@ -184,7 +183,7 @@ export function tryLoadNvmAndInstallTool(nodeVersion) {
184183
fi
185184
`;
186185

187-
const spawnedShell = spawnSync(process.env.SHELL || "bash", ["-c", command], {
186+
const result = spawnSync(process.env.SHELL || "bash", ["-c", command], {
188187
encoding: "utf-8",
189188
shell: process.env.SHELL || true,
190189
});
@@ -228,10 +227,10 @@ export function doNpmInstall(filePath, nvmNodePath) {
228227
// There was some problem with NpmInstall
229228
if (DEBUG_MODE) {
230229
if (console.stdout) {
231-
console.log(result.stdout);
230+
console.log(resultNpmInstall.stdout);
232231
}
233232
if (console.stderr) {
234-
console.log(result.stderr);
233+
console.log(resultNpmInstall.stderr);
235234
}
236235
}
237236
}

0 commit comments

Comments
 (0)