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

Support custom danger-js path #206

Merged
merged 1 commit into from Mar 5, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/RunnerLib/GetDangerJSPath.swift
@@ -0,0 +1,13 @@
import Foundation
import Logger
import ShellOut

public func getDangerCommandPath(logger: Logger, args: [String] = CommandLine.arguments, shellOutExecutor: ShellOutExecuting = ShellOutExecutor()) throws -> String {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ⚠️ Line should be 120 characters or less: currently 165 characters (line_length)

if let dangerJSPathOptionIndex = args.firstIndex(of: "--danger-js-path"),
dangerJSPathOptionIndex + 1 < args.count {
return args[dangerJSPathOptionIndex + 1]
} else {
logger.debug("Finding out where the danger executable is")
return try shellOutExecutor.shellOut(command: "which danger").trimmingCharacters(in: .whitespaces)
}
}
8 changes: 0 additions & 8 deletions Sources/RunnerLib/getDangerJSPath.swift

This file was deleted.

23 changes: 23 additions & 0 deletions Tests/RunnerLibTests/GetDangerJSPathTests.swift
@@ -0,0 +1,23 @@
import XCTest
import Logger
@testable import RunnerLib

final class GetDangerJSPathTests: XCTestCase {
private let logger = Logger(isVerbose: false, isSilent: false, printer: SpyPrinter())

func testItUsesTheDangerJSPathOptionIfPresent() throws {
let expectedResult = "/franco/test/danger-js"
let path = try getDangerCommandPath(logger: logger, args: ["test", "--danger-js-path", expectedResult])
XCTAssertEqual(path, expectedResult)
}

func testItSearchesForDangerJSIfTheDangerJSPathOptionIsNotPresent() throws {
let executor = MockedExecutor()
let expectedResult = "/usr/test/danger-js"
executor.result = expectedResult

let path = try getDangerCommandPath(logger: logger, args: [], shellOutExecutor: executor)
XCTAssertEqual(executor.receivedCommand, "which danger")
XCTAssertEqual(path, expectedResult)
}
}