update replace behavior

This commit is contained in:
Michael Shick 2023-05-07 09:03:15 -04:00
parent 25e7c93662
commit ff82b38f95
No known key found for this signature in database
GPG key ID: ADF5BC9704BB4A61
3 changed files with 36 additions and 5 deletions

View file

@ -97,10 +97,7 @@ const handlers = [
const server = setupServer(...handlers)
beforeAll(() => {
// vi.spyOn(console, 'log').mockImplementation(() => {})
// vi.spyOn(core, 'debug').mockImplementation(() => {})
// vi.spyOn(core, 'info').mockImplementation(() => {})
// vi.spyOn(core, 'warning').mockImplementation(() => {})
vi.spyOn(console, 'log').mockImplementation(() => {})
server.listen({ onUnhandledRequest: 'error' })
})
afterAll(() => server.close())
@ -517,6 +514,35 @@ describe('find and replace', () => {
expect(core.setOutput).toHaveBeenCalledWith('comment-id', commentId)
})
it('can multiple find and replace a single pattern with a multiline replacement', async () => {
inputs['find'] = 'hello'
inputs['message'] = 'h\ne\nl\nl\no'
const body = `<!-- add-pr-comment:${inputs['message-id']} -->\n\nhello\nworld`
const commentId = 123
const replyBody = [
{
id: commentId,
body,
},
]
getIssueCommentsResponse = replyBody
postIssueCommentsResponse = {
id: commentId,
}
await run()
expect(`<!-- add-pr-comment:add-pr-comment -->\n\nh\ne\nl\nl\no\nworld`).toEqual(
messagePayload?.body,
)
expect(core.setOutput).toHaveBeenCalledWith('comment-updated', 'true')
expect(core.setOutput).toHaveBeenCalledWith('comment-id', commentId)
})
it('can multiple find and replace text using a message-path', async () => {
inputs['find'] = '<< FILE_CONTENTS >>'
inputs['message-path'] = messagePath1Fixture