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

Generate library for test mock target #2638

Merged
merged 2 commits into from
Nov 10, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ struct SwiftPackageManagerModuleTemplate: TemplateRenderer {
],
products: [
.library(name: "\(casedSchemaName)", targets: ["\(casedSchemaName)"]),
\(ifLet: testMockTarget(), { """
.library(name: "\($0.targetName)", targets: ["\($0.targetName)"]),
"""})
],
dependencies: [
.package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,26 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
// then
expect(actual).to(equalLineByLine(expected, atLine: 19, ignoringExtraLines: true))
}

func test__packageDescription__givenTestMockConfig_swiftPackage_noTargetName_generatesProduct() {
// given
buildSubject(testMockConfig: .swiftPackage())

let expected = """
products: [
.library(name: "TestModule", targets: ["TestModule"]),
.library(name: "TestModuleTestMocks", targets: ["TestModuleTestMocks"]),
],
"""

// when
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 13, ignoringExtraLines: true))
}


func test__packageDescription__givenTestMockConfig_swiftPackage_noTargetName_generatesTargets() {
// given
buildSubject(testMockConfig: .swiftPackage())
Expand Down Expand Up @@ -315,7 +334,25 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 19, ignoringExtraLines: true))
expect(actual).to(equalLineByLine(expected, atLine: 20, ignoringExtraLines: true))
}

func test__packageDescription__givenTestMockConfig_swiftPackage_withTargetName_generatesProduct() {
// given
buildSubject(testMockConfig: .swiftPackage(targetName: "CustomMocks"))

let expected = """
products: [
.library(name: "TestModule", targets: ["TestModule"]),
.library(name: "CustomMocks", targets: ["CustomMocks"]),
],
"""

// when
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 13, ignoringExtraLines: true))
}

func test__packageDescription__givenTestMockConfig_swiftPackage_withTargetName_generatesTargets() {
Expand Down Expand Up @@ -346,7 +383,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 19, ignoringExtraLines: true))
expect(actual).to(equalLineByLine(expected, atLine: 20, ignoringExtraLines: true))
}

func test__packageDescription__givenTestMockConfig_withLowercaseSchemaName_generatesTestMockTargetWithCapitalizedTargetDependency() {
Expand All @@ -363,7 +400,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 31, ignoringExtraLines: true))
expect(actual).to(equalLineByLine(expected, atLine: 32, ignoringExtraLines: true))
}

func test__packageDescription__givenTestMockConfig_withUppercaseSchemaName_generatesTestMockTargetWithUppercaseTargetDependency() {
Expand All @@ -380,7 +417,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 31, ignoringExtraLines: true))
expect(actual).to(equalLineByLine(expected, atLine: 32, ignoringExtraLines: true))
}

func test__packageDescription__givenTestMockConfig_withCapitalizedSchemaName_generatesTestMockTargetWithCapitalizedTargetDependency() {
Expand All @@ -397,7 +434,7 @@ class SwiftPackageManagerModuleTemplateTests: XCTestCase {
let actual = renderSubject()

// then
expect(actual).to(equalLineByLine(expected, atLine: 31, ignoringExtraLines: true))
expect(actual).to(equalLineByLine(expected, atLine: 32, ignoringExtraLines: true))
}

}