Skip to content

Commit 9861d64

Browse files
committed
feat: fix tests
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent 1ce936c commit 9861d64

File tree

8 files changed

+85
-49
lines changed

8 files changed

+85
-49
lines changed

.eslintrc.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"root": true,
3-
"extends": [
4-
"eslint:recommended",
5-
"plugin:editorconfig/all"
6-
],
7-
"parserOptions": {
8-
"ecmaVersion": 2022,
9-
"sourceType": "module"
10-
},
11-
"env": {
12-
"node": true,
13-
"mocha": true,
14-
"es6": true
15-
},
16-
"plugins": [
17-
"editorconfig"
18-
],
19-
"rules": {
20-
"curly": "warn",
21-
"eqeqeq": "warn",
22-
"no-throw-literal": "warn",
23-
"sort-imports":"warn"
24-
},
25-
"ignorePatterns": [
26-
"integration"
27-
]
28-
}
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:editorconfig/all"
6+
],
7+
"parserOptions": {
8+
"ecmaVersion": 2022,
9+
"sourceType": "module"
10+
},
11+
"env": {
12+
"node": true,
13+
"mocha": true,
14+
"es6": true
15+
},
16+
"plugins": [
17+
"editorconfig"
18+
],
19+
"rules": {
20+
"curly": "warn",
21+
"eqeqeq": "warn",
22+
"no-throw-literal": "warn",
23+
"sort-imports": "warn"
24+
},
25+
"ignorePatterns": [
26+
"integration"
27+
]
28+
}

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
"fast-toml": "^0.5.4",
5454
"fast-xml-parser": "^4.2.4",
5555
"help": "^3.0.2",
56+
"node-fetch": "^2.6.7",
5657
"packageurl-js": "^1.0.2",
57-
"yargs": "^17.7.2",
58-
"node-fetch": "^2.6.7"
58+
"yargs": "^17.7.2"
5959
},
6060
"devDependencies": {
6161
"@babel/core": "^7.23.2",
@@ -104,6 +104,5 @@
104104
},
105105
"eslintIgnore": [
106106
"index.js"
107-
],
108-
"packageManager": "[email protected]+sha512.0e82714d1b5b43c74610193cb20734897c1d00de89d0e18420aebc5977fa13d780a9cb05734624e81ebd81cc876cd464794850641c48b9544326b5622ca29971"
107+
]
109108
}

src/provider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import path from 'node:path'
2+
13
import golangGomodulesProvider from './providers/golang_gomodules.js'
24
import Java_gradle_groovy from "./providers/java_gradle_groovy.js";
35
import Java_gradle_kotlin from "./providers/java_gradle_kotlin.js";
46
import Java_maven from "./providers/java_maven.js";
5-
import path from 'node:path'
67
import pythonPipProvider from './providers/python_pip.js'
78
import Javascript_npm from './providers/javascript_npm.js';
89
import Javascript_pnpm from './providers/javascript_pnpm.js';
@@ -29,7 +30,7 @@ export const availableProviders = [new Java_maven(), new Java_gradle_groovy(), n
2930
export function match(manifest, providers) {
3031
const manifestPath = path.parse(manifest)
3132
const supported = providers.filter(prov => prov.isSupported(manifestPath.base))
32-
if (supported.length == 0) {
33+
if (supported.length === 0) {
3334
throw new Error(`${manifestPath.base} is not supported`)
3435
}
3536
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir))

src/providers/base_java.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PackageURL } from 'packageurl-js'
2+
23
import { invokeCommand } from "../tools.js"
34

45

