-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use properties of object entries as custom field (#194)
Example: use custom field 'repository.url'.
- Loading branch information
Showing
15 changed files
with
432 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,57 @@ describe('addLocalPackageData', () => { | |
assert.ok(depsIndexElement.installedVersion); | ||
assert.strictEqual(depsIndexElement.installedVersion, 'n/a'); | ||
}); | ||
|
||
it('adds package data for custom field', async () => { | ||
const depsIndexElement = { | ||
fullName: 'my-local-package', | ||
alias: 'my-local-package', | ||
name: 'my-local-package', | ||
version: 'file:local-libs/my-local-package', | ||
}; | ||
const customFields = [ | ||
'author', | ||
'description', | ||
]; | ||
await addLocalPackageData(depsIndexElement, projectRootPath, customFields); | ||
|
||
assert.ok(depsIndexElement.description); | ||
assert.strictEqual(depsIndexElement.description, 'A list of color names and its values'); | ||
}); | ||
|
||
it('adds package data for object property of custom field', async () => { | ||
const depsIndexElement = { | ||
fullName: 'my-local-package', | ||
alias: 'my-local-package', | ||
name: 'my-local-package', | ||
version: 'file:local-libs/my-local-package', | ||
}; | ||
const customFields = [ | ||
'author', | ||
'repository', | ||
]; | ||
await addLocalPackageData(depsIndexElement, projectRootPath, customFields); | ||
|
||
assert.ok(depsIndexElement.repository); | ||
assert.deepStrictEqual(depsIndexElement.repository, {type: "git",url: "[email protected]:colors/my-local-package.git"}); | ||
}); | ||
|
||
it('adds package data for nested property of custom field', async () => { | ||
const depsIndexElement = { | ||
fullName: 'my-local-package', | ||
alias: 'my-local-package', | ||
name: 'my-local-package', | ||
version: 'file:local-libs/my-local-package', | ||
}; | ||
const customFields = [ | ||
'name', | ||
'repository.url', | ||
]; | ||
await addLocalPackageData(depsIndexElement, projectRootPath, customFields); | ||
|
||
assert.ok(depsIndexElement['repository.url']); | ||
assert.strictEqual(depsIndexElement['repository.url'], '[email protected]:colors/my-local-package.git'); | ||
}); | ||
}); | ||
|
||
describe('addLocalPackageData with monorepo', () => { | ||
|
@@ -182,44 +233,86 @@ describe('addLocalPackageData', () => { | |
|
||
describe('addLocalPackageData with custom fields', () => { | ||
let projectRootPath; | ||
const fields = [ | ||
'name', | ||
'material', | ||
'licenseType', | ||
'homepage', | ||
'definedVersion', | ||
'author', | ||
'bugs', | ||
]; | ||
|
||
beforeEach(() => { | ||
projectRootPath = path | ||
.resolve(__dirname, 'fixture', 'add-local-data') | ||
.replace(/(\s+)/g, '\\$1'); | ||
}); | ||
|
||
it('adds package data for package in root level', async () => { | ||
it('adds package data for default and custom fields', async () => { | ||
const fields = [ | ||
'name', | ||
'material', | ||
'licenseType', | ||
'homepage', | ||
'definedVersion', | ||
'author', | ||
'bugs', | ||
]; | ||
|
||
const depsIndexElement = { | ||
fullName: '@kessler/tableify', | ||
alias: '', | ||
name: 'tableify', | ||
version: '^1.0.2', | ||
scope: '@kessler', | ||
}; | ||
|
||
const expectedResult = { | ||
fullName: "@kessler/tableify", | ||
alias: "", | ||
name: "tableify", | ||
version: "^1.0.2", | ||
scope: "@kessler", | ||
installedVersion: "1.0.2", | ||
author: "Dan VerWeire, Yaniv Kessler", | ||
licenseType: "MIT", | ||
homepage: "https://github.com/kessler/node-tableify", | ||
bugs: { | ||
url: "https://github.com/kessler/node-tableify/issues", | ||
}, | ||
}; | ||
|
||
await addLocalPackageData(depsIndexElement, projectRootPath, fields); | ||
|
||
assert.ok(depsIndexElement.installedVersion); | ||
assert.strictEqual(depsIndexElement.installedVersion, '1.0.2'); | ||
assert.ok(depsIndexElement.homepage); | ||
assert.strictEqual( | ||
depsIndexElement.homepage, | ||
'https://github.com/kessler/node-tableify', | ||
); | ||
assert.ok(depsIndexElement.bugs); | ||
const expectedBugs = { | ||
url: 'https://github.com/kessler/node-tableify/issues', | ||
assert.deepStrictEqual(depsIndexElement, expectedResult); | ||
}); | ||
|
||
it('adds package data for for nested custom field', async () => { | ||
const fields = [ | ||
'name', | ||
'repository', | ||
'repository.url', | ||
]; | ||
|
||
const depsIndexElement = { | ||
fullName: '@kessler/tableify', | ||
alias: '', | ||
name: 'tableify', | ||
version: '^1.0.2', | ||
scope: '@kessler', | ||
}; | ||
|
||
const expectedResult = { | ||
fullName: "@kessler/tableify", | ||
alias: "", | ||
name: "tableify", | ||
version: "^1.0.2", | ||
scope: "@kessler", | ||
installedVersion: "1.0.2", | ||
author: "Dan VerWeire, Yaniv Kessler", | ||
licenseType: "MIT", | ||
repository: { | ||
type: "git", | ||
url: "https://github.com/kessler/node-tableify.git", | ||
}, | ||
"repository.url": "https://github.com/kessler/node-tableify.git", | ||
}; | ||
assert.deepStrictEqual(depsIndexElement.bugs, expectedBugs); | ||
|
||
await addLocalPackageData(depsIndexElement, projectRootPath, fields); | ||
|
||
assert.deepStrictEqual(depsIndexElement, expectedResult); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.