Skip to content

Commit ded410c

Browse files
committed
tests
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent bfa43f0 commit ded410c

3 files changed

Lines changed: 40 additions & 18 deletions

File tree

src/factories/fromNodePackageJson.node.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,20 @@ export class ExternalReferenceFactory {
112112
const { tarball, integrity, shasum } = data.dist ?? {}
113113
if (typeof tarball === 'string') {
114114
const hashes = new HashDictionary()
115-
const hashSources = []
115+
let comment = 'as detected from PackageJson property "dist.tarball"'
116116
if (typeof integrity === 'string') {
117117
try {
118118
// actually not the hash of the file, but more of an integrity-check -- lets use it anyway.
119119
// see https://blog.npmjs.org/post/172999548390/new-pgp-machinery
120120
hashes.set(...parsePackageIntegrity(integrity))
121-
hashSources.push(' and property "dist.integrity"')
121+
comment += ' and property "dist.integrity"'
122122
} catch { /* pass */ }
123123
}
124124
if (typeof shasum === 'string' && shasum.length === 40) {
125125
hashes.set(HashAlgorithm["SHA-1"], shasum)
126-
hashSources.push(' and property "dist.shasum"')
126+
comment += ' and property "dist.shasum"'
127127
}
128-
return new ExternalReference(
129-
tarball,
130-
ExternalReferenceType.Distribution,
131-
{
132-
hashes,
133-
comment: `as detected from PackageJson property "dist.tarball"${hashSources.join('')}`
134-
}
135-
)
128+
return new ExternalReference(tarball, ExternalReferenceType.Distribution, { hashes, comment })
136129
}
137130
return undefined
138131
}

tests/integration/Factories.FromNodePackageJson.ExternalReferenceFactory.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ suite('integration: Factories.FromNodePackageJson.ExternalReferenceFactory', ()
9797
assert.strictEqual(actual.length, 0)
9898
})
9999
})
100+
100101
suite('from "repository"', () => {
101102
test('non-empty string', () => {
102103
const expected = [new ExternalReference(
@@ -267,4 +268,38 @@ suite('integration: Factories.FromNodePackageJson.ExternalReferenceFactory', ()
267268
assert.deepEqual(actual, expected)
268269
})
269270
})
271+
272+
273+
})
274+
275+
suite('integration: Factories.FromNodePackageJson.ExternalReferenceFactory', () => {
276+
const factory = new ExternalReferenceFactory()
277+
278+
const cases = {
279+
makeVcs: [
280+
// TODO
281+
],
282+
makeHomepage: [
283+
// TODO
284+
],
285+
makeIssueTracker: [
286+
// TODO
287+
],
288+
makeDist: [
289+
// TODO
290+
],
291+
}
292+
cases.makeExternalReferences = [
293+
// TODO
294+
]
295+
for (const [func, testData] of Object.entries(cases)) {
296+
suite(func, () => {
297+
for (const [label, data, expected] of testData) {
298+
test(label, () => {
299+
const actual = factory[func](data)
300+
assert.deepStrictEqual(actual, expected)
301+
})
302+
}
303+
})
304+
}
270305
})

tests/unit/Factories.FromNodePackageJson.PackageUrlFactory.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@ const assert = require('node:assert')
2222
const { suite, test } = require('mocha')
2323

2424
const {
25-
Factories: { FromNodePackageJson: {
26-
ExternalReferenceFactory, PackageUrlFactory
27-
}},
25+
Factories: { FromNodePackageJson: { PackageUrlFactory }},
2826
Enums: { ComponentType, ExternalReferenceType },
2927
Models: { Component, ExternalReference, ExternalReferenceRepository }
3028
} = require('../../')
3129

32-
suite('unit: Factories.FromNodePackageJson.ExternalReferenceFactory', () => {
33-
// TODO
34-
})
35-
3630
suite('unit: Factories.FromNodePackageJson.PackageUrlFactory', () => {
3731
suite('makeFromComponent()', () => {
3832
test('plain', () => {

0 commit comments

Comments
 (0)