-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not mark github release as latest if higher version exists (#69)
* fix: do not mark github release as latest if higher version exists * chore: adjust tests for a new github request
- Loading branch information
1 parent
95377fd
commit 3cfd8c6
Showing
8 changed files
with
165 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { rest } from 'msw' | ||
import { DeferredPromise } from '@open-draft/deferred-promise' | ||
import { testEnvironment } from '../../../../test/env' | ||
import { mockRepo } from '../../../../test/fixtures' | ||
import type { GitHubRelease } from '../getGitHubRelease' | ||
import { createGitHubRelease } from '../createGitHubRelease' | ||
|
||
const { setup, reset, cleanup, api } = testEnvironment({ | ||
fileSystemPath: 'create-github-release', | ||
}) | ||
|
||
beforeAll(async () => { | ||
await setup() | ||
}) | ||
|
||
afterEach(async () => { | ||
await reset() | ||
}) | ||
|
||
afterAll(async () => { | ||
await cleanup() | ||
}) | ||
|
||
it('marks the release as non-latest if there is a higher version released on GitHub', async () => { | ||
const repo = mockRepo() | ||
const requestBodyPromise = new DeferredPromise() | ||
api.use( | ||
rest.get<never, never, GitHubRelease>( | ||
`https://api.github.com/repos/:owner/:name/releases/latest`, | ||
(req, res, ctx) => { | ||
return res( | ||
// Set the latest GitHub release as v2.0.0. | ||
ctx.json({ | ||
tag_name: 'v2.0.0', | ||
html_url: '/v2.0.0', | ||
}), | ||
) | ||
}, | ||
), | ||
rest.post<never, never, GitHubRelease>( | ||
`https://api.github.com/repos/:owner/:name/releases`, | ||
(req, res, ctx) => { | ||
requestBodyPromise.resolve(req.json()) | ||
return res( | ||
ctx.status(201), | ||
ctx.json({ | ||
tag_name: 'v1.1.1', | ||
html_url: '/v1.1.1', | ||
}), | ||
) | ||
}, | ||
), | ||
) | ||
|
||
// Try to release a backport version for v1.0.0. | ||
const notes = '# Release notes' | ||
const githubRelease = await createGitHubRelease( | ||
{ | ||
repo, | ||
nextRelease: { | ||
version: '1.1.1', | ||
tag: 'v1.1.1', | ||
publishedAt: new Date(), | ||
}, | ||
}, | ||
notes, | ||
) | ||
expect(githubRelease).toHaveProperty('html_url', '/v1.1.1') | ||
|
||
const requestBody = await requestBodyPromise | ||
expect(requestBody).toEqual({ | ||
tag_name: 'v1.1.1', | ||
name: 'v1.1.1', | ||
body: notes, | ||
// Must set "false" as the value of the "make_latest" property. | ||
make_latest: 'false', | ||
}) | ||
}) |
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