Skip to main content

Motoko dev server

Overview

Motoko dev server, or mo-dev for short, is a command line tool that features a development server with live reloading for Motoko.

Installation

Prerequisites

You can install mo-dev with npm:

npm i -g mo-dev

Standalone mo-dev binaries are also available as GitHub releases.

Usage

Specify the working directory of your Motoko project, which must contain a dfx.json file:

mo-dev --cwd path/to/dfx_project

Then, run the dev server for a specific canister:

mo-dev --canister foo --deploy

You can deploy all canisters within a dfx.json file with --deploy flag. Canisters will be deployed when a Motoko file is changed:

mo-dev --deploy

You can also pass an installation argument to dfx deploy:

mo-dev --deploy --argument '()'

View the full usage of mo-dev.

Testing

mo-dev supports running unit tests (*.test.mo). Tests will be run when a Motoko file is changed:

mo-dev --test

mo-dev also includes a mo-test command, which can be used to run unit tests within CI workflows.

To run all Motoko unit tests (*.test.mo), use the command:

mo-test

You can also run all Motoko unit tests using a WASI runtime by default. This has a higher performance, requires installing Wasmtime on your system:

mo-test --testmode wasi

To configure the runtime of an individual unit test, include the following comment within your test file (*.test.mo):

// @testmode wasi

View the full usage of mo-test.

Examples

The Vite + React + Motoko project showcases how to integrate mo-dev into a full-stack dapp.

Open in Gitpod

Important notes

mo-dev is early in development. Please feel free to report a bug, ask a question, or request a feature on the project's GitHub issues page.