Skip to content

Commit

Permalink
[docs] Improve mops test documentation with replica and verbose options
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenVoich committed Feb 13, 2025
1 parent 03aecad commit fd0dc95
Showing 1 changed file with 45 additions and 18 deletions.
63 changes: 45 additions & 18 deletions docs/docs/cli/4-dev/01-mops-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,27 @@ You can also specify `wasi` mode for a specific test file by adding the line bel
// @testmode wasi
```

**Replica tests**
### `--replica`

Which replica to use to run actor tests.

Default `pocket-ic` if `pocket-ic` is specified in `mops.toml` in `[toolchain]` section, otherwise `dfx`.

Possible values:
- `dfx` - use `dfx` local replica
- `pocket-ic` - use [PocketIC](https://pypi.org/project/pocket-ic/) light replica via [pic.js](https://www.npmjs.com/package/@hadronous/pic) wrapper

:::info
If you run `mops test --replica pocket-ic` AND `pocket-ic` is not specified in `mops.toml` in `[toolchain]` section, Mops will use pocket-ic replica that comes with dfx (`dfx start --pocketic`).
:::

### `--verbose`

Show replica logs



## Replica tests

Replica tests are useful if you need to test actor code which relies on the IC API(cycles, timers, canister upgrades, etc.).

Expand All @@ -82,27 +102,34 @@ actor {
};
```

See example [here](https://github.com/ZenVoich/mops/blob/main/test/storage-actor.test.mo).

Under the hood, Mops will:
- Start a local replica on port `4945`
- Compile test files and deploy them
- Call `runTests` method of the deployed canister
Example:
```motoko
import {test} "mo:test/async";
import MyCanister "../my-canister";
### `--replica`
actor {
// add cycles to deploy your canister
ExperimentalCycles.add<system>(1_000_000_000_000);
Which replica to use to run actor tests.
// deploy your canister
let myCanister = await MyCanister.MyCanister();
Default `pocket-ic` if `pocket-ic` is specified in `mops.toml` in `[toolchain]` section, otherwise `dfx`.
public func runTests() : async () {
await test("test name", func() : async () {
let res = await myCanister.myFunc();
assert res == 123;
});
};
};
```

Possible values:
- `dfx` - use `dfx` local replica
- `pocket-ic` - use [PocketIC](https://pypi.org/project/pocket-ic/) light replica via [pic.js](https://www.npmjs.com/package/@hadronous/pic) wrapper
Make sure your actor doesn't have a name `actor {`.

:::info
If you run `mops test --replica pocket-ic` AND `pocket-ic` is not specified in `mops.toml` in `[toolchain]` section, Mops will use pocket-ic replica that comes with dfx (`dfx start --pocketic`).
:::
Make sure your actor has `runTests` method.

### `--verbose`
See example [here](https://github.com/ZenVoich/mops/blob/main/test/storage-actor.test.mo).

Show replica logs
Under the hood, Mops will:
- Start a local replica on port `4945`
- Compile test files and deploy them
- Call `runTests` method of the deployed canister

0 comments on commit fd0dc95

Please sign in to comment.