Skip to content

fix: Encapsulate Wcmd within a private wrapper#275

Open
surajk-m wants to merge 5 commits intojonhoo:mainfrom
surajk-m:fix/wcmd-wrapper
Open

fix: Encapsulate Wcmd within a private wrapper#275
surajk-m wants to merge 5 commits intojonhoo:mainfrom
surajk-m:fix/wcmd-wrapper

Conversation

@surajk-m
Copy link
Copy Markdown
Contributor

Closes #225

The change encapsulates Wcmd within a private wrapper.

@codecov
Copy link
Copy Markdown

codecov bot commented Sep 21, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.33%. Comparing base (29bbfa7) to head (0dd402d).
⚠️ Report is 61 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
src/session.rs 73.53% <100.00%> (-0.05%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on!

Comment thread src/session.rs Outdated
Comment thread Cargo.toml Outdated
Comment thread src/session.rs Outdated
Comment thread tests/local.rs
- Remove `test_wrap_command` and `test_helpers` feature
- Refactor `issue_cmd` to accept impl `Into<Box<dyn WebDriverCompatibleCommand + Send + static>>`
- Introduce a `GetTitle` struct that implements `WebDriverCompatibleCommand`
Comment thread tests/local.rs Outdated
}

// Implement `Into<Box<dyn WebDriverCompatibleCommand + Send>>` for `GetTitle`
impl Into<Box<dyn WebDriverCompatibleCommand + Send>> for GetTitle {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think if you use exactly the version of issur_cmd I proposed, this impl becomes unnecessary

Copy link
Copy Markdown
Contributor Author

@surajk-m surajk-m Oct 28, 2024

Choose a reason for hiding this comment

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

I was trying to use cmd: impl Into<Box<impl WebDriverCompatibleCommand + Send + 'static>> as the parameter type, but I'm getting error[E0666]

error[E0666]: nested `impl Trait` is not allowed
   --> src/session.rs:341:28
    |
341 |         cmd: impl Into<Box<impl WebDriverCompatibleCommand + Send + 'static>>,
    |              --------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^--
    |              |             |
    |              |             nested `impl Trait` here
    |              outer `impl Trait`

To avoid using nested impl Trait, we should flatten the types.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ah, that just means you'll need to use "proper" generics instead:

<C, CC> where C: Into<Box<CC>>, CC: WebDriverCompatibleCommand + Send + 'static

Copy link
Copy Markdown
Contributor Author

@surajk-m surajk-m Oct 29, 2024

Choose a reason for hiding this comment

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

Using generics <C, CC> with C: Into<Box<CC>> and CC: WebDriverCompatibleCommand + Send + 'static works better. The only overhead is the conversion via .into(), which is a bit more than a direct Box::new call if the type isn’t already boxed. If we only prefer non-boxed type as input, should we manually box cmd with Box::new(cmd) as Box<_> as you suggested?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think Box::from is meaningfully more overhead than Box::new in this context, so let's keep it as is 👍

Could you please double-check that it's still possible pass a Box to issue_cmd though, just as a sanity check? Should just be a matter of checking that the test still compiles when you pass Box::new(GetTitle).

Comment thread tests/local.rs Outdated
@jonhoo
Copy link
Copy Markdown
Owner

jonhoo commented Oct 28, 2024

Just a heads up that I'll be on holiday for the next three weeks, so won't have a chance to land this until I get back :)

@surajk-m
Copy link
Copy Markdown
Contributor Author

No worries! Wishing you a great holiday. We’ll pick this up when you're back. 😊 Safe travels!

Copy link
Copy Markdown
Owner

@jonhoo jonhoo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay here! I think this is now nearly ready, just two things I'd like you to test. One is the Box::new(GetTitle) from the open thread, and the other is to re-run the tool from #225 and check that webdriver indeed no longer appears in the public API. Once those checks are both good, and the conflicts resolved, then we can merge and release 🎉

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

Successfully merging this pull request may close these issues.

webdriver might be part of public API

2 participants