-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): remove unnecessary stack trace log when adding services (#4610
- Loading branch information
1 parent
a3feb15
commit 56efb32
Showing
13 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/amplify-cli/src/__tests__/executeAmplifyCommand.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import fs from 'fs-extra'; | ||
import { executeAmplifyCommandForPlugin } from '../../lib/execution-manager'; | ||
|
||
describe('executeAmplifyCommand: ', () => { | ||
const mockExecuteAmplifyCommand = jest.fn(); | ||
const mockContext = { | ||
print: { | ||
info: jest.fn(), | ||
}, | ||
}; | ||
|
||
const mockPluginModule = { | ||
executeAmplifyCommand: mockExecuteAmplifyCommand, | ||
}; | ||
|
||
describe('case: executeAmplifyCommand is run on a directory where amplify is not initialized', () => { | ||
const err = new Error( | ||
"You are not working inside a valid amplify project.\nUse 'amplify init' in the root of your app directory to initialize your project with Amplify", | ||
); | ||
|
||
beforeEach(() => { | ||
mockExecuteAmplifyCommand.mockReturnValue(err); | ||
(fs.existsSync as any).mockReturnValue(true); | ||
}); | ||
|
||
it('executeAmplifyCommand should fail to add a service and print an error message', async () => { | ||
await (executeAmplifyCommandForPlugin as any)(mockContext, mockPluginModule); | ||
expect(mockExecuteAmplifyCommand).toReturnWith(err); | ||
}); | ||
}); | ||
|
||
describe('case: executeAmplifyCommand returns a stack trace error', () => { | ||
const err = new Error('An unexpected error has occurred'); | ||
|
||
beforeEach(() => { | ||
mockExecuteAmplifyCommand.mockReturnValue(err.stack); | ||
(fs.existsSync as any).mockReturnValue(true); | ||
}); | ||
|
||
it('executeAmplifyCommand should get an unexpected error and print a stack trace', async () => { | ||
await (executeAmplifyCommandForPlugin as any)(mockContext, mockPluginModule); | ||
|
||
expect(mockExecuteAmplifyCommand).toReturnWith(err.stack); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/amplify-cli/tests/amplify-lib/executeAmplifyCommand.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const plugin_manager = require('../../lib/plugin-manager'); | ||
|
||
describe('executeAmplifyCommand: ', () => { | ||
const mockExecuteAmplifyCommand = jest.fn(); | ||
const mockPluginCandidates = []; | ||
|
||
const mockPluginModule = { | ||
executeAmplifyCommand: mockExecuteAmplifyCommand, | ||
}; | ||
|
||
const mockContext = { | ||
print: { | ||
info: jest.fn(), | ||
error: jest.fn(), | ||
}, | ||
}; | ||
|
||
it('executeAmplifyCommand method should exist', () => { | ||
expect(mockPluginModule.executeAmplifyCommand).toBeDefined(); | ||
}); | ||
|
||
describe('case: executeAmplifyCommand is run on a directory where amplify has not been initialized', () => { | ||
beforeEach(() => { | ||
mockExecuteAmplifyCommand.mockReturnValue(undefined); | ||
}); | ||
|
||
it('executeAmplifyCommand should fail to add a service and print an error message', async () => { | ||
await mockPluginModule.executeAmplifyCommand(mockContext); | ||
expect(mockContext.print.error).toBeCalledWith( | ||
"You are not working inside a valid amplify project.\nUse 'amplify init' in the root of your app directory to initialize your project with Amplify", | ||
); | ||
}); | ||
}); | ||
}); |