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

Generated test mocks cannot be consumed #2672

Closed
StarLard opened this issue Nov 16, 2022 · 3 comments
Closed

Generated test mocks cannot be consumed #2672

StarLard opened this issue Nov 16, 2022 · 3 comments

Comments

@StarLard
Copy link

Bug report

The Package.swift file generated when using the moduleType: .swiftPackageManager and testMocks: .swiftPackage options only defines a target for the test mocks, but does not define a product which uses the defined target. This means that there is no way to consume the mock target outside of the generated package. A work around is to manually modify the generated file, but such changes will be overridden on subsequent file generations.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.3
  • Xcode version: 14.0.1
  • Swift version: 5.7
  • Package manager: SPM

Steps to reproduce

  1. Generate code using moduleType: .swiftPackageManager and testMocks: .swiftPackage options
  2. Add generated package to project
  3. Attempt to add test mocks to target
  4. Observe missing product

Further details

Sample Package.swift

let package = Package(
  name: "MyAppGraphQL",
  platforms: [
    .iOS(.v12),
    .macOS(.v10_14),
    .tvOS(.v12),
    .watchOS(.v5),
  ],
  products: [
    .library(name: "MyAppGraphQL", targets: ["MyAppGraphQL"]),
  ],
  dependencies: [
    .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"),
  ],
  targets: [
    .target(
      name: "MyAppGraphQL",
      dependencies: [
        .product(name: "ApolloAPI", package: "apollo-ios"),
      ],
      path: "./Sources"
    ),
    .target(
      name: "MyAppGraphQLTestMocks",
      dependencies: [
        .product(name: "ApolloTestSupport", package: "apollo-ios"),
        .target(name: "MyAppGraphQL"),
      ],
      path: "./TestMocks"
    ),
  ]
)

Expected Package.swift

let package = Package(
  name: "MyAppGraphQL",
  platforms: [
    .iOS(.v12),
    .macOS(.v10_14),
    .tvOS(.v12),
    .watchOS(.v5),
  ],
  products: [
    .library(name: "MyAppGraphQL", targets: ["MyAppGraphQL"]),
    .library(name: "MyAppGraphQLTestMocks", targets: ["MyAppGraphQLTestMocks"]),
  ],
  dependencies: [
    .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"),
  ],
  targets: [
    .target(
      name: "MyAppGraphQL",
      dependencies: [
        .product(name: "ApolloAPI", package: "apollo-ios"),
      ],
      path: "./Sources"
    ),
    .target(
      name: "MyAppGraphQLTestMocks",
      dependencies: [
        .product(name: "ApolloTestSupport", package: "apollo-ios"),
        .target(name: "MyAppGraphQL"),
      ],
      path: "./TestMocks"
    ),
  ]
)
@Gois
Copy link
Contributor

Gois commented Nov 17, 2022

This issue was fixed with PR: #2638 but that hasn't been released yet.

@StarLard
Copy link
Author

Awesome thanks! Looking forward to the next release 👍

@calvincestari
Copy link
Member

1.0.4 was released on Friday, and yes, it has a fix for this issue. Please let me know if that still doesn't resolve the problem for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants