Glacier brings incremental interactive unit testing to Gleam. It is meant as a drop-in replacement for Gleeunit and depends on a fork of it.
Glacier: «A persistent body of dense ice that is constantly moving under its own weight.»-
Open
gleam.toml
and removegleeunit
from the dependencies. -
Run
gleam add glacier --dev
. -
Open
gleam.toml
and remove:[dev-dependencies] gleeunit = ...
-
Run
gleam clean
. -
Open
./test/YOUR_PROJECT.gleam
and replaceimport gleeunit
withimport glacier
andgleeunit.main()
withglacier.main()
. -
If you want to run on Deno 1.30+ open
gleam.toml
and add:[javascript.deno] allow_read = ["./"] allow_net = ["deno.land"] allow_run = ["gleam"]
-
Run
gleam test --target erlang -- --glacier
orgleam test --target javascript --runtime deno -- --glacier
orgleam test --target javascript --runtime node -- --glacier
. -
Save a
src
ortest
module and watch associated tests to re-run.
Notice: On Linux inotify must be installed.
Make sure to run gleam clean
after upgrading Glacier as a dependency.
Glacier differs from Gleeunit insofar, that it let's you:
- Pass in the
glacier
flag like so:gleam test -- --glacier
, save a module and only related tests will rerun. - Or Pass in a specific unit test modules to rerun
gleam test -- test/my_module_test.gleam
. - If
gleam test
is passed without any--
-arguments it behaves the same as Gleeunit. - You can still pass in
--target erlang
or--target javascript
like sogleam test --target erlang -- --glacier
, or likegleam test --target javascript -- test/my_module_test.gleam
.
To enable this behavior, all you have to do is add Glacier as a dev dependency, aka gleam add glacier --dev
, open ./test/YOUR_PROJECT.gleam
and replace gleeunit.main()
with glacier.main()
.
Note: gleam test
must only be executed from the base project directory!
Run these in 3 terminals side by side:
gleam test --target erlang -- --glacier
gleam test --target javascript -- --glacier
gleam test --target javascript --runtime deno -- --glacier
./src
and./test
source files with white spaces will not pass detection.- Behavior towards
./src
and./test
source files with non-alphanumeric characters is not tested, and generally unsupported.
Requires Gleam 0.26 or later.
- Erlang/OTP 25 (lower may or may not run)
- NodeJS 18 LTS+ (lower may or may not run)
- Deno v1.30.0+ (lower does not run)
Development and testing only happens on very recent stable Erlang/OTP versions, and thus may or may not run on previous versions.
Depends on fs:
Development and testing only happens on very recent NodeJS LTS versions, and thus may or may not run on previous versions.
Depends on NodeJS:fsPromises.watch
or Deno.watchFs
:
This package is available on hex.pm can be added to your Gleam project:
- Open
.gleam.toml
and remove thegleeunit
dependency becauseGlacier
will fetch its own gleeunit fork. - Run
gleam add glacier --dev
.
If you are using Deno you will need to add this to your projects's gleam.toml
file:
[javascript.deno]
allow_read = ["./"]
allow_net = ["deno.land"]
allow_run = ["gleam"]
- Open
./test/YOUR_PROJECT.gleam
and replaceimport gleeunit
withimport glacier
andgleeunit.main()
withglacier.main()
. - Run
gleam test -- --glacier
, then:- Save any test module (within
./test
) file to re-run that single test - Save any src module (within
./src
) to run all associated tests. Associated tests are test modules where the module is imported or where any of the module's imports and their import's imports (import chain) are imported into.
- Save any test module (within
- Optional: You may find and replace all
import gleeunit/should
withimport glacier/should
and removegleeunit
from your dependencies ingleam.toml
.
Documentation can be found at https://hexdocs.pm/glacier.
gleam test
passes throughglacier.main()
and simply executesgleeunit.main()
as if Gleeunit was used directly.gleam test -- test_module_a test_module_b
passes throughglacier.main()
and executesgleeunit.test_modules(modules_list)
wheremodules_list
is["foo", "bar"]
. The given modules are checked if they exist as either.gleam
or.erl
test module files and then Gleeunit runs these test modules.gleam test -- --glacier
entersglacier.main()
and starts a file watcher: Upon changes in module files in./test
it just passes those through asgleam test -- changed_test_module
(so re-saving test files executes the single test), and if a module file in./src
got changed it parses that changed module file for any imported modules and puts the module and all chained imported modules in a distinct list of modules that should be tested. Then all test module files are read and imports of those are gathered one by one and cross matched against that list. The result is a list of test modules that need to be run, which then gets done by executing a shell call similar togleam test -- detected_test_module_a detected_test_module_b detected_test_module_c etc
, aka jump to step2
.
git clone https://github.com/inoas/glacier.git
cd glacier
See all open issues on GitHub if you want to help out.
# Traditional test runs
gleam test --target erlang
gleam test --target erlang -- test/glacier_demo/glacier_demo_module_a_test.gleam
# Incremental interactive test
gleam test --target erlang -- --glacier
# Re-save ./src/glacier_demo/glacier_demo_module_a.gleam
# Traditional test runs
gleam test --target javascript --runtime node
gleam test --target javascript --runtime node -- test/glacier_demo/glacier_demo_module_a_test.gleam
# Incremental interactive test
gleam test --target javascript --runtime node -- --glacier
# Re-save ./src/glacier_demo/glacier_demo_module_a.gleam
Notice: You may omit --runtime node
as it is currently set as the default runtime for target javascript
.
# Traditional test runs
gleam test --target javascript --runtime deno
gleam test --target javascript --runtime deno -- test/glacier_demo/glacier_demo_module_a_test.gleam
# Incremental interactive test
gleam test --target javascript --runtime deno -- --glacier
# Re-save ./src/glacier_demo/glacier_demo_module_a.gleam
Do not forget to edit gleam.toml
to add deno privileges:
[javascript.deno]
allow_read = ["./"]
allow_net = ["deno.land"]
allow_run = ["gleam"]