@forgehive/forge-cli 0.2.5 → 0.2.6
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.
- package/dist/test/tasks/create.test.js +17 -18
- package/dist/test/tasks/init.test.js +21 -23
- package/dist/test/testUtils.d.ts +8 -0
- package/dist/test/testUtils.js +25 -0
- package/package.json +5 -5
- package/src/test/tasks/create.test.ts +18 -19
- package/src/test/tasks/init.test.ts +24 -26
- package/src/test/testUtils.ts +28 -0
- package/src/test/utils.ts +0 -17
|
@@ -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
|
|
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
|
|
64
|
-
const
|
|
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
|
-
//
|
|
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
|
-
//
|
|
82
|
-
getCwdFn.mockResolvedValue(rootDir);
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
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
|
|
26
|
-
const
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
init_1.init.
|
|
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.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "TypeScript CLI application",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@forgehive/record-tape": "^0.0.1",
|
|
14
14
|
"@forgehive/runner": "^0.1.4",
|
|
15
15
|
"@forgehive/schema": "^0.1.4",
|
|
16
|
-
"@forgehive/task": "^0.1.
|
|
16
|
+
"@forgehive/task": "^0.1.6",
|
|
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/
|
|
28
|
+
"@forgehive/record-tape": "0.0.3",
|
|
29
|
+
"@forgehive/runner": "0.1.6",
|
|
29
30
|
"@forgehive/schema": "0.1.4",
|
|
30
|
-
"@forgehive/
|
|
31
|
-
"@forgehive/runner": "0.1.5"
|
|
31
|
+
"@forgehive/task": "0.1.6"
|
|
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 {
|
|
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
|
|
66
|
-
const
|
|
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
|
-
//
|
|
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
|
-
//
|
|
87
|
-
getCwdFn.mockResolvedValue(rootDir)
|
|
80
|
+
// Mock getCwd to return our root directory
|
|
81
|
+
const getCwdFn = jest.fn().mockResolvedValue(rootDir)
|
|
88
82
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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 {
|
|
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
|
|
25
|
-
const
|
|
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
|
-
|
|
37
|
-
getCwdFn.mockResolvedValue(rootDir)
|
|
32
|
+
const getCwdFn = jest.fn().mockResolvedValue(rootDir)
|
|
38
33
|
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
init.
|
|
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
|
-
}
|