@friggframework/devtools 2.0.0--canary.710.7cfcf12.0 → 2.0.0--canary.682.451c957.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/README.md +30 -77
- 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/generate-iam.test.js +0 -18
- package/frigg-cli/__tests__/unit/commands/install.test.js +341 -601
- package/frigg-cli/__tests__/unit/commands/ui.test.js +30 -31
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -6
- package/frigg-cli/generate-command/index.js +0 -1
- package/frigg-cli/generate-iam-command.js +0 -1
- package/frigg-cli/index.js +4 -9
- package/frigg-cli/index.test.js +158 -0
- package/frigg-cli/init-command/backend-first-handler.js +554 -397
- package/frigg-cli/init-command/index.js +35 -82
- package/frigg-cli/install-command/commit-changes.js +8 -40
- package/frigg-cli/install-command/environment-variables.js +0 -15
- package/frigg-cli/install-command/index.js +21 -96
- package/frigg-cli/install-command/install-package.js +4 -77
- package/frigg-cli/install-command/integration-file.js +11 -20
- package/frigg-cli/install-command/template.js +75 -102
- package/frigg-cli/install-command/validate-package.js +4 -36
- package/frigg-cli/package.json +1 -1
- package/frigg-cli/test/init-command.test.js +2 -9
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +335 -0
- package/infrastructure/__tests__/postgres-config.test.js +835 -241
- package/infrastructure/__tests__/template-generation.test.js +8 -36
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +1 -21
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +2 -6
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -30
- package/infrastructure/domains/database/aurora-builder.js +2 -13
- package/infrastructure/domains/database/aurora-builder.test.js +0 -22
- 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 +12 -26
- package/infrastructure/domains/security/iam-generator.js +5 -112
- package/infrastructure/domains/security/iam-generator.test.js +0 -94
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +6 -36
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +28 -17
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +61 -22
- 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 +8 -10
- package/frigg-cli/__tests__/unit/commands/init.test.js +0 -688
- package/frigg-cli/init-command/deployment-modes.js +0 -7
- package/frigg-cli/init-command/safe-path.js +0 -58
- package/frigg-cli/init-command/scaffold-dependencies.js +0 -202
- package/frigg-cli/install-command/app-definition.js +0 -174
- package/frigg-cli/install-command/resolve-module.js +0 -69
- package/frigg-cli/templates/backend/README.md +0 -267
- package/frigg-cli/templates/backend/env.example +0 -20
- package/frigg-cli/templates/backend/gitignore +0 -10
- package/frigg-cli/templates/backend/index.js +0 -114
- package/frigg-cli/templates/backend/infrastructure.js +0 -20
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -148
|
@@ -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
|
|
|
@@ -118,7 +118,6 @@ async function generateCommand(options = {}) {
|
|
|
118
118
|
if (options.format === 'cloudformation') {
|
|
119
119
|
template = await generateCloudFormationTemplate({
|
|
120
120
|
appName,
|
|
121
|
-
serviceName: appDefinition.name || 'create-frigg-app',
|
|
122
121
|
features,
|
|
123
122
|
userPrefix: options.user || 'frigg-deployment-user',
|
|
124
123
|
stackName: options.stackName || 'frigg-deployment-iam',
|
|
@@ -62,7 +62,6 @@ async function generateIamCommand(options = {}) {
|
|
|
62
62
|
// Use the summary already extracted above (line 44)
|
|
63
63
|
const cloudFormationYaml = generateIAMCloudFormation({
|
|
64
64
|
appName: summary.appName,
|
|
65
|
-
serviceName: summary.serviceName,
|
|
66
65
|
features: summary.features,
|
|
67
66
|
userPrefix: deploymentUserName,
|
|
68
67
|
stackName,
|
package/frigg-cli/index.js
CHANGED
|
@@ -91,16 +91,11 @@ const { ssmPushCommand } = require('./ssm-command');
|
|
|
91
91
|
const program = new Command();
|
|
92
92
|
|
|
93
93
|
program
|
|
94
|
-
.command('init [
|
|
94
|
+
.command('init [templateName]')
|
|
95
95
|
.description('Initialize a new Frigg application')
|
|
96
|
-
.option('-
|
|
97
|
-
.option('-
|
|
98
|
-
.option('-
|
|
99
|
-
.option('--no-install', 'skip installing dependencies')
|
|
100
|
-
.option('--no-git', 'skip initializing a git repository')
|
|
101
|
-
.option('-f, --force', 'scaffold into a non-empty directory and overwrite README.md')
|
|
102
|
-
.option('-v, --verbose', 'enable verbose output')
|
|
103
|
-
.option('-t, --template <template>', 'legacy template (no longer supported)')
|
|
96
|
+
.option('-t, --template <template>', 'template to use', 'backend-only')
|
|
97
|
+
.option('-n, --name <name>', 'project name')
|
|
98
|
+
.option('-d, --directory <directory>', 'target directory')
|
|
104
99
|
.action(initCommand);
|
|
105
100
|
|
|
106
101
|
program
|
|
@@ -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
|
+
});
|