Skip to content

Commit

Permalink
Feat/prepare first version (#8)
Browse files Browse the repository at this point in the history
* upgraded versions + changed to interpreter

* finished refactoring file structure and improved examples

* improved example package.json

* reverted motoko upgrade

* checking version

* attempting to fix dfx version for CI

* temporary fix of dfx 14

* improed ci with dfx install

* fixing with dfx start

---------

Co-authored-by: Tiago Loureiro <[email protected]>
  • Loading branch information
tiagoicp and Tiago Loureiro authored May 5, 2023
1 parent 0ac4e72 commit e962a9c
Show file tree
Hide file tree
Showing 18 changed files with 1,388 additions and 7,918 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:

# Remember to update me!
env:
vessel_version: "v0.6.4"
moc_version: "0.8.5"
vessel_version: "v0.6.5"
moc_version: "0.8.8"

jobs:
tests:
Expand Down Expand Up @@ -41,5 +41,10 @@ jobs:
wget --output-document /home/runner/bin/vessel https://github.com/kritzcreek/vessel/releases/download/${{ env.vessel_version }}/vessel-linux64
chmod +x /home/runner/bin/vessel
vessel install
- name: "test"
run: npm test
- name: "install dfx"
run: sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
- name: "run tests"
run: |
dfx start --background
npm test
dfx stop
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ In this repo, you will find an example of it's usage on the "example" folder. (W

- Fast and powerful spec loader and runner (credit to mo-test)
- "Describe", "context", "before", "it" syntax, with grouping and sub-grouping
- Capable of running Canister / Actor specs, using the interpreter
-

[Next Features](/ROADMAP.md)
Expand Down
2 changes: 0 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ In this doc you will find a summary of the planned features.

## Current Features WIP

- Test canister code
- Example with both Canister and Module specs
- Improve mo-test error description / match
- Improve separation of code (setup, before and it)
- Add concept of factories
Expand Down
8,794 changes: 1,114 additions & 7,680 deletions example/package-lock.json

Large diffs are not rendered by default.

39 changes: 8 additions & 31 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
{
"name": "motoko_unit_tests_assets",
"name": "mospec_example",
"version": "0.1.0",
"description": "Internet Computer starter application",
"description": "MoSpec Example",
"keywords": [
"Internet Computer",
"Motoko",
"JavaScript",
"Canister"
"Canister",
"Test",
"MoSpec"
],
"scripts": {
"build": "webpack",
"prebuild": "npm run copy:types",
"start": "webpack serve --mode development --env development",
"prestart": "npm run copy:types",
"copy:types": "rsync -avr .dfx/$(echo ${DFX_NETWORK:-'**'})/canisters/** --exclude='assets/' --exclude='idl/' --exclude='*.wasm' --delete src/declarations"
"test": "mo-test --testmode interpreter --verbose"
},
"devDependencies": {
"@dfinity/agent": "0.10.2",
"@dfinity/candid": "0.10.2",
"@dfinity/principal": "0.10.2",
"assert": "2.0.0",
"buffer": "6.0.3",
"copy-webpack-plugin": "^9.0.1",
"events": "3.3.0",
"html-webpack-plugin": "5.5.0",
"process": "0.11.10",
"stream-browserify": "3.0.0",
"terser-webpack-plugin": "5.2.5",
"util": "0.12.4",
"webpack": "5.63.0",
"webpack-cli": "4.9.1",
"webpack-dev-server": "^4.4.0"
},
"browserslist": [
"last 2 chrome version",
"last 2 firefox version",
"last 2 safari version",
"last 2 edge version"
]
"mo-dev": "^0.7.1"
}
}
68 changes: 68 additions & 0 deletions example/src/example/Utils.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import U "Utils";
import Debug "mo:base/Debug";
import MoSpec "../../../src/MoSpec";

let assertTrue = MoSpec.assertTrue;
let describe = MoSpec.describe;
let context = MoSpec.context;
let before = MoSpec.before;
let it = MoSpec.it;
let skip = MoSpec.skip;
let pending = MoSpec.pending;
let run = MoSpec.run;

// setup
var iterator = 0;

let success = run([
describe(
"#sum",
[
before(
do {
iterator += 1;
}
),
context(
"when something happens",
[
it(
"should assess a boolean value",
do {
assertTrue(true);
},
),
it(
"should sum two positive Nats",
do {
assertTrue(U.sum((1, 2)) == 3);
},
),
it(
"should check that doesn't match",
do {
assertTrue(U.sum((1, 2)) != 4);
},
),
it(
"before do should have run 1 times",
do {
assertTrue(iterator == 1);
},
),
skip(
"should skip a test",
do {
// Useful for defining a test that is not yet implemented
true;
},
),
],
),
],
),
]);

if (success == false) {
Debug.trap("Tests failed");
};
2 changes: 1 addition & 1 deletion example/src/example/main.mo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import T "Types";
import U "Utils";

actor {
actor class ExampleCanister() {
public query func greet(args : T.GreetArgs) : async Text {
return U.greet(args);
};
Expand Down
73 changes: 40 additions & 33 deletions example/src/example/main.test.mo
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
import U "Utils";
import Debug "mo:base/Debug";

import Main "main";
import MoSpec "../../../src/MoSpec";
type Group = MoSpec.Group;

let exampleCanister = await Main.ExampleCanister();

let assertTrue = MoSpec.assertTrue;
let describe = MoSpec.describe;
let context = MoSpec.context;
let before = MoSpec.before;
let it = MoSpec.it;
let skip = MoSpec.skip;
let pending = MoSpec.pending;
let run = MoSpec.run;

let success = run([
describe(
"Example Test Suite",
"#greet",
[
describe(
"Subgroup",
[
it(
"should assess a boolean value",
do {
assertTrue(true);
},
),
it(
"should sum two positive Nats",
do {
assertTrue(U.sum((1, 2)) == 3);
},
),
it(
"should fail a check that doesn't match",
do {
assertTrue(U.sum((1, 2)) != 4);
},
),
skip(
"should skip a test",
do {
// Useful for defining a test that is not yet implemented
true;
},
),
],
it(
"should greet me",
do {
let response = await exampleCanister.greet({ name = "Christoph" });
assertTrue(response == "Hello, Christoph!");
},
),
it(
"greet him-whose-name-shall-not-be-spoken",
do {
let response = await exampleCanister.greet({
name = "him whose name shall not be spoken";
});
assertTrue(response != "Voldemort");
},
),
],
),
describe(
"#sum",
[
it(
"should sum two positive Nats",
do {
let response = await exampleCanister.sum((1, 2));
assertTrue(response == 3);
},
),
it(
"should fail a check that doesn't match",
do {
let response = await exampleCanister.sum((1, 2));
assertTrue(response != 4);
},
),
],
),
Expand Down
121 changes: 0 additions & 121 deletions example/webpack.config.js

This file was deleted.

Loading

0 comments on commit e962a9c

Please sign in to comment.