@friggframework/devtools 2.0.0--canary.710.9045bbc.0 → 2.0.0--canary.711.f8b6445.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.
- package/frigg-cli/__tests__/unit/commands/deploy.test.js +24 -30
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +6 -10
- package/frigg-cli/__tests__/unit/commands/install.test.js +0 -7
- package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/index.test.js +158 -0
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +8 -12
- package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +7 -19
- package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +8 -12
- package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +18 -17
- package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +2 -12
- package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +1 -8
- package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +2 -4
- package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +0 -10
- package/infrastructure/domains/networking/vpc-builder.js +8 -18
- package/infrastructure/domains/networking/vpc-builder.test.js +13 -32
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
- package/infrastructure/infrastructure-composer.test.js +794 -268
- package/infrastructure/integration.test.js +381 -0
- package/infrastructure/scripts/build-prisma-layer.test.js +7 -28
- package/infrastructure/scripts/build-time-discovery.test.js +3 -18
- package/package.json +7 -7
|
@@ -14,18 +14,10 @@ jest.mock('child_process', () => ({
|
|
|
14
14
|
spawn: jest.fn()
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
-
// Partial mock: only existsSync is stubbed, the rest of fs stays real (a
|
|
18
|
-
// bare { existsSync } mock breaks any dependency that reads fs.constants).
|
|
19
17
|
jest.mock('fs', () => ({
|
|
20
|
-
...jest.requireActual('fs'),
|
|
21
18
|
existsSync: jest.fn()
|
|
22
19
|
}));
|
|
23
20
|
|
|
24
|
-
// The post-deployment health check calls the doctor command (real AWS).
|
|
25
|
-
jest.mock('../../../doctor-command', () => ({
|
|
26
|
-
doctorCommand: jest.fn().mockResolvedValue(undefined)
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
21
|
// Require after mocks
|
|
30
22
|
const { spawn } = require('child_process');
|
|
31
23
|
const fs = require('fs');
|
|
@@ -36,8 +28,6 @@ describe('CLI Command: deploy', () => {
|
|
|
36
28
|
let consoleWarnSpy;
|
|
37
29
|
let consoleErrorSpy;
|
|
38
30
|
let mockChildProcess;
|
|
39
|
-
let childOutcome;
|
|
40
|
-
let exitSpy;
|
|
41
31
|
|
|
42
32
|
beforeEach(() => {
|
|
43
33
|
jest.clearAllMocks();
|
|
@@ -47,18 +37,10 @@ describe('CLI Command: deploy', () => {
|
|
|
47
37
|
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
48
38
|
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
49
39
|
|
|
50
|
-
// Mock child process
|
|
51
|
-
// emits `childOutcome` (default: a clean exit) once its handler is wired.
|
|
52
|
-
childOutcome = { event: 'close', value: 0 };
|
|
40
|
+
// Mock child process
|
|
53
41
|
mockChildProcess = {
|
|
54
|
-
on: jest.fn(
|
|
55
|
-
if (event === childOutcome.event) {
|
|
56
|
-
setImmediate(() => handler(childOutcome.value));
|
|
57
|
-
}
|
|
58
|
-
return mockChildProcess;
|
|
59
|
-
})
|
|
42
|
+
on: jest.fn()
|
|
60
43
|
};
|
|
61
|
-
exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
|
|
62
44
|
|
|
63
45
|
// Mock successful spawn by default
|
|
64
46
|
spawn.mockReturnValue(mockChildProcess);
|
|
@@ -71,7 +53,6 @@ describe('CLI Command: deploy', () => {
|
|
|
71
53
|
consoleLogSpy.mockRestore();
|
|
72
54
|
consoleWarnSpy.mockRestore();
|
|
73
55
|
consoleErrorSpy.mockRestore();
|
|
74
|
-
exitSpy.mockRestore();
|
|
75
56
|
});
|
|
76
57
|
|
|
77
58
|
describe('Success Cases', () => {
|
|
@@ -297,30 +278,43 @@ describe('CLI Command: deploy', () => {
|
|
|
297
278
|
});
|
|
298
279
|
|
|
299
280
|
describe('Error Handling', () => {
|
|
300
|
-
it('should log
|
|
301
|
-
|
|
281
|
+
it('should log error when spawn fails', async () => {
|
|
282
|
+
const testError = new Error('Spawn failed');
|
|
283
|
+
|
|
284
|
+
await deployCommand({ stage: 'dev' });
|
|
302
285
|
|
|
303
|
-
|
|
286
|
+
// Simulate error event
|
|
287
|
+
const errorHandler = mockChildProcess.on.mock.calls.find(
|
|
288
|
+
call => call[0] === 'error'
|
|
289
|
+
)[1];
|
|
290
|
+
errorHandler(testError);
|
|
304
291
|
|
|
305
292
|
expect(consoleErrorSpy).toHaveBeenCalledWith('Error executing command: Spawn failed');
|
|
306
293
|
});
|
|
307
294
|
|
|
308
|
-
it('should log
|
|
309
|
-
childOutcome = { event: 'close', value: 1 };
|
|
310
|
-
|
|
295
|
+
it('should log when child process exits with non-zero code', async () => {
|
|
311
296
|
await deployCommand({ stage: 'dev' });
|
|
312
297
|
|
|
298
|
+
// Simulate close event with error code
|
|
299
|
+
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
300
|
+
call => call[0] === 'close'
|
|
301
|
+
)[1];
|
|
302
|
+
closeHandler(1);
|
|
303
|
+
|
|
313
304
|
expect(consoleLogSpy).toHaveBeenCalledWith('Child process exited with code 1');
|
|
314
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
315
305
|
});
|
|
316
306
|
|
|
317
307
|
it('should NOT log when child process exits with zero code', async () => {
|
|
318
308
|
await deployCommand({ stage: 'dev' });
|
|
319
309
|
|
|
310
|
+
// Simulate close event with success code
|
|
311
|
+
const closeHandler = mockChildProcess.on.mock.calls.find(
|
|
312
|
+
call => call[0] === 'close'
|
|
313
|
+
)[1];
|
|
314
|
+
closeHandler(0);
|
|
315
|
+
|
|
320
316
|
// Should not log exit message for success
|
|
321
317
|
expect(consoleLogSpy).not.toHaveBeenCalledWith('Child process exited with code 0');
|
|
322
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
323
|
-
expect(consoleLogSpy).toHaveBeenCalledWith('\n✓ Deployment completed successfully!');
|
|
324
318
|
});
|
|
325
319
|
});
|
|
326
320
|
});
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
* Tests stack listing, selection, and health check orchestration
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
// with the binding babel-plugin-jest-hoist (Jest 30) injects into the module.
|
|
8
|
-
const { describe, test, expect, beforeEach } = require('@jest/globals');
|
|
6
|
+
const { describe, test, expect, jest, beforeEach } = require('@jest/globals');
|
|
9
7
|
|
|
10
8
|
describe('Doctor Command - Stack Listing and Selection', () => {
|
|
11
9
|
let mockCloudFormationClient;
|
|
@@ -140,27 +138,25 @@ describe('Doctor Command - Stack Listing and Selection', () => {
|
|
|
140
138
|
{
|
|
141
139
|
name: 'production-stack',
|
|
142
140
|
status: 'UPDATE_COMPLETE',
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
createdTime: new Date(2024, 0, 15),
|
|
146
|
-
updatedTime: new Date(2024, 9, 20),
|
|
141
|
+
createdTime: new Date('2024-01-15'),
|
|
142
|
+
updatedTime: new Date('2024-10-20'),
|
|
147
143
|
},
|
|
148
144
|
{
|
|
149
145
|
name: 'dev-stack',
|
|
150
146
|
status: 'CREATE_COMPLETE',
|
|
151
|
-
createdTime: new Date(2024
|
|
147
|
+
createdTime: new Date('2024-10-01'),
|
|
152
148
|
updatedTime: null,
|
|
153
149
|
},
|
|
154
150
|
];
|
|
155
151
|
|
|
156
152
|
const expectedChoices = [
|
|
157
153
|
{
|
|
158
|
-
name:
|
|
154
|
+
name: '✓ production-stack (UPDATE_COMPLETE) - Updated: 10/20/2024',
|
|
159
155
|
value: 'production-stack',
|
|
160
156
|
description: 'Status: UPDATE_COMPLETE',
|
|
161
157
|
},
|
|
162
158
|
{
|
|
163
|
-
name:
|
|
159
|
+
name: '✓ dev-stack (CREATE_COMPLETE) - Created: 10/1/2024',
|
|
164
160
|
value: 'dev-stack',
|
|
165
161
|
description: 'Status: CREATE_COMPLETE',
|
|
166
162
|
},
|
|
@@ -621,13 +621,6 @@ describe('commitChanges', () => {
|
|
|
621
621
|
it('commits only the given files and leaves other staged changes alone', () => {
|
|
622
622
|
const dir = makeTmpDir();
|
|
623
623
|
git(['init', '-q'], dir);
|
|
624
|
-
// commitChanges spawns git without an explicit env, so it sees the
|
|
625
|
-
// real process environment, not Jest's sandboxed process.env: the
|
|
626
|
-
// GIT_* identity set above never reaches it. Give the repo its own
|
|
627
|
-
// identity so the commit works on CI runners with no git user.
|
|
628
|
-
git(['config', 'user.name', 'Test'], dir);
|
|
629
|
-
git(['config', 'user.email', 'test@example.com'], dir);
|
|
630
|
-
git(['config', 'commit.gpgsign', 'false'], dir);
|
|
631
624
|
fs.writeFileSync(path.join(dir, 'package.json'), '{}');
|
|
632
625
|
fs.writeFileSync(path.join(dir, 'unrelated.txt'), 'wip');
|
|
633
626
|
git(['add', 'unrelated.txt'], dir);
|
|
@@ -33,17 +33,6 @@ const {
|
|
|
33
33
|
} = require('../../../utils/repo-detection');
|
|
34
34
|
const { uiCommand } = require('../../../ui-command');
|
|
35
35
|
|
|
36
|
-
// uiCommand waits 2 s for the dev servers and opens the browser 1 s later.
|
|
37
|
-
// Drive those timers with fake time instead of sleeping for real (the real
|
|
38
|
-
// waits made this suite take ~40 s and tripped the 5 s default timeout).
|
|
39
|
-
const STARTUP_AND_BROWSER_DELAY_MS = 3100;
|
|
40
|
-
|
|
41
|
-
async function runUi(options) {
|
|
42
|
-
const done = uiCommand(options);
|
|
43
|
-
await jest.advanceTimersByTimeAsync(STARTUP_AND_BROWSER_DELAY_MS);
|
|
44
|
-
return done;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
36
|
describe('CLI Command: ui', () => {
|
|
48
37
|
let consoleLogSpy;
|
|
49
38
|
let consoleErrorSpy;
|
|
@@ -54,7 +43,6 @@ describe('CLI Command: ui', () => {
|
|
|
54
43
|
|
|
55
44
|
beforeEach(() => {
|
|
56
45
|
jest.clearAllMocks();
|
|
57
|
-
jest.useFakeTimers();
|
|
58
46
|
|
|
59
47
|
// Mock console methods
|
|
60
48
|
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
@@ -87,7 +75,6 @@ describe('CLI Command: ui', () => {
|
|
|
87
75
|
});
|
|
88
76
|
|
|
89
77
|
afterEach(() => {
|
|
90
|
-
jest.useRealTimers();
|
|
91
78
|
consoleLogSpy.mockRestore();
|
|
92
79
|
consoleErrorSpy.mockRestore();
|
|
93
80
|
processExitSpy.mockRestore();
|
|
@@ -97,7 +84,7 @@ describe('CLI Command: ui', () => {
|
|
|
97
84
|
|
|
98
85
|
describe('Repository Detection', () => {
|
|
99
86
|
it('should use specified repo path when provided', async () => {
|
|
100
|
-
await
|
|
87
|
+
await uiCommand({ repo: '/custom/repo', port: 3001, open: false });
|
|
101
88
|
|
|
102
89
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
103
90
|
expect.stringContaining('Using specified repository')
|
|
@@ -105,7 +92,7 @@ describe('CLI Command: ui', () => {
|
|
|
105
92
|
});
|
|
106
93
|
|
|
107
94
|
it('should detect current Frigg repository', async () => {
|
|
108
|
-
await
|
|
95
|
+
await uiCommand({ port: 3001, open: false });
|
|
109
96
|
|
|
110
97
|
expect(getCurrentRepositoryInfo).toHaveBeenCalled();
|
|
111
98
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
@@ -120,7 +107,7 @@ describe('CLI Command: ui', () => {
|
|
|
120
107
|
currentSubPath: 'packages/backend'
|
|
121
108
|
});
|
|
122
109
|
|
|
123
|
-
await
|
|
110
|
+
await uiCommand({ port: 3001, open: false });
|
|
124
111
|
|
|
125
112
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
126
113
|
expect.stringContaining('Currently in subdirectory: packages/backend')
|
|
@@ -134,7 +121,7 @@ describe('CLI Command: ui', () => {
|
|
|
134
121
|
{ path: '/repos/frigg-2', name: 'frigg-2' }
|
|
135
122
|
]);
|
|
136
123
|
|
|
137
|
-
await
|
|
124
|
+
await uiCommand({ port: 3001, open: false });
|
|
138
125
|
|
|
139
126
|
expect(discoverFriggRepositories).toHaveBeenCalled();
|
|
140
127
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
@@ -146,7 +133,7 @@ describe('CLI Command: ui', () => {
|
|
|
146
133
|
getCurrentRepositoryInfo.mockResolvedValue(null);
|
|
147
134
|
discoverFriggRepositories.mockResolvedValue([]);
|
|
148
135
|
|
|
149
|
-
await
|
|
136
|
+
await uiCommand({ port: 3001, open: false });
|
|
150
137
|
|
|
151
138
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
152
139
|
expect.stringContaining('No Frigg repositories found')
|
|
@@ -157,7 +144,7 @@ describe('CLI Command: ui', () => {
|
|
|
157
144
|
|
|
158
145
|
describe('Development Mode', () => {
|
|
159
146
|
it('should spawn backend and frontend in dev mode', async () => {
|
|
160
|
-
await
|
|
147
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
161
148
|
|
|
162
149
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledTimes(2);
|
|
163
150
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
@@ -181,7 +168,7 @@ describe('CLI Command: ui', () => {
|
|
|
181
168
|
});
|
|
182
169
|
|
|
183
170
|
it('should use default port 3001', async () => {
|
|
184
|
-
await
|
|
171
|
+
await uiCommand({ open: false, dev: true });
|
|
185
172
|
|
|
186
173
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
187
174
|
expect.any(String),
|
|
@@ -194,7 +181,7 @@ describe('CLI Command: ui', () => {
|
|
|
194
181
|
});
|
|
195
182
|
|
|
196
183
|
it('should use custom port when specified', async () => {
|
|
197
|
-
await
|
|
184
|
+
await uiCommand({ port: 4000, open: false, dev: true });
|
|
198
185
|
|
|
199
186
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
200
187
|
expect.any(String),
|
|
@@ -210,7 +197,10 @@ describe('CLI Command: ui', () => {
|
|
|
210
197
|
});
|
|
211
198
|
|
|
212
199
|
it('should print status with correct URLs', async () => {
|
|
213
|
-
await
|
|
200
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
201
|
+
|
|
202
|
+
// Wait for startup delay (testing async behavior, not mocks)
|
|
203
|
+
await new Promise(resolve => setTimeout(resolve, 2100));
|
|
214
204
|
|
|
215
205
|
// Verify printStatus called with exact URLs
|
|
216
206
|
expect(mockProcessManager.printStatus).toHaveBeenCalledWith(
|
|
@@ -221,14 +211,20 @@ describe('CLI Command: ui', () => {
|
|
|
221
211
|
});
|
|
222
212
|
|
|
223
213
|
it('should open browser when open=true', async () => {
|
|
224
|
-
await
|
|
214
|
+
await uiCommand({ port: 3001, open: true, dev: true });
|
|
215
|
+
|
|
216
|
+
// Wait for startup + browser delay (testing async behavior, not mocks)
|
|
217
|
+
await new Promise(resolve => setTimeout(resolve, 3100));
|
|
225
218
|
|
|
226
219
|
// Verify browser opened with correct URL
|
|
227
220
|
expect(open).toHaveBeenCalledWith('http://localhost:5173');
|
|
228
221
|
});
|
|
229
222
|
|
|
230
223
|
it('should NOT open browser when open=false', async () => {
|
|
231
|
-
await
|
|
224
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
225
|
+
|
|
226
|
+
// Wait for startup delay (testing async behavior, not mocks)
|
|
227
|
+
await new Promise(resolve => setTimeout(resolve, 3100));
|
|
232
228
|
|
|
233
229
|
// Verify browser was not opened
|
|
234
230
|
expect(open).not.toHaveBeenCalled();
|
|
@@ -241,7 +237,7 @@ describe('CLI Command: ui', () => {
|
|
|
241
237
|
currentSubPath: null
|
|
242
238
|
});
|
|
243
239
|
|
|
244
|
-
await
|
|
240
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
245
241
|
|
|
246
242
|
expect(mockProcessManager.spawnProcess).toHaveBeenCalledWith(
|
|
247
243
|
expect.any(String),
|
|
@@ -256,7 +252,7 @@ describe('CLI Command: ui', () => {
|
|
|
256
252
|
});
|
|
257
253
|
|
|
258
254
|
it('should set REPOSITORY_INFO as JSON string with correct structure', async () => {
|
|
259
|
-
await
|
|
255
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
260
256
|
|
|
261
257
|
const call = mockProcessManager.spawnProcess.mock.calls[0];
|
|
262
258
|
const env = call[3].env;
|
|
@@ -279,7 +275,7 @@ describe('CLI Command: ui', () => {
|
|
|
279
275
|
{ path: '/repos/frigg-1', name: 'frigg-1' }
|
|
280
276
|
]);
|
|
281
277
|
|
|
282
|
-
await
|
|
278
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
283
279
|
|
|
284
280
|
const call = mockProcessManager.spawnProcess.mock.calls[0];
|
|
285
281
|
const env = call[3].env;
|
|
@@ -303,7 +299,7 @@ describe('CLI Command: ui', () => {
|
|
|
303
299
|
throw error;
|
|
304
300
|
});
|
|
305
301
|
|
|
306
|
-
await
|
|
302
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
307
303
|
|
|
308
304
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
309
305
|
expect.stringContaining('Failed to start Management UI'),
|
|
@@ -320,7 +316,7 @@ describe('CLI Command: ui', () => {
|
|
|
320
316
|
throw new Error('Generic startup error');
|
|
321
317
|
});
|
|
322
318
|
|
|
323
|
-
await
|
|
319
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
324
320
|
|
|
325
321
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
326
322
|
expect.stringContaining('Failed to start Management UI'),
|
|
@@ -332,13 +328,16 @@ describe('CLI Command: ui', () => {
|
|
|
332
328
|
|
|
333
329
|
describe('Process Management', () => {
|
|
334
330
|
it('should create ProcessManager instance', async () => {
|
|
335
|
-
await
|
|
331
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
336
332
|
|
|
337
333
|
expect(ProcessManager).toHaveBeenCalled();
|
|
338
334
|
});
|
|
339
335
|
|
|
340
336
|
it('should keep process running with stdin.resume', async () => {
|
|
341
|
-
await
|
|
337
|
+
await uiCommand({ port: 3001, open: false, dev: true });
|
|
338
|
+
|
|
339
|
+
// Wait for startup delay (testing async behavior, not mocks)
|
|
340
|
+
await new Promise(resolve => setTimeout(resolve, 2100));
|
|
342
341
|
|
|
343
342
|
// Verify stdin.resume called to keep process alive
|
|
344
343
|
expect(stdinResumeSpy).toHaveBeenCalled();
|
|
@@ -51,12 +51,8 @@ describe('frigg-cli dependencies', () => {
|
|
|
51
51
|
expect(packageJson.dependencies.commander).toBeDefined();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// would make the package depend on itself.
|
|
57
|
-
it('should declare @friggframework/devtools as a peer dependency for infrastructure', () => {
|
|
58
|
-
expect(packageJson.peerDependencies['@friggframework/devtools']).toBeDefined();
|
|
59
|
-
expect(packageJson.dependencies['@friggframework/devtools']).toBeUndefined();
|
|
54
|
+
it('should have @friggframework/devtools for infrastructure', () => {
|
|
55
|
+
expect(packageJson.dependencies['@friggframework/devtools']).toBeDefined();
|
|
60
56
|
});
|
|
61
57
|
});
|
|
62
58
|
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const { Command } = require('commander');
|
|
2
|
+
const { installCommand } = require('./index');
|
|
3
|
+
const { validatePackageExists } = require('./install-command/validate-package');
|
|
4
|
+
const { findNearestBackendPackageJson, validateBackendPath } = require('@friggframework/core');
|
|
5
|
+
const { installPackage } = require('./install-command/install-package');
|
|
6
|
+
const { createIntegrationFile } = require('./install-command/integration-file');
|
|
7
|
+
const { updateBackendJsFile } = require('./install-command/backend-js');
|
|
8
|
+
const { commitChanges } = require('./install-command/commit-changes');
|
|
9
|
+
const { logInfo, logError } = require('./install-command/logger');
|
|
10
|
+
|
|
11
|
+
describe('CLI Command Tests', () => {
|
|
12
|
+
it('should successfully install an API module when all steps complete without errors', async () => {
|
|
13
|
+
const mockApiModuleName = 'testModule';
|
|
14
|
+
const mockPackageName = `@friggframework/api-module-${mockApiModuleName}`;
|
|
15
|
+
const mockBackendPath = '/mock/backend/path';
|
|
16
|
+
|
|
17
|
+
jest.mock('./install-command/validate-package', () => ({
|
|
18
|
+
validatePackageExists: jest.fn().mockResolvedValue(true),
|
|
19
|
+
}));
|
|
20
|
+
jest.mock('./utils/backend-path', () => ({
|
|
21
|
+
findNearestBackendPackageJson: jest
|
|
22
|
+
.fn()
|
|
23
|
+
.mockReturnValue(mockBackendPath),
|
|
24
|
+
validateBackendPath: jest.fn().mockReturnValue(true),
|
|
25
|
+
}));
|
|
26
|
+
jest.mock('./install-command/install-package', () => ({
|
|
27
|
+
installPackage: jest.fn().mockReturnValue(true),
|
|
28
|
+
}));
|
|
29
|
+
jest.mock('./install-command/integration-file', () => ({
|
|
30
|
+
createIntegrationFile: jest.fn().mockReturnValue(true),
|
|
31
|
+
}));
|
|
32
|
+
jest.mock('./install-command/backend-js', () => ({
|
|
33
|
+
updateBackendJsFile: jest.fn().mockReturnValue(true),
|
|
34
|
+
}));
|
|
35
|
+
jest.mock('./install-command/commit-changes', () => ({
|
|
36
|
+
commitChanges: jest.fn().mockReturnValue(true),
|
|
37
|
+
}));
|
|
38
|
+
jest.mock('./install-command/logger', () => ({
|
|
39
|
+
logInfo: jest.fn(),
|
|
40
|
+
logError: jest.fn(),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
const program = new Command();
|
|
44
|
+
program
|
|
45
|
+
.command('install <apiModuleName>')
|
|
46
|
+
.description('Install an API module')
|
|
47
|
+
.action(installCommand);
|
|
48
|
+
|
|
49
|
+
await program.parseAsync(['node', 'install', mockApiModuleName]);
|
|
50
|
+
|
|
51
|
+
expect(validatePackageExists).toHaveBeenCalledWith(mockPackageName);
|
|
52
|
+
expect(findNearestBackendPackageJson).toHaveBeenCalled();
|
|
53
|
+
expect(validateBackendPath).toHaveBeenCalledWith(mockBackendPath);
|
|
54
|
+
expect(installPackage).toHaveBeenCalledWith(
|
|
55
|
+
mockBackendPath,
|
|
56
|
+
mockPackageName
|
|
57
|
+
);
|
|
58
|
+
expect(createIntegrationFile).toHaveBeenCalledWith(
|
|
59
|
+
mockBackendPath,
|
|
60
|
+
mockApiModuleName
|
|
61
|
+
);
|
|
62
|
+
expect(updateBackendJsFile).toHaveBeenCalledWith(
|
|
63
|
+
mockBackendPath,
|
|
64
|
+
mockApiModuleName
|
|
65
|
+
);
|
|
66
|
+
expect(commitChanges).toHaveBeenCalledWith(
|
|
67
|
+
mockBackendPath,
|
|
68
|
+
mockApiModuleName
|
|
69
|
+
);
|
|
70
|
+
expect(logInfo).toHaveBeenCalledWith(
|
|
71
|
+
`Successfully installed ${mockPackageName} and updated the project.`
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should log an error and exit with code 1 if the package does not exist', async () => {
|
|
76
|
+
const mockExit = jest
|
|
77
|
+
.spyOn(process, 'exit')
|
|
78
|
+
.mockImplementation(() => {});
|
|
79
|
+
const mockLogError = jest
|
|
80
|
+
.spyOn(require('./install-command/logger'), 'logError')
|
|
81
|
+
.mockImplementation(() => {});
|
|
82
|
+
const mockValidatePackageExists = jest
|
|
83
|
+
.spyOn(
|
|
84
|
+
require('./install-command/validate-package'),
|
|
85
|
+
'validatePackageExists'
|
|
86
|
+
)
|
|
87
|
+
.mockImplementation(() => {
|
|
88
|
+
throw new Error('Package not found');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const program = new Command();
|
|
92
|
+
program
|
|
93
|
+
.command('install <apiModuleName>')
|
|
94
|
+
.description('Install an API module')
|
|
95
|
+
.action(installCommand);
|
|
96
|
+
|
|
97
|
+
await program.parseAsync(['node', 'install', 'nonexistent-package']);
|
|
98
|
+
|
|
99
|
+
expect(mockValidatePackageExists).toHaveBeenCalledWith(
|
|
100
|
+
'@friggframework/api-module-nonexistent-package'
|
|
101
|
+
);
|
|
102
|
+
expect(mockLogError).toHaveBeenCalledWith(
|
|
103
|
+
'An error occurred:',
|
|
104
|
+
expect.any(Error)
|
|
105
|
+
);
|
|
106
|
+
expect(mockExit).toHaveBeenCalledWith(1);
|
|
107
|
+
|
|
108
|
+
mockExit.mockRestore();
|
|
109
|
+
mockLogError.mockRestore();
|
|
110
|
+
mockValidatePackageExists.mockRestore();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should log an error and exit with code 1 if the backend path is invalid', async () => {
|
|
114
|
+
const mockLogError = jest
|
|
115
|
+
.spyOn(require('./install-command/logger'), 'logError')
|
|
116
|
+
.mockImplementation(() => {});
|
|
117
|
+
const mockProcessExit = jest
|
|
118
|
+
.spyOn(process, 'exit')
|
|
119
|
+
.mockImplementation(() => {});
|
|
120
|
+
const mockValidatePackageExists = jest
|
|
121
|
+
.spyOn(
|
|
122
|
+
require('./install-command/validate-package'),
|
|
123
|
+
'validatePackageExists'
|
|
124
|
+
)
|
|
125
|
+
.mockResolvedValue(true);
|
|
126
|
+
const mockFindNearestBackendPackageJson = jest
|
|
127
|
+
.spyOn(
|
|
128
|
+
require('./utils/backend-path'),
|
|
129
|
+
'findNearestBackendPackageJson'
|
|
130
|
+
)
|
|
131
|
+
.mockReturnValue('/invalid/path');
|
|
132
|
+
const mockValidateBackendPath = jest
|
|
133
|
+
.spyOn(require('./utils/backend-path'), 'validateBackendPath')
|
|
134
|
+
.mockImplementation(() => {
|
|
135
|
+
throw new Error('Invalid backend path');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const program = new Command();
|
|
139
|
+
program
|
|
140
|
+
.command('install <apiModuleName>')
|
|
141
|
+
.description('Install an API module')
|
|
142
|
+
.action(installCommand);
|
|
143
|
+
|
|
144
|
+
await program.parseAsync(['node', 'install', 'test-module']);
|
|
145
|
+
|
|
146
|
+
expect(mockLogError).toHaveBeenCalledWith(
|
|
147
|
+
'An error occurred:',
|
|
148
|
+
expect.any(Error)
|
|
149
|
+
);
|
|
150
|
+
expect(mockProcessExit).toHaveBeenCalledWith(1);
|
|
151
|
+
|
|
152
|
+
mockLogError.mockRestore();
|
|
153
|
+
mockProcessExit.mockRestore();
|
|
154
|
+
mockValidatePackageExists.mockRestore();
|
|
155
|
+
mockFindNearestBackendPackageJson.mockRestore();
|
|
156
|
+
mockValidateBackendPath.mockRestore();
|
|
157
|
+
});
|
|
158
|
+
});
|