Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inline mode] Fix a bug with multiple updates for the inline comment. #551

Merged
merged 2 commits into from
Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Master

* Item. [@name][]
* Fixed a bug where updating multiple inline comments caused a Javascript error [@sunshinejr][]

## 3.4.2

Expand Down
2 changes: 1 addition & 1 deletion source/runner/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class Executor {
let promise: Promise<any>
if (index != -1) {
let previousComment = deleteComments[index]
delete deleteComments[index]
deleteComments.splice(index, 1)
promise = this.updateInlineComment(inlineResult, previousComment)
} else {
promise = this.sendInlineComment(git, inlineResult)
Expand Down
20 changes: 20 additions & 0 deletions source/runner/_tests/_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
inlineRegularResults,
inlineFailResults,
inlineMessageResults,
inlineMultipleWarnResults,
inlineMultipleWarnResults2,
} from "./fixtures/ExampleDangerResults"
import inlineRunner from "../runners/inline"
import { jsonDSLGenerator } from "../dslGenerator"
Expand Down Expand Up @@ -162,6 +164,24 @@ describe("setup", () => {
expect(platform.createInlineComment).not.toBeCalled()
})

it("Updates multiple inline comments", async () => {
const platform = new FakePlatform()
const exec = new Executor(new FakeCI({}), platform, inlineRunner, defaultConfig)
const dsl = await defaultDsl(platform)
const previousResults = inlineMultipleWarnResults
const newResults = inlineMultipleWarnResults2
const previousComments = mockPayloadForResults(previousResults)
platform.getInlineComments = jest.fn().mockReturnValue(new Promise(r => r(previousComments)))
platform.updateInlineComment = jest.fn()
platform.createInlineComment = jest.fn()
platform.deleteInlineComment = jest.fn()

await exec.handleResults(newResults, dsl.git)
expect(platform.updateInlineComment).toHaveBeenCalledTimes(3)
expect(platform.createInlineComment).not.toBeCalled()
expect(platform.deleteInlineComment).not.toBeCalled()
})

it("Doesn't update/create an inline comment as the old was the same as the new", async () => {
const platform = new FakePlatform()
const exec = new Executor(new FakeCI({}), platform, inlineRunner, defaultConfig)
Expand Down
22 changes: 22 additions & 0 deletions source/runner/_tests/fixtures/ExampleDangerResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ export const inlineWarnResults: DangerResults = {
markdowns: [],
}

export const inlineMultipleWarnResults: DangerResults = {
messages: [],
warnings: [
{ message: "Test message", file: "File.swift", line: 10 },
{ message: "Test message", file: "File.swift", line: 11 },
{ message: "Test message", file: "File2.swift", line: 10 },
],
fails: [],
markdowns: [],
}

export const inlineMultipleWarnResults2: DangerResults = {
messages: [],
warnings: [
{ message: "Test message2", file: "File.swift", line: 10 },
{ message: "Test message2", file: "File.swift", line: 11 },
{ message: "Test message2", file: "File2.swift", line: 10 },
],
fails: [],
markdowns: [],
}

export const inlineFailResults: DangerResults = {
messages: [],
warnings: [],
Expand Down