elm unit test runner
The installation guide assumes that you already have the following installed:
It is recommended to install lobo locally for your application and lobo-cli globally:
npm install lobo --save
npm install -g lobo-cli
Once they are installed you can run lobo via the following command:
lobo --help
Once lobo has been run once you should find the "lobo.json" file and the ".lobo" directory in the root of your project.
The lobo.json file is similar to the elm.json file with the additional dependencies and source directories required to run lobo. This file is created and managed automatically by lobo. In general you should not edit this file by hand. It is recommended that you check this file into your source control.
The .lobo directory only contains temp files for the running of lobo. You should configure your source control to ignore this directory and its contents.
After updating lobo, you may find that elm does not properly find the lobo elm code. To fix this delete lobo.json, .lobo and elm-stuff.
Prior to 0.5 lobo did not generate the test suite and required you to construct the test suites, which were typically linked together at a central Tests.elm file. This is no longer required - you should be able to remove most if not all of the describe tests in your project and change each test module to expose everything.
The recommended approach to writing tests is to expose all of the tests automatically in the module through the use of "exposing (..)"
Lobo supports the following test frameworks:
If you are using the elm-test framework your elm tests should be similar to this:
module Tests exposing (..)
import Expect
import Test exposing (Test, test)
testExpectTrue : Test
testExpectTrue =
test "Expect.true test" <|
\() ->
True
|> Expect.true "Expected true"
testExpectNotEqual : Test
testExpectNotEqual =
test "Expect Not Equal" <|
\() ->
Expect.notEqual "foo" "foobar"
...
If you are using the elm-test-extra framework your elm tests should be similar to this:
module Tests exposing (..)
import ElmTest.Extra exposing (Test, test)
import Expect
testExpectTrue : Test
testExpectTrue =
test "Expect.true test" <|
\() ->
True
|> Expect.true "Expected true"
testExpectNotEqual : Test
testExpectNotEqual =
test "Expect Not Equal" <|
\() ->
Expect.notEqual "foo" "foobar"
...
The following elm-test functions are not available in elm-test-extra:
describe
Note: the use of skip in lobo requires a reason to be specified
Lobo considers any function that it finds in the test directory that has no arguments and returns a Test to be a test that should be part of the test suite. Using this definition lobo checks for the following issues:
These are tests that exist within the test files, but have not been exposed by their module. The easiest way to avoid this issue is to simply expose all of the types in the module by "exposing (..)".
These are tests that are exposed directly or indirectly by more than one test suite. This commonly occurs when using a describe block that either is in a module that exposes all tests or including a test that belongs to another module.
Assuming your application follows the recommended directory structure for an elm application:
.lobo --> lobo temp directory - should be ignored by source control
elm.json --> definition of the elm required packages
lobo.json --> lobo configuration file
elm-stuff/ --> elm installed packages
node_modules/ --> npm installed modules
package.json --> definition of the npm required packages
src/ --> source code directory
tests/ --> test code directory
Locally running the following command will start lobo in watch mode:
lobo --watch
Lobo will then check that the elm.json and lobo.json files are in-sync. If they are out of sync it will ask you if the tests lobo.json can be updated.
Lobo will then attempt to generate the test suite and build the tests, if this fails the errors from elm make will be displayed
Once the build succeeds lobo will analyze the test suite for issues, if this fails the issues will be displayed.
After the analysis is completed without any issues lobo will run the test suite and report the result to the console.
Once a build/run loop has completed if lobo is running in watch mode (recommended) it will wait for changes in the source code and automatically repeat the build/run loop.
The list of options available can be obtained by running:
lobo --help
For example lobo can be run with elm-test by running:
lobo --framework=elm-test
The path to elm executable
Disables auto-cleanup of temporary files. This can be useful when debugging issues when combined with the verbose option
Exit with non zero exit code when there are any only tests
Exit with non zero exit code when there are any skip tests
Exit with non zero exit code when there are any todo tests
Specifies the test framework to use. The default is elm-test-extra. To use elm-test use the following:
lobo --framework=elm-test
Prevents lobo from running the test suite analysis. This can be useful when the analysis is reporting false positives that cause the tests not to run.
Prevents lobo from trying to run elm install when running the tests. This can be useful when using lobo without an internet connection.
Prevents lobo from trying to update the lobo.json file when running the tests.
Attempts to build with the elm optimize flag. However, setting this flag will be ignored if lobo finds usages of the Debug module in the elm.json source directories.
Note: The optimizations performed by elm will prevent useful test failure messages from being displayed.
Prevents lobo and elm tools asking your permission, and always answers "yes"
Minimise the output to build and test summary information and errors
The name of the reporter to use. Currently there is only one default-reporter
Specify the path to the tests directory. The default is "tests". This is useful if you have a non standard directory setup and can be used as follows:
lobo --testDirectory="test/unit"
Increases the verbosity of lobo logging messages. Please use this when reporting an issue with lobo to get details about what lobo was trying and failed todo.
Increases the verbosity of lobo logging to be very detailed.
Put lobo in a infinite loop that watches for changes and automatically reruns the build and tests when the source code has changed.
Note: Currently watch mode does not deal with changes to the elm.json source directories. If you change these you will need to exit watch mode and restart it.
The following test frameworks are supported:
elm-test-extra is the default framework, it is similar to elm-test with additions for running test.
The following options are supported elm-test-extra:
To use elm-test lobo will need to be run with the framework option "elm-test" - see the options section for more information.
The following options are supported elm-test-extra:
The following reporters are supported:
The default reporter displays a summary of the test run followed by details of any failures. When the failure is from an Expect.equal assertion it adds a visual hint for the source of the difference:
The following options are supported by the default reporter:
The JSON reporter outputs the progress and run details as JSON. This reporter is generally only useful when integrating lobo with other tools.
The following options are supported by the JSON reporter:
The JUnit reporter outputs progress and summary to the console and details of the test run to the specified report file. This reporter is mainly useful when integrating lobo with other build tools.
The following options are supported by the JUnit reporter:
In general if lobo quits abnormally try deleting lobo.json, .lobo and elm-stuff.
findTests
is causing a mismatchIf you are seeing an error similar to the following:
The argument to function `findTests` is causing a mismatch.
15| ElmTestExtra.findTests Tests.all
^^^^^^^^^
Function `findTests` is expecting the argument to be:
ElmTest.Runner.Test
But it is:
Test.Internal.Test
Detected errors in 1 module.
Check that you have replaced all instances of import Test
with
import ElmTest.Extra
If you are seeing an error similar to the following:
ReferenceError: _user$.....Plugin$findTests is not defined
Try deleting the test elm-stuff directory and re-running lobo
Contributions and suggestions welcome! In the first instance please raise an issue to against this project before starting work on a pull request.