genlayer 0.0.31 → 0.0.32-beta.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,19 +1,26 @@
1
- import {program} from "commander";
2
-
1
+ import {Command} from "commander";
2
+ import {jest} from "@jest/globals";
3
3
  import {initializeGeneralCommands} from "../../src/commands/general";
4
4
  import {getCommand, getCommandOption} from "../utils";
5
5
 
6
6
  jest.mock("inquirer", () => ({
7
- prompt: jest.fn().mockResolvedValue({}),
7
+ prompt: jest.fn(() => {}),
8
8
  }));
9
9
  const action = jest.fn();
10
10
 
11
11
  describe("init command", () => {
12
- initializeGeneralCommands(program);
13
- const initCommand = getCommand("init");
14
- initCommand?.action(action);
12
+ let initCommand: Command;
13
+ let program: Command;
15
14
 
16
15
  beforeEach(() => {
16
+ program = new Command();
17
+ initializeGeneralCommands(program);
18
+
19
+ initCommand = getCommand(program, "init");
20
+ initCommand?.action(async args => {
21
+ action(args);
22
+ });
23
+
17
24
  jest.clearAllMocks();
18
25
  });
19
26
 
@@ -21,21 +28,30 @@ describe("init command", () => {
21
28
  jest.restoreAllMocks();
22
29
  });
23
30
 
24
- test("doesn't have required arguments nor options", () => {
31
+ test("doesn't have required arguments nor options", async () => {
25
32
  expect(() => program.parse(["node", "test", "init"])).not.toThrow();
26
33
  });
27
34
 
28
- test("option -n, --numValidators is accepted", () => {
29
- expect(() => program.parse(["node", "test", "init", "-n", "10"])).not.toThrow();
35
+ test("option --numValidators is accepted", async () => {
30
36
  expect(() => program.parse(["node", "test", "init", "--numValidators", "10"])).not.toThrow();
31
37
  });
32
38
 
33
- test("option -n, --numValidators default value is 5", async () => {
39
+ test("option --numValidators default value is 5", async () => {
34
40
  // Given // When
35
41
  const numValidatorsOption = getCommandOption(initCommand, "--numValidators");
36
42
  expect(numValidatorsOption?.defaultValue).toBe("5");
37
43
  });
38
44
 
45
+ test("option --branch is accepted", async () => {
46
+ expect(() => program.parse(["node", "test", "init", "--branch", "example"])).not.toThrow();
47
+ });
48
+
49
+ test("option --branch default value is main", async () => {
50
+ // Given // When
51
+ const numValidatorsOption = getCommandOption(initCommand, "--branch");
52
+ expect(numValidatorsOption?.defaultValue).toBe("main");
53
+ });
54
+
39
55
  test("random option is not accepted", async () => {
40
56
  initCommand?.exitOverride();
41
57
  expect(() => program.parse(["node", "test", "init", "-random"])).toThrow(
@@ -46,10 +62,11 @@ describe("init command", () => {
46
62
  );
47
63
  });
48
64
 
49
- test("action is called", () => {
65
+ test("action is called", async () => {
50
66
  // Given When
51
67
  program.parse(["node", "test", "init"]);
52
68
  // Then
53
69
  expect(action).toHaveBeenCalledTimes(1);
70
+ expect(action).toHaveBeenCalledWith({numValidators: "5", branch: "main"});
54
71
  });
55
72
  });
package/tests/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {Command, Option, program} from "commander";
1
+ import {Command, Option} from "commander";
2
2
 
3
- export function getCommand(commandName: string): Command {
3
+ export function getCommand(program: Command, commandName: string): Command {
4
4
  const command = program.commands.find(command => command.name() === commandName);
5
5
  if (!command) {
6
6
  throw new Error(`Command ${commandName} not found`);
package/tsconfig.json CHANGED
@@ -11,7 +11,7 @@
11
11
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
12
 
13
13
  /* Language and Environment */
14
- "target": "ES2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
14
+ "target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
17
  // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
@@ -25,9 +25,9 @@
25
25
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
26
 
27
27
  /* Modules */
28
- "module": "commonjs" /* Specify what module code is generated. */,
28
+ "module": "ES2022" /* Specify what module code is generated. */,
29
29
  // "rootDir": /* Specify the root folder within your source files. */,
30
- // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
30
+ "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
31
31
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
32
  "paths": {
33
33
  "@/*": ["./src/*"],
@@ -38,7 +38,11 @@
38
38
  "./tests"
39
39
  ] /* Allow multiple folders to be treated as one when resolving modules. */,
40
40
  // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
41
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
41
+ "types": [
42
+ "jest",
43
+ "node",
44
+ "@types/jest"
45
+ ] /* Specify type package names to be included without being referenced in a source file. */,
42
46
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
43
47
  // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
44
48
  // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */