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

Only spawn a browser when using the feature macro, not normal tests #795

Merged

Conversation

s3cur3
Copy link
Contributor

@s3cur3 s3cur3 commented Dec 29, 2024

This fixes an unintended behavior where having use Wallaby.Feature at the top of your module would cause a browser to be spawned for every test in the module, not just feature tests. The result is that if you had a large test module, most of which used the normal test macro and one of which used the feature macro, every test would take a minimum of a third of a second or more.

I also took the liberty to check and see in the setup block if we already had a :session, and if so, avoid spawning a second. I don't think anyone was relying on the behavior where a second browser was being spawned if you had use Wallaby.Feature at both the top of the module and a describe block.

Resolves #794

This fixes an unintended behavior where having `use Wallaby.Feature` at the top of your module would cause a browser to be spawned for every test in the module, not just `feature` tests. The result is that if you had a large test module, most of which used the normal `test` macro and one of which used the `feature` macro, every test would take a minimum of a third of a second or more.

I also took the liberty to check and see in the `setup` block if we already had a `:session`, and if so, avoid spawning a second. I don't *think* anyone was relying on the behavior where a second browser was being spawned if you had `use Wallaby.Feature` at both the top of the module and a `describe` block.

Resolves elixir-wallaby#794

# If you have `use Wallaby.Feature` at the top of your test module,
# then also within a `describe` block, we only want to set up one session.
already_has_session? = is_map_key(context, :session)
Copy link
Member

Choose a reason for hiding this comment

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

Let's not deal with this in this pull request and do a second one.

This might be better to emit a warning rather than be silent.

end)
|> unquote(__MODULE__).Utils.build_setup_return()
# Only set up a session if this is a feature test (using the `feature` macro).
feature_test? = context[:feature] == true
Copy link
Member

Choose a reason for hiding this comment

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

I think here you want to check context[:test_type] == :feature

Copy link
Member

Choose a reason for hiding this comment

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

Also I would just inline this. It's self explanatory.

@mhanberg
Copy link
Member

The tests might fail a bunch but you don't have to worry about it.

@s3cur3 s3cur3 requested a review from mhanberg December 30, 2024 14:03
@s3cur3
Copy link
Contributor Author

s3cur3 commented Dec 31, 2024

Changes made! ☺️

@mhanberg mhanberg merged commit 4e87275 into elixir-wallaby:main Jan 3, 2025
7 of 14 checks passed
@s3cur3 s3cur3 deleted the only-spawn-browser-for-feature-macro branch January 6, 2025 12:42
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.

use Wallaby.Feature spawns an instance of Chromedriver for every test in the module, not just features
2 participants