Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE @W-17052870@ Polished config output #1665

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions messages/action-summary-viewer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
5 changes: 4 additions & 1 deletion src/lib/actions/ConfigAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/viewers/ActionSummaryViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this from action-summary-viewer.md as well ?

this.displayLineSeparator();
}
this.displayLineSeparator();

this.displayLogFileInfo(logFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
=== Summary

No output file was specified.

Additional log information written to:
24 changes: 23 additions & 1 deletion test/lib/actions/ConfigAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});
});

Expand Down