-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: `versionInfo` Add full test coverage resolving the `versionInfo` * fix: whitespace * fix: update the test * fix: just get the test to pass * fix: substring --------- Co-authored-by: Tom Hu <thomas.hu@sentry.io>
- Loading branch information
1 parent
a87fadc
commit a06c39c
Showing
1 changed file
with
62 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as core from '@actions/core'; | ||
import {Agent, MockAgent, setGlobalDispatcher} from 'undici'; | ||
|
||
import versionInfo from './version'; | ||
|
||
const mockAgent = new MockAgent(); | ||
|
||
beforeAll(() => { | ||
setGlobalDispatcher(mockAgent); | ||
mockAgent.disableNetConnect(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await mockAgent.close(); | ||
setGlobalDispatcher(new Agent()); | ||
}); | ||
|
||
describe('versionInfo', () => { | ||
const platform = 'linux'; | ||
|
||
test('should resolve requested version info', async () => { | ||
const version = 'latest'; | ||
const coreInfoSpy = jest.spyOn(core, 'info'); | ||
|
||
mockAgent | ||
.get('https://cli.codecov.io') | ||
.intercept({ | ||
path: `/${platform}/${version}`, | ||
}) | ||
.reply(200, { | ||
version: 'v0.5.2', | ||
}); | ||
|
||
await versionInfo(platform, version); | ||
|
||
expect(coreInfoSpy).toHaveBeenCalledTimes(2); | ||
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version latest'); | ||
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version v0.5.2'); | ||
}); | ||
|
||
test('should handle unsupported version', async () => { | ||
const version = 'unsupported'; | ||
const coreInfoSpy = jest.spyOn(core, 'info'); | ||
|
||
mockAgent | ||
.get('https://cli.codecov.io') | ||
.intercept({ | ||
path: `/${platform}/${version}`, | ||
}) | ||
.reply(404, 'MESSAGE'); | ||
|
||
await versionInfo(platform, version); | ||
|
||
expect(coreInfoSpy).toHaveBeenCalledTimes(2); | ||
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version unsupported'); | ||
expect(coreInfoSpy).toHaveBeenCalledWith(expect.stringContaining('Could not pull latest version information')); | ||
}); | ||
}); |