Skip to content

Commit

Permalink
Fix mo-test for projects without default.packtool.sources in `dfx…
Browse files Browse the repository at this point in the history
….json` file (#52)

* Update project unit tests

* Fix 'mo-test' for projects without 'default.packtool.sources' in dfx.json

* 0.11.2
  • Loading branch information
rvanasa authored Jul 29, 2023
1 parent 556c63a commit d88d715
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mo-dev",
"version": "0.11.1",
"version": "0.11.2",
"description": "A live reload development server for Motoko smart contracts.",
"author": "DFINITY Foundation (https://dfinity.org)",
"license": "Apache-2.0",
Expand Down
17 changes: 12 additions & 5 deletions src/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function runTests(
const dfxSources = await loadDfxSources(directory);

if (settings.verbosity >= 1) {
console.log(pc.magenta(dfxSources));
console.log(pc.magenta(dfxSources ?? '(no package sources)'));
}

if (settings.verbosity >= 0) {
Expand Down Expand Up @@ -151,10 +151,15 @@ export async function runTests(
return runs;
}

interface SharedTestInfo {
mocPath: string;
dfxSources: string | undefined;
}

async function runTestFile(
test: Test,
settings: TestSettings,
shared: { mocPath: string; dfxSources: string },
shared: SharedTestInfo,
): Promise<TestRun[]> {
const source = await readFile(test.path, 'utf8');
const modes: TestMode[] = [];
Expand All @@ -178,7 +183,7 @@ async function runTest(
test: Test,
mode: TestMode,
settings: TestSettings,
{ mocPath, dfxSources }: { mocPath: string; dfxSources: string },
{ mocPath, dfxSources }: SharedTestInfo,
): Promise<TestRun> {
const { path } = test;

Expand All @@ -196,7 +201,9 @@ async function runTest(
try {
if (mode === 'interpreter') {
const interpretResult = await execa(
`${shellEscape([mocPath, '-r', path])} ${dfxSources}`,
`${shellEscape([mocPath, '-r', path])}${
dfxSources ? ` ${dfxSources}` : ''
}`,
{ shell: true, cwd: settings.directory, reject: false },
);
return {
Expand All @@ -222,7 +229,7 @@ async function runTest(
'-o',
wasmPath,
path,
])} ${dfxSources}`,
])}${dfxSources ? ` ${dfxSources}` : ''}`,
{ shell: true, cwd: settings.directory },
);
const wasmtimeResult = await execa(
Expand Down
1 change: 1 addition & 0 deletions tests/mo-dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('mo-dev', () => {
'motoko_canister/test/WasiError.test.mo',
'motoko_canister/test/WasiFail.test.mo',
'motoko_canister/test/WasiPass.test.mo',
'vm/tests/Main.test.mo',
'vm/vm_canister/Main.mo',
]);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion tests/mo-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('mo-test', () => {
testRuns.push(result);
},
);
expect(testRuns.length).toEqual(6);
expect(testRuns.length).toEqual(7);
}, 20000);

test('--testmode, wasi', async () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/project/vm/tests/Main.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Main } "../vm_canister/Main";

let canister = await Main();

assert (await canister.main()) == 123;
2 changes: 1 addition & 1 deletion tests/project/vm/vm_canister/Main.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
actor {
actor class Main() {
public func main() : async Nat {
123;
};
Expand Down

0 comments on commit d88d715

Please sign in to comment.