Skip to content

Commit 3f13d26

Browse files
authored
Set up CLI snapshot testing (#343)
* Set up CLI snapshot testing * Update Candid tests * Revert changes to 'cli/bin/mops.js' * Update snapshots * Increase test timeout * Update tests * Remove commented code
1 parent f6e03bf commit 3f13d26

23 files changed

Lines changed: 8643 additions & 3665 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ jobs:
7777

7878
- name: Build CLI releases
7979
run: npm run build-cli-releases
80+
81+
- name: Run CLI tests
82+
run: cd cli && npm test

cli/bin/mops.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
import "../cli.js";
3+
import "../cli.js";

cli/commands/build.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ export async function build(
5959
if (!(await exists(outputDir))) {
6060
await mkdir(outputDir, { recursive: true });
6161
}
62-
for (let [canisterName, canister] of Object.entries(canisters)) {
62+
63+
const filteredCanisters = canisterNames
64+
? Object.fromEntries(
65+
Object.entries(canisters).filter(([name]) =>
66+
canisterNames.includes(name),
67+
),
68+
)
69+
: canisters;
70+
71+
for (let [canisterName, canister] of Object.entries(filteredCanisters)) {
6372
options.verbose && console.time(`build canister ${canisterName}`);
6473
console.log(chalk.blue("build canister"), chalk.bold(canisterName));
6574
let motokoPath = canister.main;
@@ -161,6 +170,8 @@ export async function build(
161170
}
162171

163172
console.log(
164-
chalk.green(`\n✓ Built ${Object.keys(canisters).length} canisters`),
173+
chalk.green(
174+
`\n✓ Built ${Object.keys(filteredCanisters).length} canister${Object.keys(filteredCanisters).length == 1 ? "" : "s"} successfully`,
175+
),
165176
);
166177
}

cli/jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @type {import("jest").Config} **/
2+
export default {
3+
preset: "ts-jest/presets/default-esm",
4+
testPathIgnorePatterns: [
5+
"<rootDir>/node_modules/",
6+
"<rootDir>/dist/",
7+
"<rootDir>/bundle/",
8+
"<rootDir>/commands/"
9+
],
10+
transform: {
11+
"^.+\\.tsx?$": ["ts-jest", { useESM: true }],
12+
},
13+
testTimeout: 60000,
14+
};

0 commit comments

Comments
 (0)