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

Add simulated location support on testable target configuration #6187

Merged
merged 7 commits into from Apr 22, 2024

Conversation

woin2ee
Copy link
Contributor

@woin2ee woin2ee commented Apr 14, 2024

Resolves #5375

Short description πŸ“

This PR adds the simulatedLocation property to the TestableTarget.

The API looks like this

testAction: .targets(
    [
        .testableTarget(
            target: "AppTests",
            simulatedLocation: .rioDeJaneiro
//          simulatedLocation: .custom(gpxFile: "Resources/Grand Canyon.gpx")
        ),
    ],
    arguments: .arguments()
)

then...

image

How to test the changes locally 🧐

Run tuist generate in the ios_app_with_custom_scheme fixture. Then check the Simulated location setting for the test target in the test action of the App-Debug or App-Release scheme of the created project.

Contributor checklist βœ…

  • The code has been linted using run mise run lint:fix
  • The change is tested via unit testing or acceptance testing, or both
  • The title of the PR is formulated in a way that is usable as a changelog entry
  • In case the PR introduces changes that affect users, the documentation has been updated

Reviewer checklist βœ…

  • The code architecture and patterns are consistent with the rest of the codebase
  • Reviewer has checked that, if needed, the PR includes the label changelog:added, changelog:fixed, or changelog:changed, and the title is usable as a changelog entry

Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

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

Great work πŸ‘

It would be amazing if we could test the location is added to the test action via an acceptance test. We can add an assertion similar to this that would check the simulated location is added for the test target and you would test that here.

Let me know if you need any help setting that up 🀞

Comment on lines 138 to 134
fileElements.formUnion(runActionGPXFiles)

let testActionGPXFiles = project.schemes.compactMap { scheme -> [GroupFileElement] in
guard let testAction = scheme.testAction else { return [] }

let elements = testAction.targets.compactMap { target -> GroupFileElement? in
guard case let .gpxFile(path) = target.simulatedLocation else {
return nil
}

return GroupFileElement(path: path, group: project.filesGroup)
}

return elements
}
.flatMap { $0 }

fileElements.formUnion(testActionGPXFiles)
Copy link
Member

Choose a reason for hiding this comment

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

Can we test the logic here in ProjectFileElementsTests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added test cases for extracting GPX files.

Comment on lines 257 to 262
try await run(BuildCommand.self, "App-Local")

let xcodeprojPath = fixturePath.appending(components: ["App", "MainApp.xcodeproj"])

try XCTAssertSimulatedLocationAdded(
xcodeprojPath: xcodeprojPath,
Copy link
Contributor Author

@woin2ee woin2ee Apr 16, 2024

Choose a reason for hiding this comment

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

For this test case, I specified the path manually because the .xcodeproj file is not generated in the root of the fixture. I would like to ask if this is a good way to do it.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's fine πŸ™Œ

@woin2ee
Copy link
Contributor Author

woin2ee commented Apr 16, 2024

I apologize for my force push. I didn't realize this would happen... πŸ˜“

Copy link
Member

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

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

Thanks a lot for adding the acceptance tests ❀️ Just two nits, afterwards, we can merge this one πŸ™‚

Comment on lines 257 to 262
try await run(BuildCommand.self, "App-Local")

let xcodeprojPath = fixturePath.appending(components: ["App", "MainApp.xcodeproj"])

try XCTAssertSimulatedLocationAdded(
xcodeprojPath: xcodeprojPath,
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's fine πŸ™Œ

/// - testTarget: A specific test target name.
/// - simulatedLocation: A simulated location. This value can be passed a `location string` or a `GPX filename`.
/// For example, "Rio de Janeiro, Brazil" or "Grand Canyon.gpx".
public func XCTAssertSimulatedLocationAdded(
Copy link
Member

Choose a reason for hiding this comment

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

nit: Can we rename this to XCTAssertContainsSimulatedLocation? It's more inline with how we name these custom assert methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! That makes sense!

line: UInt = #line
) throws {
if let xcodeprojPath {
self.xcodeprojPath = xcodeprojPath
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't override the self.xcodeprojPath, I would only use the custom one directly in this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a great way to keep it simple πŸ‘.

@fortmarek
Copy link
Member

@all-contributors add @woin2ee for code

Copy link
Contributor

@fortmarek

I've put up a pull request to add @woin2ee! πŸŽ‰

@fortmarek
Copy link
Member

Amazing work πŸ‘

@fortmarek fortmarek merged commit afcd2dc into tuist:main Apr 22, 2024
8 checks passed
@fortmarek fortmarek added the changelog:added PR will be listed in the Added section of CHANGELOG label Apr 22, 2024
@woin2ee
Copy link
Contributor Author

woin2ee commented Apr 22, 2024

I was able to finish it with your help. Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:added PR will be listed in the Added section of CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No support for simulated locations on scheme's test action configuration
2 participants