-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add init prompts for Gen2 (#13849)
* feat: add warning to init * feat: add prompt to init * feat: only prompt on new project * feat: add guide to Gen2 * refactor: change to use process exit * Update packages/amplify-cli/src/init-steps/preInitMigrationWarning.ts Co-authored-by: Amplifiyer <[email protected]> * refactor: rename to gen2Recommendation * refactor: combine gen2Recommendation to preInitSetup * feat: remove goodbye message * test: fix init.test * test: add unit test for preInitSetup * chore: rename to getPreInitSetup * feat: change verbiage * chore: update unit test * feat: add whyContinueWithGen1 to stack metadata * fix: verify verify_versions_match * fix: verify verify_versions_match * feat: bump versions * feat: bump versions * feat: bump versions * chore: rename to recommendGen2 * chore: rename to recommendGen2 in test * revert .sh format * chore: rename and not export preInitSetup * fix: export gen2Recommandation and preInitSetup for test * fix: set inital answer for pick * Revert "fix: set inital answer for pick" This reverts commit 7ecde5c. * Revert "Revert "fix: set inital answer for pick"" This reverts commit d8fa624. * fix: preInitSetup.test * fix: e2e test by adding isCI * chore: upgrade node-pty * Revert "fix: e2e test by adding isCI" This reverts commit 71b204c. * test: add prompt to e2e * fix: set default value for whyContinueWithGen1 * fix: projectConfig undefined and remove default choice * fix: preInitSetup.test.ts * fix: add default choice back * fix: remove prompts from migration test * test: move new prompt from v12 * test: move new prompt from initJSProjectWithProfile * Revert "test: move new prompt from initJSProjectWithProfile" This reverts commit eeb6f71. * test: move new prompts from initJSProjectWithProfile * chore: change recommendGen2 * test: fix preInitSetup unit test * test: add includeGen2RecommendationPrompt * test: add includeGen2RecommendationPrompt to migration-2 * test: remove prompts from initAndroidProjectWithProfileV12 --------- Co-authored-by: 0.618 <[email protected]> Co-authored-by: Amplifiyer <[email protected]>
- Loading branch information
1 parent
a644a1f
commit 7ab8fae
Showing
19 changed files
with
223 additions
and
28 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
95 changes: 95 additions & 0 deletions
95
packages/amplify-cli/src/__tests__/init-steps/preInitSetup.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,95 @@ | ||
import { $TSContext } from '@aws-amplify/amplify-cli-core'; | ||
import { printer, prompter } from '@aws-amplify/amplify-prompts'; | ||
import { getPreInitSetup, preInitSetup, gen2Recommendation } from '../../init-steps/preInitSetup'; | ||
import { isNewProject } from '../../init-steps/s0-analyzeProject'; | ||
|
||
// Mock dependencies | ||
jest.mock('@aws-amplify/amplify-cli-core', () => ({ | ||
...(jest.requireActual('@aws-amplify/amplify-cli-core') as {}), | ||
FeatureFlags: { | ||
getBoolean: jest.fn(), | ||
getNumber: jest.fn(), | ||
isInitialized: jest.fn().mockReturnValue(true), | ||
ensureDefaultFeatureFlags: jest.fn(), | ||
}, | ||
getPackageManager: jest.fn(), | ||
})); | ||
|
||
jest.mock('@aws-amplify/amplify-prompts', () => ({ | ||
printer: { | ||
warn: jest.fn(), | ||
}, | ||
prompter: { | ||
confirmContinue: jest.fn(), | ||
pick: jest.fn(), | ||
}, | ||
})); | ||
|
||
jest.mock('../../init-steps/s0-analyzeProject', () => ({ | ||
isNewProject: jest.fn(), | ||
})); | ||
|
||
describe('preInitSetup', () => { | ||
it('should return preInitSetupBasic when isHeadless is true', () => { | ||
const result = getPreInitSetup(false); | ||
expect(result).toBe(preInitSetup); | ||
}); | ||
|
||
it('should return a function when isHeadless is false', () => { | ||
const result = getPreInitSetup(false); | ||
expect(typeof result).toBe('function'); | ||
}); | ||
}); | ||
|
||
describe('gen2Recommendation', () => { | ||
let context; | ||
|
||
beforeEach(() => { | ||
context = { exeInfo: {} } as $TSContext; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should recommend using Gen 2 for new projects', async () => { | ||
const isNewProjectMock = jest.mocked(isNewProject); | ||
isNewProjectMock.mockReturnValue(true); | ||
|
||
const confirmContinueMock = jest.mocked(prompter.confirmContinue); | ||
confirmContinueMock.mockResolvedValue(true); | ||
|
||
const pickMock = jest.mocked(prompter.pick); | ||
pickMock.mockResolvedValue('I am a current Gen 1 user'); | ||
|
||
await gen2Recommendation(context); | ||
|
||
expect(require('@aws-amplify/amplify-prompts').printer.warn).toHaveBeenCalledWith( | ||
'For new projects, we recommend starting with AWS Amplify Gen 2, our new code-first developer experience. Get started at https://docs.amplify.aws/react/start/quickstart/', | ||
); | ||
expect(confirmContinueMock).toHaveBeenCalledWith('Do you want to continue with Amplify Gen 1?'); | ||
expect(pickMock).toHaveBeenCalledWith( | ||
'Why would you like to use Amplify Gen 1?', | ||
[ | ||
'I am a current Gen 1 user', | ||
'Gen 2 is missing features I need from Gen 1', | ||
'I find the Gen 1 CLI easier to use', | ||
'Prefer not to answer', | ||
], | ||
{ initial: 3 }, | ||
); | ||
expect(context.exeInfo.projectConfig).toEqual({ whyContinueWithGen1: 'I am a current Gen 1 user' }); | ||
}); | ||
|
||
it('should return the context for existing projects', async () => { | ||
const isNewProjectMock = jest.mocked(isNewProject); | ||
isNewProjectMock.mockReturnValue(false); | ||
|
||
const result = await gen2Recommendation(context); | ||
|
||
expect(result).toEqual(context); | ||
expect(printer.warn).not.toHaveBeenCalled(); | ||
expect(prompter.confirmContinue).not.toHaveBeenCalled(); | ||
expect(prompter.pick).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.