@forgehive/forge-cli 0.2.5 → 0.2.7

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.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const createTask_1 = require("../../tasks/task/createTask");
7
7
  const memfs_1 = require("memfs");
8
8
  const path_1 = __importDefault(require("path"));
9
- const utils_1 = require("../utils");
9
+ const testUtils_1 = require("../testUtils");
10
10
  // Verify the task file content
11
11
  const expectedContent = `// TASK: newTask
12
12
  // Run this task with:
@@ -58,32 +58,31 @@ describe('Create task', () => {
58
58
  });
59
59
  afterEach(() => {
60
60
  jest.clearAllMocks();
61
+ // Reset any boundary mocks
62
+ createTask_1.createTaskCommand.resetMocks();
61
63
  });
62
64
  it('should create a new task file with correct content and update forge.json', async () => {
63
- // Create properly typed mocks for the boundaries
64
- const persistTaskMock = (0, utils_1.createBoundaryMock)();
65
- const persistConfMock = (0, utils_1.createBoundaryMock)();
66
- const getCwdMock = (0, utils_1.createBoundaryMock)();
67
- const persistTaskFn = persistTaskMock;
68
- const persistConfFn = persistConfMock;
69
- const getCwdFn = getCwdMock;
70
- // Override the persistTask implementation to use our in-memory fs
71
- persistTaskFn.mockImplementation(async (dir, fileName, content, cwd) => {
65
+ // Create mock functions with Jest
66
+ const persistTaskFn = jest.fn().mockImplementation(async (dir, fileName, content, cwd) => {
72
67
  const fullPath = path_1.default.join(cwd, dir, fileName);
73
68
  await fs.promises.writeFile(fullPath, content);
74
69
  return { path: fullPath };
75
70
  });
76
- // Override the persistConf implementation to use our in-memory fs
77
- persistConfFn.mockImplementation(async (conf, cwd) => {
71
+ // Mock persistConf to use our in-memory fs
72
+ const persistConfFn = jest.fn().mockImplementation(async (conf, cwd) => {
78
73
  const forgePath = path_1.default.join(cwd, 'forge.json');
79
74
  await fs.promises.writeFile(forgePath, JSON.stringify(conf, null, 2));
80
75
  });
81
- // Override the getCwd implementation to return our root directory
82
- getCwdFn.mockResolvedValue(rootDir);
83
- // Override the boundaries
84
- createTask_1.createTaskCommand.getBoundaries().persistTask = persistTaskMock;
85
- createTask_1.createTaskCommand.getBoundaries().persistConf = persistConfMock;
86
- createTask_1.createTaskCommand.getBoundaries().getCwd = getCwdMock;
76
+ // Mock getCwd to return our root directory
77
+ const getCwdFn = jest.fn().mockResolvedValue(rootDir);
78
+ // Create boundary mocks with proper type casting
79
+ const persistTaskMock = (0, testUtils_1.createMockBoundary)(persistTaskFn);
80
+ const persistConfMock = (0, testUtils_1.createMockBoundary)(persistConfFn);
81
+ const getCwdMock = (0, testUtils_1.createMockBoundary)(getCwdFn);
82
+ // Use the mockBoundary method to mock the boundaries
83
+ createTask_1.createTaskCommand.mockBoundary('persistTask', persistTaskMock);
84
+ createTask_1.createTaskCommand.mockBoundary('persistConf', persistConfMock);
85
+ createTask_1.createTaskCommand.mockBoundary('getCwd', getCwdMock);
87
86
  // Run the task
88
87
  const taskName = 'sample:new-task';
89
88
  await createTask_1.createTaskCommand.run({ descriptorName: taskName });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const init_1 = require("../../tasks/init");
7
7
  const memfs_1 = require("memfs");
8
8
  const path_1 = __importDefault(require("path"));
9
- const utils_1 = require("../utils");
9
+ const testUtils_1 = require("../testUtils");
10
10
  describe('Init task', () => {
11
11
  let volume;
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -20,23 +20,22 @@ describe('Init task', () => {
20
20
  });
21
21
  afterEach(() => {
22
22
  jest.clearAllMocks();
23
+ // Reset any boundary mocks after each test
24
+ init_1.init.resetMocks();
23
25
  });
24
26
  it('should create forge.json with correct content in the filesystem', async () => {
25
- // Create properly typed mocks for the boundaries
26
- const saveFileMock = (0, utils_1.createBoundaryMock)();
27
- const getCwdMock = (0, utils_1.createBoundaryMock)();
28
- const saveFileFn = saveFileMock;
29
- const getCwdFn = getCwdMock;
30
- // Override the saveFile implementation to use our in-memory fs
31
- saveFileFn.mockImplementation(async (filePath, content) => {
27
+ // Create mocks directly using Jest
28
+ const saveFileFn = jest.fn().mockImplementation(async (filePath, content) => {
32
29
  const fullPath = path_1.default.join(rootDir, filePath);
33
30
  await fs.promises.writeFile(fullPath, content);
34
31
  });
35
- // Override the getCwd implementation to return our root directory
36
- getCwdFn.mockResolvedValue(rootDir);
37
- // Override the boundaries
38
- init_1.init.getBoundaries().saveFile = saveFileMock;
39
- init_1.init.getBoundaries().getCwd = getCwdMock;
32
+ const getCwdFn = jest.fn().mockResolvedValue(rootDir);
33
+ // Create wrapped boundary mocks
34
+ const saveFileMock = (0, testUtils_1.createMockBoundary)(saveFileFn);
35
+ const getCwdMock = (0, testUtils_1.createMockBoundary)(getCwdFn);
36
+ // Mock the boundaries
37
+ init_1.init.mockBoundary('saveFile', saveFileMock);
38
+ init_1.init.mockBoundary('getCwd', getCwdMock);
40
39
  // Run the task
41
40
  await init_1.init.run({});
42
41
  // Read the created file
@@ -51,16 +50,15 @@ describe('Init task', () => {
51
50
  expect(config).toHaveProperty('runners');
52
51
  });
53
52
  it('should not create forge.json when dryRun is true', async () => {
54
- // Create properly typed mocks for the boundaries
55
- const saveFileMock = (0, utils_1.createBoundaryMock)();
56
- const getCwdMock = (0, utils_1.createBoundaryMock)();
57
- const saveFileFn = saveFileMock;
58
- const getCwdFn = getCwdMock;
59
- // Override the getCwd implementation to return our root directory
60
- getCwdFn.mockResolvedValue(rootDir);
61
- // Override the boundaries
62
- init_1.init.getBoundaries().saveFile = saveFileMock;
63
- init_1.init.getBoundaries().getCwd = getCwdMock;
53
+ // Create mocks directly using Jest
54
+ const saveFileFn = jest.fn();
55
+ const getCwdFn = jest.fn().mockResolvedValue(rootDir);
56
+ // Create wrapped boundary mocks
57
+ const saveFileMock = (0, testUtils_1.createMockBoundary)(saveFileFn);
58
+ const getCwdMock = (0, testUtils_1.createMockBoundary)(getCwdFn);
59
+ // Mock the boundaries
60
+ init_1.init.mockBoundary('saveFile', saveFileMock);
61
+ init_1.init.mockBoundary('getCwd', getCwdMock);
64
62
  // Run the task with dryRun flag
65
63
  const result = await init_1.init.run({ dryRun: true });
66
64
  // Verify saveFile was not called
@@ -0,0 +1,8 @@
1
+ import { type WrappedBoundaryFunction } from '@forgehive/task';
2
+ /**
3
+ * Creates a mock boundary function that implements the WrappedBoundaryFunction interface
4
+ *
5
+ * @param mockFn Optional Jest mock function to use as the base function
6
+ * @returns A wrapped boundary function compatible with task.mockBoundary()
7
+ */
8
+ export declare const createMockBoundary: (mockFn?: jest.Mock) => WrappedBoundaryFunction;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMockBoundary = void 0;
4
+ /**
5
+ * Creates a mock boundary function that implements the WrappedBoundaryFunction interface
6
+ *
7
+ * @param mockFn Optional Jest mock function to use as the base function
8
+ * @returns A wrapped boundary function compatible with task.mockBoundary()
9
+ */
10
+ const createMockBoundary = (mockFn) => {
11
+ // Use provided mock or create a new one
12
+ const baseMockFn = mockFn || jest.fn().mockResolvedValue(undefined);
13
+ // Create a proper boundary function object that extends the mock function
14
+ const boundaryMock = Object.assign(baseMockFn, {
15
+ getTape: jest.fn().mockReturnValue([]),
16
+ setTape: jest.fn(),
17
+ getMode: jest.fn().mockReturnValue('proxy'),
18
+ setMode: jest.fn(),
19
+ startRun: jest.fn(),
20
+ stopRun: jest.fn(),
21
+ getRunData: jest.fn().mockReturnValue([])
22
+ });
23
+ return boundaryMock;
24
+ };
25
+ exports.createMockBoundary = createMockBoundary;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgehive/forge-cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "TypeScript CLI application",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -10,10 +10,10 @@
10
10
  "publishConfig": {
11
11
  "access": "public",
12
12
  "dependencies": {
13
- "@forgehive/record-tape": "^0.0.1",
14
- "@forgehive/runner": "^0.1.4",
13
+ "@forgehive/record-tape": "^0.1.0",
14
+ "@forgehive/runner": "^0.1.7",
15
15
  "@forgehive/schema": "^0.1.4",
16
- "@forgehive/task": "^0.1.5",
16
+ "@forgehive/task": "^0.1.7",
17
17
  "esbuild": "^0.25.0",
18
18
  "handlebars": "^4.7.8",
19
19
  "minimist": "^1.2.8"
@@ -25,10 +25,10 @@
25
25
  "esbuild": "^0.25.0",
26
26
  "handlebars": "^4.7.8",
27
27
  "minimist": "^1.2.8",
28
- "@forgehive/task": "0.1.5",
29
28
  "@forgehive/schema": "0.1.4",
30
- "@forgehive/record-tape": "0.0.2",
31
- "@forgehive/runner": "0.1.5"
29
+ "@forgehive/record-tape": "0.1.0",
30
+ "@forgehive/runner": "0.1.7",
31
+ "@forgehive/task": "0.1.7"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/jest": "^29.5.3",
@@ -1,7 +1,7 @@
1
1
  import { createTaskCommand } from '../../tasks/task/createTask'
2
2
  import { createFsFromVolume, Volume } from 'memfs'
3
3
  import path from 'path'
4
- import { createBoundaryMock } from '../utils'
4
+ import { createMockBoundary } from '../testUtils'
5
5
  import { ForgeConf } from '../../tasks/types'
6
6
 
7
7
  // Verify the task file content
@@ -59,37 +59,36 @@ describe('Create task', () => {
59
59
 
60
60
  afterEach(() => {
61
61
  jest.clearAllMocks()
62
+ // Reset any boundary mocks
63
+ createTaskCommand.resetMocks()
62
64
  })
63
65
 
64
66
  it('should create a new task file with correct content and update forge.json', async () => {
65
- // Create properly typed mocks for the boundaries
66
- const persistTaskMock = createBoundaryMock()
67
- const persistConfMock = createBoundaryMock()
68
- const getCwdMock = createBoundaryMock()
69
- const persistTaskFn = persistTaskMock as unknown as jest.Mock
70
- const persistConfFn = persistConfMock as unknown as jest.Mock
71
- const getCwdFn = getCwdMock as unknown as jest.Mock
72
-
73
- // Override the persistTask implementation to use our in-memory fs
74
- persistTaskFn.mockImplementation(async (dir: string, fileName: string, content: string, cwd: string) => {
67
+ // Create mock functions with Jest
68
+ const persistTaskFn = jest.fn().mockImplementation(async (dir: string, fileName: string, content: string, cwd: string) => {
75
69
  const fullPath = path.join(cwd, dir, fileName)
76
70
  await (fs as { promises: { writeFile: (path: string, content: string) => Promise<void> } }).promises.writeFile(fullPath, content)
77
71
  return { path: fullPath }
78
72
  })
79
73
 
80
- // Override the persistConf implementation to use our in-memory fs
81
- persistConfFn.mockImplementation(async (conf: ForgeConf, cwd: string) => {
74
+ // Mock persistConf to use our in-memory fs
75
+ const persistConfFn = jest.fn().mockImplementation(async (conf: ForgeConf, cwd: string) => {
82
76
  const forgePath = path.join(cwd, 'forge.json')
83
77
  await (fs as { promises: { writeFile: (path: string, content: string) => Promise<void> } }).promises.writeFile(forgePath, JSON.stringify(conf, null, 2))
84
78
  })
85
79
 
86
- // Override the getCwd implementation to return our root directory
87
- getCwdFn.mockResolvedValue(rootDir)
80
+ // Mock getCwd to return our root directory
81
+ const getCwdFn = jest.fn().mockResolvedValue(rootDir)
88
82
 
89
- // Override the boundaries
90
- createTaskCommand.getBoundaries().persistTask = persistTaskMock
91
- createTaskCommand.getBoundaries().persistConf = persistConfMock
92
- createTaskCommand.getBoundaries().getCwd = getCwdMock
83
+ // Create boundary mocks with proper type casting
84
+ const persistTaskMock = createMockBoundary(persistTaskFn)
85
+ const persistConfMock = createMockBoundary(persistConfFn)
86
+ const getCwdMock = createMockBoundary(getCwdFn)
87
+
88
+ // Use the mockBoundary method to mock the boundaries
89
+ createTaskCommand.mockBoundary('persistTask', persistTaskMock)
90
+ createTaskCommand.mockBoundary('persistConf', persistConfMock)
91
+ createTaskCommand.mockBoundary('getCwd', getCwdMock)
93
92
 
94
93
  // Run the task
95
94
  const taskName = 'sample:new-task'
@@ -1,7 +1,7 @@
1
1
  import { init } from '../../tasks/init'
2
2
  import { createFsFromVolume, Volume } from 'memfs'
3
3
  import path from 'path'
4
- import { createBoundaryMock } from '../utils'
4
+ import { createMockBoundary } from '../testUtils'
5
5
 
6
6
  describe('Init task', () => {
7
7
  let volume: InstanceType<typeof Volume>
@@ -18,27 +18,26 @@ describe('Init task', () => {
18
18
 
19
19
  afterEach(() => {
20
20
  jest.clearAllMocks()
21
+ // Reset any boundary mocks after each test
22
+ init.resetMocks()
21
23
  })
22
24
 
23
25
  it('should create forge.json with correct content in the filesystem', async () => {
24
- // Create properly typed mocks for the boundaries
25
- const saveFileMock = createBoundaryMock()
26
- const getCwdMock = createBoundaryMock()
27
- const saveFileFn = saveFileMock as unknown as jest.Mock
28
- const getCwdFn = getCwdMock as unknown as jest.Mock
29
-
30
- // Override the saveFile implementation to use our in-memory fs
31
- saveFileFn.mockImplementation(async (filePath: string, content: string) => {
26
+ // Create mocks directly using Jest
27
+ const saveFileFn = jest.fn().mockImplementation(async (filePath: string, content: string) => {
32
28
  const fullPath = path.join(rootDir, filePath)
33
29
  await (fs as { promises: { writeFile: (path: string, content: string) => Promise<void> } }).promises.writeFile(fullPath, content)
34
30
  })
35
31
 
36
- // Override the getCwd implementation to return our root directory
37
- getCwdFn.mockResolvedValue(rootDir)
32
+ const getCwdFn = jest.fn().mockResolvedValue(rootDir)
38
33
 
39
- // Override the boundaries
40
- init.getBoundaries().saveFile = saveFileMock
41
- init.getBoundaries().getCwd = getCwdMock
34
+ // Create wrapped boundary mocks
35
+ const saveFileMock = createMockBoundary(saveFileFn)
36
+ const getCwdMock = createMockBoundary(getCwdFn)
37
+
38
+ // Mock the boundaries
39
+ init.mockBoundary('saveFile', saveFileMock)
40
+ init.mockBoundary('getCwd', getCwdMock)
42
41
 
43
42
  // Run the task
44
43
  await init.run({})
@@ -57,18 +56,17 @@ describe('Init task', () => {
57
56
  })
58
57
 
59
58
  it('should not create forge.json when dryRun is true', async () => {
60
- // Create properly typed mocks for the boundaries
61
- const saveFileMock = createBoundaryMock()
62
- const getCwdMock = createBoundaryMock()
63
- const saveFileFn = saveFileMock as unknown as jest.Mock
64
- const getCwdFn = getCwdMock as unknown as jest.Mock
65
-
66
- // Override the getCwd implementation to return our root directory
67
- getCwdFn.mockResolvedValue(rootDir)
68
-
69
- // Override the boundaries
70
- init.getBoundaries().saveFile = saveFileMock
71
- init.getBoundaries().getCwd = getCwdMock
59
+ // Create mocks directly using Jest
60
+ const saveFileFn = jest.fn()
61
+ const getCwdFn = jest.fn().mockResolvedValue(rootDir)
62
+
63
+ // Create wrapped boundary mocks
64
+ const saveFileMock = createMockBoundary(saveFileFn)
65
+ const getCwdMock = createMockBoundary(getCwdFn)
66
+
67
+ // Mock the boundaries
68
+ init.mockBoundary('saveFile', saveFileMock)
69
+ init.mockBoundary('getCwd', getCwdMock)
72
70
 
73
71
  // Run the task with dryRun flag
74
72
  const result = await init.run({ dryRun: true })
@@ -0,0 +1,28 @@
1
+ import { type WrappedBoundaryFunction } from '@forgehive/task'
2
+
3
+ /**
4
+ * Creates a mock boundary function that implements the WrappedBoundaryFunction interface
5
+ *
6
+ * @param mockFn Optional Jest mock function to use as the base function
7
+ * @returns A wrapped boundary function compatible with task.mockBoundary()
8
+ */
9
+ export const createMockBoundary = (mockFn?: jest.Mock): WrappedBoundaryFunction => {
10
+ // Use provided mock or create a new one
11
+ const baseMockFn = mockFn || jest.fn().mockResolvedValue(undefined)
12
+
13
+ // Create a proper boundary function object that extends the mock function
14
+ const boundaryMock = Object.assign(
15
+ baseMockFn,
16
+ {
17
+ getTape: jest.fn().mockReturnValue([]),
18
+ setTape: jest.fn(),
19
+ getMode: jest.fn().mockReturnValue('proxy'),
20
+ setMode: jest.fn(),
21
+ startRun: jest.fn(),
22
+ stopRun: jest.fn(),
23
+ getRunData: jest.fn().mockReturnValue([])
24
+ }
25
+ ) as WrappedBoundaryFunction
26
+
27
+ return boundaryMock
28
+ }
package/src/test/utils.ts DELETED
@@ -1,17 +0,0 @@
1
- import { type WrappedBoundaryFunction } from '@forgehive/task'
2
-
3
- export const createBoundaryMock = (): WrappedBoundaryFunction => {
4
- const mockFn = jest.fn().mockResolvedValue(undefined)
5
- const boundaryMock = mockFn as unknown as WrappedBoundaryFunction
6
-
7
- // Add required methods to satisfy the interface
8
- boundaryMock.getTape = jest.fn().mockReturnValue([])
9
- boundaryMock.setTape = jest.fn()
10
- boundaryMock.getMode = jest.fn().mockReturnValue('proxy')
11
- boundaryMock.setMode = jest.fn()
12
- boundaryMock.startRun = jest.fn()
13
- boundaryMock.stopRun = jest.fn()
14
- boundaryMock.getRunData = jest.fn().mockReturnValue([])
15
-
16
- return boundaryMock
17
- }