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 --skip-ui-tests parameter to tuist test command #2832

Merged
merged 12 commits into from
Jun 19, 2021

Conversation

mollyIV
Copy link
Collaborator

@mollyIV mollyIV commented Apr 28, 2021

Resolves #2562

Short description 📝

Add --skip-ui-tests parameter to tuist test command to skip UI Tests targets from being executed.

The changes in a nutshell

new project mapper called PruneUITestsProjectMapper has been introduced. It marks UI Tests targets as "to be pruned" (only if a --skip-ui-tests flag is passed) and then CacheTreeShakingGraphMapper removes marked targets ✨

Please let me know if you feel like more acceptance / unit tests should be added 🙏

Kudos to @fortmarek for help 😊

$ tuist test --skip-ui-tests

Checklist ✅

  • The code architecture and patterns are consistent with the rest of the codebase.
  • The changes have been tested following the documented guidelines.
  • The CHANGELOG.md has been updated to reflect the changes. In case of a breaking change, it's been flagged as such.
  • In case the PR introduces changes that affect users, the documentation has been updated.

@mollyIV mollyIV marked this pull request as ready for review April 28, 2021 18:04
@mollyIV mollyIV requested a review from fortmarek April 28, 2021 18:04
@@ -22,6 +22,7 @@ final class AutomationGraphMapperProvider: GraphMapperProviding {
mappers.append(
TestsCacheGraphMapper(hashesCacheDirectory: testsCacheDirectory, config: config)
)
mappers.append(CacheTreeShakingGraphMapper())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whats this cange for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This mapper is getting rid of the targets marked as prune.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned in one of the comments, I'd extract the logic of ensuring the project integrity into a new mapper and use that one instead.

Copy link
Collaborator

@luispadron luispadron left a comment

Choose a reason for hiding this comment

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

This is lookin' good! I think it will be helpful for users that are letting Tuist handle all the schemes & target generation.

mollyIV added 2 commits April 29, 2021 08:15
* main:
  Update the link to documented guidelines in pull request template (tuist#2833)
  `Dependencies.swift` documentation (tuist#2804)
  [Fix] Resources Targets should inherit their parents Deployment Version (tuist#2830)
  docs: add fila95 as a contributor (tuist#2831)
  🗑 Remove 'CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER' key
  📜 Update the beautiful changelog
  🛠 Fix the failing DefaultSettingsProviderTests
  Deal with SPM 🙈
  wip
  wip
Package.resolved Outdated Show resolved Hide resolved
public final class PruneUITestsProjectMapper: ProjectMapping {
public init() {}

public func map(project: Project) throws -> (Project, [SideEffectDescriptor]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should revisit the idea of "pruning". I think long-term, it's better if mappers just do what they are designed for. In this case removing certain targets for the project. This might leave the project in a invalid state, for example schemes with broken references to targets. For that reason I think we should extract from CacheTreeShakingGraphMapper the logic that ensures the integrity of the project. We can place that in a IntegrityGraphMapper. @luispadron do you think "integrity" is the right word for describe what it does?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it makes sense to move the tree-shaking to a mapper that will always be run as the last one to ensure the "integrity". Maybe ValidityChecker as an alternative to Integrity (just throwing ideas out there)?

Copy link
Collaborator Author

@mollyIV mollyIV May 13, 2021

Choose a reason for hiding this comment

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

Hey @pepibumur , @fortmarek 👋

I like the idea, however maybe we can tackle that in the following PR from two reasons:

  • I'd like to keep the size of a pull request small
  • getting rid of puring feels out of scope for this PR

I have already been playing with extracting the integrity part from CacheTreeShakingGraphMapper. I'd like to write down a quick summary to be sure we are on the same page 🙏

  1. SkipUITestsProjectMapper would remove the ui tests targets explicitly instead of marking them as to be pruned.
public final class SkipUITestsProjectMapper: ProjectMapping {
    public func map(project: Project) throws -> (Project, [SideEffectDescriptor]) {
        var project = project
        project.targets = project.targets.filter { $0.product != .uiTests }
        return (project, [])
    }
}
  1. IntegrityGraphMapper implementation would be identical to the current state of CacheTreeShakingGraphMapper, but it would do nothing related to target.prune, meaning this would be removed:

  2. We'd need to add IntegrityGraphMapper as a last mapper to every place where the CacheTreeShakingGraphMapper is added.

  3. CacheGraphMutator sets targets to be pruned - how we would migrate this part? Should the mutator remove the targets directly? Would we need CacheTreeShakingGraphMapper then still? I am a bit confused how those would fit together.

Thanks for the feedback!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hope you do not mind, but I have created a follow-up ticket to tackle pruning refactoring 🙇

@@ -46,6 +46,11 @@ struct TestCommand: ParsableCommand {
)
var configuration: String?

@Flag(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: I'd extend the annotation to be more explicit about the short version of the flag. Since it's UI tests, what about making it -u?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, if at some point we decided to add skip-unit-tests option, wouldn't a -u short version be confusing? 🤔 Maybe -ui?

Copy link
Contributor

@pepicrft pepicrft left a comment

Choose a reason for hiding this comment

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

This is great @mollyIV. From my suggestions the one I'd try to address is removing the "prune" thing and have a mapper that ensures the integrity of the project. This integrity mapper should always be the last one.

@pepicrft
Copy link
Contributor

I forgot to mention that we should update the documentation to document what the new flag is for. Moreover, I'd consider adding an acceptance test that verifies that UI tests are skipped. You can set up the acceptance test to run tuist test and verify from the list of run tests whether the UI ones were skipped.

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.

Looking good! Thanks @mollyIV 👏

CHANGELOG.md Outdated Show resolved Hide resolved
public final class PruneUITestsProjectMapper: ProjectMapping {
public init() {}

public func map(project: Project) throws -> (Project, [SideEffectDescriptor]) {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it makes sense to move the tree-shaking to a mapper that will always be run as the last one to ensure the "integrity". Maybe ValidityChecker as an alternative to Integrity (just throwing ideas out there)?

Sources/TuistKit/Commands/TestCommand.swift Outdated Show resolved Hide resolved
Sources/TuistKit/Commands/TestCommand.swift Outdated Show resolved Hide resolved
mollyIV added 4 commits May 13, 2021 06:21
* main: (118 commits)
  Don't import the config
  Bump @theme-ui/color from 0.3.5 to 0.8.4 in /projects/website (tuist#2908)
  Fix documentation website
  Update docusaurus
  Bump @typescript-eslint/eslint-plugin in /projects/next (tuist#2929)
  Bump gatsby-image from 3.4.0 to 3.5.0 in /projects/next (tuist#2936)
  Bump babel-preset-gatsby from 1.4.0 to 1.5.0 in /projects/next (tuist#2939)
  Bump gatsby-image from 3.4.0 to 3.5.0 in /projects/website (tuist#2951)
  Bump gatsby-plugin-manifest from 3.4.0 to 3.5.0 in /projects/website (tuist#2952)
  Bump gatsby-plugin-mdx from 2.4.0 to 2.5.0 in /projects/next (tuist#2935)
  Bump prettier from 2.2.1 to 2.3.0 in /projects/website (tuist#2942)
  Bump eslint from 7.25.0 to 7.26.0 in /projects/next (tuist#2931)
  Bump @docusaurus/core in /projects/docs (tuist#2924)
  Bump @vitejs/plugin-react-refresh from 1.3.2 to 1.3.3 in /projects/lab (tuist#2923)
  Bump devise from 4.7.3 to 4.8.0 in /projects/lab (tuist#2926)
  Bump puma from 5.2.2 to 5.3.1 in /projects/lab (tuist#2928)
  Bump vite-plugin-full-reload from 0.2.1 to 0.2.2 in /projects/lab (tuist#2932)
  Bump rubocop from 1.13.0 to 1.14.0 in /projects/lab (tuist#2933)
  Bump rubocop-rails_config from 1.4.2 to 1.5.3 in /projects/lab (tuist#2934)
  Bump rails from 6.1.3.1 to 6.1.3.2 in /projects/lab (tuist#2937)
  ...

# Conflicts:
#	CHANGELOG.md
@pepicrft pepicrft added this to the 2.0 milestone May 17, 2021
@github-actions
Copy link
Contributor

This PR has been marked as stale because it's been opened for more than 30 days. If no action is taken, it'll be closed in 5 days.

mollyIV added 2 commits June 17, 2021 14:40
* main: (95 commits)
  fix typo on tuist graph command option --skip-test-targets
  Bump normalize-url from 4.5.0 to 4.5.1 in /projects/docs (tuist#3068)
  [Dependencies.swift] Generate `DependenciesGraph` for `Carthage` dependencies. (tuist#3043)
  Fix manifest loading when using Swift 5.5 (tuist#3062)
  Update project.md (tuist#3063)
  Add release name
  Bundle libProjectAutomation.dylib
  Support for tvOS Top Shelf Extensions (tuist#2793)
  Fix tuist and tuistenv release mismatch
  Version 1.44.0
  Bump version to 1.44.0
  Bump gatsby-plugin-theme-ui from 0.8.4 to 0.9.1 in /projects/website (tuist#3046)
  Bump autoprefixer from 10.2.5 to 10.2.6 in /projects/website
  Bump gatsby-plugin-sharp from 3.5.0 to 3.6.0 in /projects/website
  Bump react-spring from 9.1.2 to 9.2.1 in /projects/website
  Bump gatsby-redirect-from from 0.3.0 to 0.4.1 in /projects/website
  Bump @theme-ui/color from 0.8.4 to 0.9.1 in /projects/website
  Bump tailwindcss from 2.1.2 to 2.1.4 in /projects/website
  Bump ws from 6.2.1 to 6.2.2 in /projects/docs
  Remove stickers and shop link
  ...

# Conflicts:
#	CHANGELOG.md
@mollyIV
Copy link
Collaborator Author

mollyIV commented Jun 17, 2021

I forgot to mention that we should update the documentation to document what the new flag is for.

The documentation has been updated 👌

Moreover, I'd consider adding an acceptance test that verifies that UI tests are skipped. You can set up the acceptance test to run tuist test and verify from the list of run tests whether the UI ones were skipped.

TBH I'd stick to unit tests only as most of the logic is contained.

@mollyIV
Copy link
Collaborator Author

mollyIV commented Jun 17, 2021

Hey @pepibumur , @fortmarek, @luispadron 👋

Thanks a lot for your feedback ❤️ I believe every comment / suggestion has been addressed and the pull request is ready for re-review 👀

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.

Some minor comments, but otherwise good to merge IMHO 👏

@@ -57,3 +57,4 @@ One of the benefits of using Tuist over other automation tools is that developer
| `--device` | `-d` | `Test on a specific device.` | | No |
| `--os` | `-o` | `Test with a specific version of the OS.` | | No |
| `--configuration` | `-C` | `The configuration to be used when building the scheme.` | | No |
| `--skip-ui-tests` | `-C` | `When passed, it skips testing UI Tests targets.` | False | No |
Copy link
Member

Choose a reason for hiding this comment

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

I believe the short flag here is wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed, by not allowing a short. The reason behind it mentioned here.

@@ -265,15 +265,17 @@ private extension TestService {
configuration: String? = nil,
path: AbsolutePath,
deviceName: String? = nil,
osVersion: String? = nil
osVersion: String? = nil,
skipUiTests: Bool = false
Copy link
Member

Choose a reason for hiding this comment

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

Nit: There is inconsistent usage of skipUiTests and skipUITests - can you just do a quick search and replace, so only skipUITests is used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed 💪

@fortmarek fortmarek merged commit 35fa0d1 into tuist:main Jun 19, 2021
@mollyIV mollyIV deleted the add-skip-ui-tests-flag-to-test-command branch June 20, 2021 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --skip-ui-tests parameter to tuist test command to skip UI Tests targets from being executed
4 participants