ic-mops 2.3.2 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,100 @@
1
- import { describe, expect, test } from "@jest/globals";
1
+ import { describe, expect, jest, test } from "@jest/globals";
2
2
  import { execa } from "execa";
3
- import { existsSync } from "node:fs";
3
+ import { existsSync, rmSync } from "node:fs";
4
4
  import path from "path";
5
- import { cliSnapshot } from "./helpers";
5
+ import { cli, cliSnapshot } from "./helpers";
6
6
 
7
7
  const distBin = path.resolve(import.meta.dirname, "../dist/bin/mops.js");
8
8
 
9
+ function cleanFixture(cwd: string, ...extras: string[]) {
10
+ rmSync(path.join(cwd, ".mops"), { recursive: true, force: true });
11
+ for (const p of extras) {
12
+ rmSync(p, { recursive: true, force: true });
13
+ }
14
+ }
15
+
9
16
  describe("build", () => {
17
+ // Several dfx/pocket-ic builds per test; slow CI (e.g. node 20 matrix) can exceed 60s default.
18
+ jest.setTimeout(120_000);
19
+
10
20
  test("ok", async () => {
11
21
  const cwd = path.join(import.meta.dirname, "build/success");
12
- await cliSnapshot(["build", "--verbose"], { cwd }, 0);
13
- await cliSnapshot(["build", "foo"], { cwd }, 0);
14
- await cliSnapshot(["build", "bar"], { cwd }, 0);
15
- await cliSnapshot(["build", "foo", "bar"], { cwd }, 0);
22
+ try {
23
+ await cliSnapshot(["build", "--verbose"], { cwd }, 0);
24
+ await cliSnapshot(["build", "foo"], { cwd }, 0);
25
+ await cliSnapshot(["build", "bar"], { cwd }, 0);
26
+ await cliSnapshot(["build", "foo", "bar"], { cwd }, 0);
27
+ } finally {
28
+ cleanFixture(cwd);
29
+ }
16
30
  });
17
31
 
18
32
  test("error", async () => {
19
33
  const cwd = path.join(import.meta.dirname, "build/error");
20
- await cliSnapshot(["build", "foo", "--verbose"], { cwd }, 0);
21
- expect((await cliSnapshot(["build", "bar"], { cwd }, 1)).stderr).toMatch(
22
- "Candid compatibility check failed for canister bar",
23
- );
24
- expect(
25
- (await cliSnapshot(["build", "foo", "bar"], { cwd }, 1)).stderr,
26
- ).toMatch("Candid compatibility check failed for canister bar");
34
+ try {
35
+ await cliSnapshot(["build", "foo", "--verbose"], { cwd }, 0);
36
+ expect((await cliSnapshot(["build", "bar"], { cwd }, 1)).stderr).toMatch(
37
+ "Candid compatibility check failed for canister bar",
38
+ );
39
+ expect(
40
+ (await cliSnapshot(["build", "foo", "bar"], { cwd }, 1)).stderr,
41
+ ).toMatch("Candid compatibility check failed for canister bar");
42
+ } finally {
43
+ cleanFixture(cwd);
44
+ }
45
+ });
46
+
47
+ // [build].outputDir in mops.toml should control where build output goes
48
+ test("custom output path via config outputDir", async () => {
49
+ const cwd = path.join(import.meta.dirname, "build/custom-output");
50
+ const customOut = path.join(cwd, "custom-out");
51
+ const customWasm = path.join(customOut, "main.wasm");
52
+ const customDid = path.join(customOut, "main.did");
53
+ const defaultDid = path.join(cwd, ".mops/.build/main.did");
54
+
55
+ try {
56
+ const result = await cli(["build"], { cwd });
57
+ expect(result.exitCode).toBe(0);
58
+ expect(existsSync(customWasm)).toBe(true);
59
+ expect(existsSync(customDid)).toBe(true);
60
+ expect(existsSync(defaultDid)).toBe(false);
61
+ } finally {
62
+ cleanFixture(cwd, customOut);
63
+ }
64
+ });
65
+
66
+ // Regression: --output CLI option was silently ignored due to
67
+ // Commander storing it as options.output while build() read options.outputDir
68
+ test("--output CLI option", async () => {
69
+ const cwd = path.join(import.meta.dirname, "build/success");
70
+ const outputDir = path.join(cwd, "cli-output-test");
71
+
72
+ try {
73
+ const result = await cli(["build", "foo", "--output", outputDir], {
74
+ cwd,
75
+ });
76
+ expect(result.exitCode).toBe(0);
77
+ expect(existsSync(path.join(outputDir, "foo.wasm"))).toBe(true);
78
+ expect(existsSync(path.join(outputDir, "foo.did"))).toBe(true);
79
+ } finally {
80
+ cleanFixture(cwd, outputDir);
81
+ }
82
+ });
83
+
84
+ test("warns when args contain managed flags", async () => {
85
+ const cwd = path.join(import.meta.dirname, "build/success");
86
+ const artifact = path.join(cwd, "x");
87
+ const artifactDid = path.join(cwd, "x.did");
88
+
89
+ try {
90
+ await cliSnapshot(
91
+ ["build", "foo", "--", "-o", "x", "-c", "--idl"],
92
+ { cwd },
93
+ 1,
94
+ );
95
+ } finally {
96
+ cleanFixture(cwd, artifact, artifactDid);
97
+ }
27
98
  });
28
99
 
29
100
  // Regression: bin/mops.js must route through environments/nodejs/cli.js
@@ -35,14 +106,18 @@ describe("build", () => {
35
106
  "wasm bindings initialized via dist entry point",
36
107
  async () => {
37
108
  const cwd = path.join(import.meta.dirname, "build/success");
38
- const result = await execa("node", [distBin, "build", "foo"], {
39
- cwd,
40
- stdio: "pipe",
41
- reject: false,
42
- });
109
+ try {
110
+ const result = await execa("node", [distBin, "build", "foo"], {
111
+ cwd,
112
+ stdio: "pipe",
113
+ reject: false,
114
+ });
43
115
 
44
- expect(result.stderr).not.toContain("Wasm bindings have not been set");
45
- expect(result.exitCode).toBe(0);
116
+ expect(result.stderr).not.toContain("Wasm bindings have not been set");
117
+ expect(result.exitCode).toBe(0);
118
+ } finally {
119
+ cleanFixture(cwd);
120
+ }
46
121
  },
47
122
  );
48
123
  });
@@ -0,0 +1,3 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+ pocket-ic = "12.0.0"
@@ -0,0 +1,3 @@
1
+ persistent actor {
2
+ public func runTests() : async () {};
3
+ };
@@ -0,0 +1,19 @@
1
+ import { describe, test, expect } from "@jest/globals";
2
+ import path from "path";
3
+ import { cli } from "./helpers";
4
+
5
+ describe("pocket-ic", () => {
6
+ test("runs tests with pocket-ic 12.0.0", async () => {
7
+ const cwd = path.join(import.meta.dirname, "pocket-ic");
8
+ const result = await cli(
9
+ ["test", "--reporter", "verbose", "--replica", "pocket-ic"],
10
+ { cwd },
11
+ );
12
+
13
+ expect(result.stderr).not.toContain("is not supported");
14
+ expect(result.stderr).not.toContain(
15
+ "only supports pocket-ic 9.x.x and 4.0.0",
16
+ );
17
+ expect(result.exitCode).toBe(0);
18
+ });
19
+ });