Hi
I’m still working on that part :).
In order to start using this tool you need to add it to package.json which should be in the same directory as your dfx.json file.
So you could start with
npm i lightic
Than you need to choose the js testing framework, it could be: mocha, jest, vitest or any other.
For the mocha, you can check an example here: lightic/test at main · icopen/lightic · GitHub
In order to be able to write test in mocha using typescript, you need to add following packages
npm i @types/mocha @types/node typescript mocha chai ts-node
And create .mochars.json
with content
// This config file contains Mocha's defaults.
// This same configuration could be provided in the `mocha` property of your
// project's `package.json`.
{
"diff": true,
"extension": ["js", "cjs", "mjs", "ts"],
"package": "./package.json",
"reporter": "spec",
"slow": "75",
"timeout": "2000",
"ui": "bdd",
"watch-files": ["lib/**/*.js", "test/**/*.ts"],
"watch-ignore": ["lib/vendor"],
"loader": "ts-node/esm"
}
In order to actually test your canister, you need to add to your test file
import { TestContext } from 'lightic'
const context = new TestContext()
This will create a context to run tests, it is a harness that gives you a possibility to install and run canisters
const canister = await context.deploy('./dfx/local/canisters/example/example.wasm')
const caller = Principal.anonymous()
const actor = Actor.createActor(canister.getIdlBuilder(), {
agent: context.getAgent(caller),
canisterId: canister.get_id()
})
As you can see this works with a wasm
file, so you need to first compile the project using dfx, in the future the test harness will also take care of compilation.
You also need to specify the identity principle (who is calling the canisters) and create an actor.
Then you get an actor, which is the same type as regular dfinity actor.
In order to call canister:
const result = await actor.test_caller()
If you have any questions regarding the usage, I can help