Skip to content

Commit f1d02ec

Browse files
committed
tests
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent fe64d90 commit f1d02ec

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"c8": "^10",
9898
"deepmerge": "^4.2.2",
9999
"fast-glob": "^3.3.1",
100+
"memfs": "4.17.2",
100101
"mocha": "11.5.0",
101102
"npm-run-all2": "^8",
102103
"rimraf": "^6",
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
19+
20+
const assert = require('node:assert')
21+
22+
const { memfs } = require('memfs')
23+
const { suite, test } = require('mocha')
24+
25+
const {
26+
Utils: { LicenseUtility: { LicenseEvidenceGatherer } }
27+
} = require('../../')
28+
29+
suite('integration: Utils.LicenseUtility.LicenseEvidenceGatherer', () => {
30+
test('no path -> throws', () => {
31+
const { fs } = memfs({ '/': {} })
32+
const leg = new LicenseEvidenceGatherer({ fs })
33+
assert.throws(() => {
34+
Array.from(leg.getFileAttachments('/foo'))
35+
},
36+
{
37+
code: 'ENOENT',
38+
message: "ENOENT: no such file or directory, scandir '/foo'",
39+
path: '/foo',
40+
}
41+
)
42+
})
43+
44+
test('no files', () => {
45+
const { fs } = memfs({ '/': {} })
46+
const leg = new LicenseEvidenceGatherer({ fs })
47+
const errors = []
48+
const found = Array.from(
49+
leg.getFileAttachments(
50+
'/',
51+
(e) => { errors.push(e) }
52+
))
53+
assert.deepEqual(found, [])
54+
assert.deepEqual(errors, [])
55+
})
56+
})

tests/unit/internals/helpers.mime.node.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ suite('unit: internals: helpers.mime.getMimeForLicenseFile', () => {
3232
['license.md', 'text/markdown'],
3333
['info.xml', 'text/xml'],
3434
['UNKNOWN', 'text/plain'],
35-
['LICENCE.MIT', 'text/plain']
35+
['LICENCE.MIT', 'text/plain'],
36+
['mit.license', 'text/plain']
3637
]) {
3738
test(fileName, () => {
3839
const value = guessMimeTypeForLicenseFile(fileName)

0 commit comments

Comments
 (0)