Skip to content

Commit

Permalink
fix: get the defaultEditor value from the localEnvInfo context variab…
Browse files Browse the repository at this point in the history
…le (#9783)

* fix: get the defaultEditor value from the localEnvInfo context variable

Get the defaultEditor value from the context when the local-env-info.json file has not been created
yet

fix #8356

* fix: get the defaultEditor value from the localEnvInfo context variable

* fix: get the defaultEditor value from the localEnvInfo context variable
  • Loading branch information
flozender committed Feb 25, 2022
1 parent f8c9100 commit cdb5aec
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { $TSContext } from 'amplify-cli-core';
import { analyzeProject } from '../../init-steps/s0-analyzeProject';
import { constructMockPluginPlatform } from '../extensions/amplify-helpers/mock-plugin-platform';
import { Input } from '../../domain/input';
import { constructContext } from '../../context-manager';

describe('analyzeProject', () => {
it('recognizes the default editor', async () => {
const mockPluginPlatform = constructMockPluginPlatform();
const mockProcessArgv = [
'/Users/userName/.nvm/versions/node/v12.16.1/bin/node',
'/Users/userName/.nvm/versions/node/v12.16.1/bin/amplify',
'init',
'-y',
];
const mockInput = new Input(mockProcessArgv);
const mockContext = constructContext(mockPluginPlatform, mockInput) as unknown as $TSContext;
const frontendPlugins = [
{
name: 'amplify-frontend-javascript',
pluginType: 'frontend',
pluginName: 'javascript',
directory: 'amplify-frontend-javascript',
},
{
name: 'amplify-frontend-flutter',
pluginType: 'frontend',
pluginName: 'flutter',
directory: 'amplify-frontend-flutter',
},
];
mockContext.exeInfo = {
inputParams: {},
localEnvInfo: {
defaultEditor: 'Visual Studio Code',
},
};
mockContext.runtime.plugins.push(...frontendPlugins);
const result = await analyzeProject(mockContext);
expect(result.exeInfo.localEnvInfo.defaultEditor).toStrictEqual('Visual Studio Code');
});
});
4 changes: 4 additions & 0 deletions packages/amplify-cli/src/init-steps/s0-analyzeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ async function getEditor(context: $TSContext) {
editor = await editorSelection(editor);
}

if (!editor) {
editor = context.exeInfo.localEnvInfo?.defaultEditor;
}

return editor;
}
/* End getEditor */
Expand Down

0 comments on commit cdb5aec

Please sign in to comment.