Skip to content

Commit 4e87275

Browse files
authored
Only spawn a browser when using the feature macro, not normal tests (#795)
* Only spawn a browser when using the `feature` macro, not normal `test`s 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 * Bump upload-artifact version to fix deprecation error * Address PR feedback
1 parent c144c92 commit 4e87275

3 files changed

Lines changed: 27 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
- name: Run Tests
164164
run: mix test || mix test --failed || mix test --failed
165165

166-
- uses: actions/upload-artifact@v2
166+
- uses: actions/upload-artifact@v4
167167
if: always()
168168
with:
169169
name: Selenium Logs
@@ -210,7 +210,7 @@ jobs:
210210
- name: Run Tests
211211
run: mix test || mix test --failed || mix test --failed
212212

213-
- uses: actions/upload-artifact@v2
213+
- uses: actions/upload-artifact@v4
214214
if: always()
215215
with:
216216
name: Selenium Logs
@@ -250,7 +250,7 @@ jobs:
250250
- name: Run Tests
251251
run: mix test || mix test --failed || mix test --failed
252252

253-
- uses: actions/upload-artifact@v2
253+
- uses: actions/upload-artifact@v4
254254
if: always()
255255
with:
256256
name: Selenium Logs

integration_test/cases/feature/use_feature_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ defmodule Wallaby.Integration.Browser.UseFeatureTest do
3434
feature "reads capabilities from session attribute", %{session: %{capabilities: capabilities}} do
3535
assert capabilities.test == @expected_capabilities.test
3636
end
37+
38+
test "does not set up a session for non-feature tests", context do
39+
refute is_map_key(context, :session)
40+
end
3741
end

lib/wallaby/feature.ex

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,26 @@ defmodule Wallaby.Feature do
2323
import Wallaby.Feature
2424

2525
setup context do
26-
metadata = unquote(__MODULE__).Utils.maybe_checkout_repos(context[:async])
27-
28-
start_session_opts =
29-
[metadata: metadata]
30-
|> unquote(__MODULE__).Utils.put_create_session_fn(context[:create_session_fn])
31-
32-
get_in(context, [:registered, :sessions])
33-
|> unquote(__MODULE__).Utils.sessions_iterable()
34-
|> Enum.map(fn
35-
opts when is_list(opts) ->
36-
unquote(__MODULE__).Utils.start_session(opts, start_session_opts)
37-
38-
i when is_number(i) ->
39-
unquote(__MODULE__).Utils.start_session([], start_session_opts)
40-
end)
41-
|> unquote(__MODULE__).Utils.build_setup_return()
26+
if context[:test_type] == :feature do
27+
metadata = unquote(__MODULE__).Utils.maybe_checkout_repos(context[:async])
28+
29+
start_session_opts =
30+
[metadata: metadata]
31+
|> unquote(__MODULE__).Utils.put_create_session_fn(context[:create_session_fn])
32+
33+
get_in(context, [:registered, :sessions])
34+
|> unquote(__MODULE__).Utils.sessions_iterable()
35+
|> Enum.map(fn
36+
opts when is_list(opts) ->
37+
unquote(__MODULE__).Utils.start_session(opts, start_session_opts)
38+
39+
i when is_number(i) ->
40+
unquote(__MODULE__).Utils.start_session([], start_session_opts)
41+
end)
42+
|> unquote(__MODULE__).Utils.build_setup_return()
43+
else
44+
:ok
45+
end
4246
end
4347
end
4448
end

0 commit comments

Comments
 (0)