You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(mix test) add test_load_filters and test_warn_filters
When using the default project configuration, mix test would only warn
about files ending in `_test.ex`. The only mistake this warns about is
forgetting the `s` of `.exs`. In a work project we noticed (after more
than a year) that we had multiple test files that did not match the test
pattern, preventing them from running in mix test locally and CI.
Because we have many other tests, nobody noticed this. If CI passes, all
is good, right?
Because there is no easy way to evaluate glob patterns in Elixir without
touching the filesystem, I decided to deprecate the old `warn_test_pattern`
configuration and instead add two new configurations:
`test_load_filters` and `test_warn_filters`
Now, by changing the default of `test_pattern` to `*.{ex,exs}`, we can
load all potential test files once and then match their paths to the
patterns.
The `test_load_filters` is used to filter the files that are loaded by
mix test. This defaults to the regex equivalent of "*_test.exs". The
`test_warn_filters` is used to filter the files that we warn about if
they are not loaded. By default, we ignore any file ending in `_helper.exs`,
which will prevent the default test_helper.exs from generating a warning
and also provides a simple way to name other files that might be required
explicitly in tests. We also default to ignore any files that start with
a configured elixirc_path, which are compiled often test support files.
For projects with an existing `warn_test_pattern` configuration,
a deprecation warning is logged. The warnings can be disabled by setting
`test_warn_filters` to a falsy value.
Projects with an existing custom `test_pattern` should check if their
pattern conflicts with the new `test_load_filters` and adjust their
configuration accordingly. It is also possible to keep the old `test_pattern`
and configure the `test_load_filters` to accept any file, for example by
configuring it to `[fn _ -> true end]`. In that case, the `test_warn_filters`
don't have an effect, as any potential test file is also loaded.
0 commit comments