This document explains how to develop Ory Kratos, run tests, and work with the tooling around it.
Check releases tab for updates and changelogs when using the open source license.
To see available commands and flags, run:
kratos -h
# or
kratos helpWe encourage all contributions. Before opening a pull request, read the contribution guidelines.
You need Go 1.16+ and, for the test suites:
- Docker and Docker Compose
make- Node.js and npm
You can develop Ory Kratos on Windows, but most guides assume a Unix shell such as bash or zsh.
To install Kratos from source:
make installFormat all code using:
make formatThe continuous integration pipeline checks code formatting.
There are three types of tests:
- Short tests that do not require a SQL database
- Regular tests that require PostgreSQL, MySQL, and CockroachDB
- End to end tests that use real databases and a test browser
Short tests run quickly and use SQLite.
Run all short tests:
go test -short ./...Run short tests in a specific module:
cd client
go test -short .Regular tests require a database setup.
The test suite can start databases using ory/dockertest. In practice, it is usually easier and faster to use the Makefile targets.
Run the full test suite:
make testNote:
make testrecreates the databases every time. This can be slow if you are iterating frequently on a specific test.
If you want to reuse databases across test runs, initialize them once:
make test-resetdb
export TEST_DATABASE_MYSQL='mysql://root:secret@(127.0.0.1:3444)/mysql?parseTime=true'
export TEST_DATABASE_POSTGRESQL='postgres://postgres:[email protected]:3445/kratos?sslmode=disable'
export TEST_DATABASE_COCKROACHDB='cockroach://[email protected]:3446/defaultdb?sslmode=disable'Then you can run Go tests directly as often as needed:
go test ./...
# or in a module:
cd client
go test .Some tests use snapshot fixtures.
Update snapshots for short tests:
make test-update-snapshotsUpdate all snapshots:
UPDATE_SNAPSHOTS=true go test -p 4 ./...You can run this from the repository root or from subdirectories.
End to end tests are implemented with Cypress.
On ARM based Macs you may need to install Rosetta 2 to run Cypress. See the Cypress documentation: https://www.cypress.io/blog/2021/01/20/running-cypress-on-the-apple-m1-silicon-arm-architecture-using-rosetta-2/
To install Rosetta 2:
softwareupdate --install-rosetta --agree-to-licenseRun e2e tests in development mode:
./test/e2e/run.sh --dev sqliteRun all e2e tests with databases:
make test-e2eFor more options:
./test/e2e/run.shAdd .only to the test you want to run, for example:
it.only('invalid remote recovery email template', () => {
// ...
})To run a subset of e2e tests:
-
Edit
cypress.jsonintest/e2e/. -
Add the
testFilesoption and point it to the specs you want, for example:"testFiles": ["profiles/network/*"]
-
Start the tests again using the run script or Makefile.
To build a development Docker image:
make dockerTo work on and preview the generated API documentation:
-
Update the SDK including the OpenAPI specification:
make sdk
-
Run the preview server for API documentation:
make docs/api
-
Run the preview server for Swagger documentation:
make docs/swagger