diff --git a/messages/action-summary-viewer.md b/messages/action-summary-viewer.md index 2fe72f796..c29822674 100644 --- a/messages/action-summary-viewer.md +++ b/messages/action-summary-viewer.md @@ -6,10 +6,6 @@ Summary Additional log information written to: -# config-action.no-outfiles - -No output file was specified. - # config-action.outfile-location Configuration written to: diff --git a/src/lib/actions/ConfigAction.ts b/src/lib/actions/ConfigAction.ts index e588334ae..c997b5031 100644 --- a/src/lib/actions/ConfigAction.ts +++ b/src/lib/actions/ConfigAction.ts @@ -121,10 +121,13 @@ export class ConfigAction { }; const configModel: ConfigModel = this.dependencies.modelGenerator(relevantEngines, userConfigContext, defaultConfigContext); - this.dependencies.viewer.view(configModel); const fileWritten: boolean = this.dependencies.writer ? await this.dependencies.writer.write(configModel) : false; + if (!fileWritten) { + this.dependencies.viewer.view(configModel); + } + this.dependencies.actionSummaryViewer.view(logFileWriter.getLogDestination(), fileWritten ? input['output-file'] : undefined); return Promise.resolve(); } diff --git a/src/lib/viewers/ActionSummaryViewer.ts b/src/lib/viewers/ActionSummaryViewer.ts index 0754696d2..59377b028 100644 --- a/src/lib/viewers/ActionSummaryViewer.ts +++ b/src/lib/viewers/ActionSummaryViewer.ts @@ -34,10 +34,8 @@ export class ConfigActionSummaryViewer extends AbstractActionSummaryViewer { if (outfile) { this.displayOutfile(outfile); - } else { - this.display.displayLog(getMessage(BundleName.ActionSummaryViewer, 'config-action.no-outfiles')); + this.displayLineSeparator(); } - this.displayLineSeparator(); this.displayLogFileInfo(logFile); } diff --git a/test/fixtures/comparison-files/lib/actions/ConfigAction.test.ts/action-summaries/no-outfile-created.txt.goldfile b/test/fixtures/comparison-files/lib/actions/ConfigAction.test.ts/action-summaries/no-outfile-created.txt.goldfile index 3bcdbe5f2..86522fd7c 100644 --- a/test/fixtures/comparison-files/lib/actions/ConfigAction.test.ts/action-summaries/no-outfile-created.txt.goldfile +++ b/test/fixtures/comparison-files/lib/actions/ConfigAction.test.ts/action-summaries/no-outfile-created.txt.goldfile @@ -1,5 +1,3 @@ === Summary -No output file was specified. - Additional log information written to: \ No newline at end of file diff --git a/test/lib/actions/ConfigAction.test.ts b/test/lib/actions/ConfigAction.test.ts index 10edee0ab..84c536c08 100644 --- a/test/lib/actions/ConfigAction.test.ts +++ b/test/lib/actions/ConfigAction.test.ts @@ -13,6 +13,7 @@ import {ConfigStyledYamlViewer} from '../../../src/lib/viewers/ConfigViewer'; import {ConfigActionSummaryViewer} from '../../../src/lib/viewers/ActionSummaryViewer'; import {SpyConfigWriter} from '../../stubs/SpyConfigWriter'; +import {SpyConfigViewer} from '../../stubs/SpyConfigViewer'; import {DisplayEventType, SpyDisplay} from '../../stubs/SpyDisplay'; const PATH_TO_FIXTURES = path.join(__dirname, '..', '..', 'fixtures'); @@ -403,17 +404,38 @@ describe('ConfigAction tests', () => { }; }); - it('If a ConfigWriter is provided, it is used along with the ConfigViewer', async () => { + it('If a file is created, then the ConfigViewer is unused', async () => { // ==== SETUP ==== // We need to add a Writer to the dependencies. const spyWriter = new SpyConfigWriter(); dependencies.writer = spyWriter; + // Replace the viewer with a Spy. + const spyViewer = new SpyConfigViewer(); + dependencies.viewer = spyViewer; // ==== TESTED BEHAVIOR ==== await runActionAndGetDisplayedConfig(dependencies, ['all']); // ==== ASSERTIONS ==== expect(spyWriter.getCallHistory()).toHaveLength(1); + expect(spyViewer.getCallHistory()).toHaveLength(0); + }); + + it('If a file is specified by not created, then the ConfigViewer is used', async () => { + // ==== SETUP ==== + // We need to add a Writer to the dependencies. + const spyWriter = new SpyConfigWriter(false); + dependencies.writer = spyWriter; + // Replace the viewer with a Spy. + const spyViewer = new SpyConfigViewer(); + dependencies.viewer = spyViewer; + + // ==== TESTED BEHAVIOR ==== + await runActionAndGetDisplayedConfig(dependencies, ['all']); + + // ==== ASSERTIONS ==== + expect(spyWriter.getCallHistory()).toHaveLength(1); + expect(spyViewer.getCallHistory()).toHaveLength(1); }); });