Testing

You should be able to use this guide to...

Check code linting and style

Run and write unit tests

Run and write functional tests

Learn how to write tests

Code linting and standards

Lando implements some basic linting and a slightly less annoying version of the googlees6 code standards to make sure things remain consistent between developers and to prevent syntax errors. You can easily check whether your code matches these standards using grunt.

yarn lint

Unit tests

In order to familiarize yourself with where tests should live for both core and plugins please consult the structure guide. Lando's core libraries currently have decent coverage so you can scope them out for help writing tests.

To run the unit test suite, execute:

yarn test:unit

Functional tests

Lando uses it's own functional testing framework called leia. Leia helps us ensure that Lando is the real hero we all know him to be.

Leia combines mocha as the test runner, chai for assertions and command-line-test to make the process of executing commands simpler. Tests are written as specially structured README.md files that live in the examples folder and contain code blocks. When the suite runs these are scanned, parsed and outputted as mocha tests.

Pretty sure these will not run on Windows yet

SORRY WINDOZE USERS!

To generate tests from the examples repo and then run the functional test suite, execute:

yarn generate-tests && yarn test:functional

NOTE: This may take awhile to complete locally and could destroy any apps you may already have running. It's best to use it in a continuos integration environment.

To better understand how these markdown files need to be parsed check out the Leia docs. Lando will specifically look for headers that start with the following to determine which kinds of tests your code block is for:

Type

Headers

Start

Starting

Test

Testing

Cleanup

Cleaning

Here are some caveats and general guidelines about when and how to write functional tests.

So what's the catch?

The suite will run against the lando it finds in your PATH so you need to make sure that lando is running from source

For test commands to pass they must return a 0 status code eg not have any errors

Additional quotes inside of a lando ssh -c "STUFF" are not handled very well right now

So when does your code need to include functional tests?

When you are fixing a bug, you should first write a test to confirm the bug exists repeatably, then you can fix the bug, and the test should pass. Because this framework is essentially just running a bunch of Lando and/or Docker commands it should be pretty easy to write out steps to replicate using the framework.

When shouldn't you bother with a new functional test?

Your code alters Lando in a way that doesn't alter the 'contract' with the user. Internal refactoring should add or alter appropriate unit tests, but if the net affect is not visible to an end user, it doesn't need a functional test.

References

In addition to the tips above, looking at existing tests will give you a good idea of how to write your own, but if you're looking for more tips, we recommend: