-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(changelog): get from jsDelivr filelist if possible (#640)
Co-authored-by: Haroen Viaene <[email protected]>
- Loading branch information
Showing
3 changed files
with
145 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { getChangelogs, baseUrlMap } from '../changelog'; | ||
import { getChangelogs, baseUrlMap, getChangelog } from '../changelog'; | ||
import * as jsDelivr from '../jsDelivr'; | ||
|
||
jest.mock('got', () => { | ||
const gotSnapshotUrls = new Set([ | ||
|
@@ -16,6 +17,12 @@ jest.mock('got', () => { | |
}; | ||
}); | ||
|
||
const spy = jest | ||
.spyOn(jsDelivr, 'getFilesList') | ||
.mockImplementation((): Promise<any[]> => { | ||
return Promise.resolve([]); | ||
}); | ||
|
||
describe('should test baseUrlMap', () => { | ||
it('should work with paths', () => { | ||
const bitbucketRepo = { | ||
|
@@ -210,3 +217,76 @@ it('should work with HISTORY.md', async () => { | |
'https://raw.githubusercontent.com/expressjs/body-parser/master/HISTORY.md' | ||
); | ||
}); | ||
|
||
describe('jsDelivr', () => { | ||
it('should early return when finding changelog', async () => { | ||
spy.mockResolvedValue([ | ||
{ name: '/package.json', hash: '', time: '1', size: 1 }, | ||
{ name: '/CHANGELOG.md', hash: '', time: '1', size: 1 }, | ||
]); | ||
|
||
const { changelogFilename } = await getChangelog({ | ||
name: 'foo', | ||
version: '1.0.0', | ||
repository: { | ||
url: '', | ||
host: 'github.com', | ||
user: 'expressjs', | ||
project: 'body-parser', | ||
path: '', | ||
head: 'master', | ||
branch: 'master', | ||
}, | ||
}); | ||
expect(jsDelivr.getFilesList).toHaveBeenCalled(); | ||
expect(changelogFilename).toEqual( | ||
'https://cdn.jsdelivr.net/npm/[email protected]/CHANGELOG.md' | ||
); | ||
}); | ||
|
||
it('should early return when finding changelog in nested file', async () => { | ||
spy.mockResolvedValue([ | ||
{ name: '/pkg/CHANGELOG.md', hash: '', time: '1', size: 1 }, | ||
]); | ||
|
||
const { changelogFilename } = await getChangelog({ | ||
name: 'foo', | ||
version: '1.0.0', | ||
repository: { | ||
url: '', | ||
host: 'github.com', | ||
user: 'expressjs', | ||
project: 'body-parser', | ||
path: '', | ||
head: 'master', | ||
branch: 'master', | ||
}, | ||
}); | ||
expect(jsDelivr.getFilesList).toHaveBeenCalled(); | ||
expect(changelogFilename).toEqual( | ||
'https://cdn.jsdelivr.net/npm/[email protected]/pkg/CHANGELOG.md' | ||
); | ||
}); | ||
|
||
it('should not register a file looking like a changelog', async () => { | ||
spy.mockResolvedValue([ | ||
{ name: '/dist/changelog.js', hash: '', time: '1', size: 1 }, | ||
]); | ||
|
||
const { changelogFilename } = await getChangelog({ | ||
name: 'foo', | ||
version: '1.0.0', | ||
repository: { | ||
url: '', | ||
host: 'github.com', | ||
user: 'hello', | ||
project: 'foo', | ||
path: '', | ||
head: 'master', | ||
branch: 'master', | ||
}, | ||
}); | ||
expect(jsDelivr.getFilesList).toHaveBeenCalled(); | ||
expect(changelogFilename).toEqual(null); | ||
}); | ||
}); |
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