@@ -44,7 +45,7 @@ export default class Base_Java {
4445
let matchedScope = target.match(/:compile|:provided|:runtime|:test|:system|:import/g)
4546
let matchedScopeSrc = src.match(/:compile|:provided|:runtime|:test|:system|:import/g)
4647
// only add dependency to sbom if it's not with test scope or if it's root
47-
if ((matchedScope && matchedScope[0] !== ":test" && (matchedScopeSrc && matchedScopeSrc[0] !== ":test")) || (srcDepth == 0 && matchedScope && matchedScope[0] !== ":test")) {
48+
if ((matchedScope && matchedScope[0] !== ":test" && (matchedScopeSrc && matchedScopeSrc[0] !== ":test")) || (srcDepth === 0 && matchedScope && matchedScope[0] !== ":test")) {
4849
sbom.addDependency(sbom.purlToComponent(from), to)
4950
}
5051
} else {

src/providers/base_javascript.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import fs from 'node:fs'
22
import os from "node:os";
3-
import { handleSpacesInPath, invokeCommand } from "../tools.js";
43
import path from 'node:path'
5-
import Sbom from '../sbom.js'
64
import { PackageURL } from 'packageurl-js'
75

6+
import { invokeCommand } from "../tools.js";
7+
import Sbom from '../sbom.js'
8+
89
/** @typedef {import('../provider.js').Provider} */
910

1011
/** @typedef {import('../provider.js').Provided} Provided */
@@ -171,7 +172,7 @@ export default class Base_javascript {
171172
#executeListCmd(includeTransitive, manifestDir) {
172173
const listArgs = this._listCmdArgs(includeTransitive, manifestDir);
173174
try {
174-
invokeCommand(this._cmdName(), listArgs)
175+
return invokeCommand(this._cmdName(), listArgs)
175176
} catch (error) {
176177
throw new Error(`failed to list dependencies via "${this._cmdName()} ${listArgs.join(' ')}" - Error: ${error}`, {cause: error});
177178
}
@@ -195,9 +196,8 @@ export default class Base_javascript {
195196
if (os.platform() === 'win32') {
196197
process.chdir(manifestDir)
197198
}
198-
199+
const args = this._updateLockFileCmdArgs(manifestDir);
199200
try {
200-
const args = this._updateLockFileCmdArgs(manifestDir);
201201
invokeCommand(this._cmdName(), args)
202202
} catch (error) {
203203
throw new Error(`failed to create lockfile "${args}" - Error: ${error}`, {cause: error});

src/providers/javascript_pnpm.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ export default class Javascript_pnpm extends Base_javascript {
1111
}
1212

1313
_listCmdArgs(includeTransitive, manifestDir) {
14-
const args = ['ls', includeTransitive ? '--all' : '--depth=0', '--prod', '--json'];
14+
const args = ['ls', includeTransitive ? '--depth=Infinity' : '--depth=0', '--prod', '--json'];
1515
if (manifestDir) {
16-
args.push('--prefix', manifestDir);
16+
args.push('--dir', manifestDir);
1717
}
1818
return args;
1919
}
2020

2121
_updateLockFileCmdArgs(manifestDir) {
2222
const args = ['install', '--frozen-lockfile'];
2323
if (manifestDir) {
24-
args.push('--prefix', manifestDir)
24+
args.push('--dir', manifestDir)
2525
}
2626
args.push(...[])
2727
return args;

test/providers/javascript.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ let clock
99

1010
async function mockProvider(providerName, listingOutput) {
1111

12-
const mockExecSync = (cmd) => {
13-
if (cmd.includes('--version')) { return ''; }
12+
const mockInvokeCommand = (_cmd, args) => {
13+
if (args.includes('--version')) {return '';}
1414
return listingOutput;
15-
}
15+
};
1616

17-
return esmock(`../../src/providers/Javascript_${providerName}.js`, {
18-
'../../src/providers/Base_javascript.js': await esmock('../../src/providers/base_javascript.js', {
19-
'node:child_process': {
20-
execSync: mockExecSync
17+
return esmock(`../../src/providers/javascript_${providerName}.js`, {
18+
'../../src/providers/base_javascript.js': await esmock('../../src/providers/base_javascript.js', {
19+
'../../src/tools.js': {
20+
invokeCommand: mockInvokeCommand
2121
}
2222
})
2323
});

0 commit comments

Comments
 (0)