Skip to content

Commit

Permalink
Fix: nvm tests in envcontext.test.js (#1362)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
aryan-rajoria authored Sep 8, 2024
1 parent f1a60cd commit 38cd3df
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Sections include:
## Installing

```shell
npm install -g @cyclonedx/[email protected].8
npm install -g @cyclonedx/[email protected].9
```

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

```shell
npm install -g @cyclonedx/[email protected].8
npm install -g @cyclonedx/[email protected].9
cdx-verify -i bom.json --public-key public.key
```

Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "10.9.8",
"version": "10.9.9",
"exports": "./index.js",
"compilerOptions": {
"allowJs": true,
Expand Down
2 changes: 1 addition & 1 deletion docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ flowchart LR
## Installing

```shell
sudo npm install -g @cyclonedx/[email protected].8
sudo npm install -g @cyclonedx/[email protected].9
```

If you are a [Homebrew](https://brew.sh/) user, you can also install [cdxgen](https://formulae.brew.sh/formula/cdxgen) via:
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cdxgen is available as an npm package, container image, and single application e
## Installation

```shell
sudo npm install -g @cyclonedx/[email protected].8
sudo npm install -g @cyclonedx/[email protected].9
```

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

```shell
sudo npm install -g @cyclonedx/[email protected].8
sudo npm install -g @cyclonedx/[email protected].9
```

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

```shell
npm install -g @cyclonedx/[email protected].8
npm install -g @cyclonedx/[email protected].9
cdx-verify -i bom.json --public-key public.key
```

Expand Down
33 changes: 28 additions & 5 deletions envcontext.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawnSync } from "node:child_process";
import process from "node:process";
import { expect, test } from "@jest/globals";

import {
collectDotnetInfo,
collectGccInfo,
Expand All @@ -10,9 +10,10 @@ import {
collectPythonInfo,
collectRustInfo,
getBranch,
getNvmToolDirectory,
getOrInstallNvmTool,
getOriginUrl,
isNvmAvailable,
isNvmToolAvailable,
isSdkmanAvailable,
isSdkmanToolAvailable,
listFiles,
Expand Down Expand Up @@ -43,8 +44,30 @@ test("sdkman tests", () => {
});

test("nvm tests", () => {
if (process.env?.SDKMAN_VERSION) {
expect(isNvmAvailable()).toBeTruthy();
expect(isNvmToolAvailable("22")).toBeTruthy();
if (process.env?.NVM_DIR) {
if (isNvmAvailable()) {
// try to remove nodejs 14 before testing below
const removeNode14 = spawnSync(
process.env.SHELL || "bash",
["-i", "-c", `"nvm uninstall 14"`],
{
encoding: "utf-8",
shell: process.env.SHELL || true,
},
);

// expected to be run in CircleCi, where node version is 22.8.0
// as defined in our Dockerfile
expect(getNvmToolDirectory(22)).toBeTruthy();
expect(getNvmToolDirectory(14)).toBeFalsy();

// now we install nvm tool for a specific verison
expect(getOrInstallNvmTool(14)).toBeTruthy();
expect(getNvmToolDirectory(14)).toBeTruthy();
} else {
// if this test is failing it would be due to an error in isNvmAvailable()
expect(getNvmToolDirectory(22)).toBeFalsy();
expect(getOrInstallNvmTool(14)).toBeFalsy();
}
}
});
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "10.9.8",
"version": "10.9.9",
"exports": "./index.js",
"include": ["*.js", "bin/**", "data/**", "types/**"],
"exclude": ["test/", "docs/", "contrib/", "ci/", "tools_config/"]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "10.9.8",
"version": "10.9.9",
"description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
"homepage": "http://github.com/cyclonedx/cdxgen",
"author": "Prabhu Subramanian <[email protected]>",
Expand Down
9 changes: 4 additions & 5 deletions pregen.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { spawn, spawnSync } from "node:child_process";
import { spawnSync } from "node:child_process";
import { mkdtempSync, readdirSync } from "node:fs";
import { arch, platform, tmpdir } from "node:os";
import { delimiter, join } from "node:path";
import {
SDKMAN_TOOL_ALIASES,
getNvmToolDirectory,
getOrInstallNvmTool,
installSdkmanTool,
isNvmAvailable,
Expand Down Expand Up @@ -184,7 +183,7 @@ export function tryLoadNvmAndInstallTool(nodeVersion) {
fi
`;

const spawnedShell = spawnSync(process.env.SHELL || "bash", ["-c", command], {
const result = spawnSync(process.env.SHELL || "bash", ["-c", command], {
encoding: "utf-8",
shell: process.env.SHELL || true,
});
Expand Down Expand Up @@ -228,10 +227,10 @@ export function doNpmInstall(filePath, nvmNodePath) {
// There was some problem with NpmInstall
if (DEBUG_MODE) {
if (console.stdout) {
console.log(result.stdout);
console.log(resultNpmInstall.stdout);
}
if (console.stderr) {
console.log(result.stderr);
console.log(resultNpmInstall.stderr);
}
}
}
Expand Down

0 comments on commit 38cd3df

Please sign in to comment.