@@ -13,7 +13,8 @@ import {ConfigActionSummaryViewer} from '../../../src/lib/viewers/ActionSummaryV
1313
1414import { SpyConfigWriter } from '../../stubs/SpyConfigWriter' ;
1515import { SpyConfigViewer } from '../../stubs/SpyConfigViewer' ;
16- import { DisplayEventType , SpyDisplay } from '../../stubs/SpyDisplay' ;
16+ import { DisplayEvent , DisplayEventType , SpyDisplay } from '../../stubs/SpyDisplay' ;
17+ import { LogEventDisplayer } from '../../../src/lib/listeners/LogEventListener' ;
1718
1819const PATH_TO_FIXTURES = path . join ( __dirname , '..' , '..' , 'fixtures' ) ;
1920
@@ -32,7 +33,7 @@ describe('ConfigAction tests', () => {
3233 beforeEach ( ( ) => {
3334 spyDisplay = new SpyDisplay ( ) ;
3435 dependencies = {
35- logEventListeners : [ ] ,
36+ logEventListeners : [ new LogEventDisplayer ( spyDisplay ) ] ,
3637 progressEventListeners : [ ] ,
3738 viewer : new ConfigStyledYamlViewer ( spyDisplay ) ,
3839 configFactory : new StubCodeAnalyzerConfigFactory ( ) ,
@@ -158,7 +159,7 @@ describe('ConfigAction tests', () => {
158159 stubConfigFactory = new AlternativeStubCodeAnalyzerConfigFactory ( ) ;
159160 spyDisplay = new SpyDisplay ( ) ;
160161 dependencies = {
161- logEventListeners : [ ] ,
162+ logEventListeners : [ new LogEventDisplayer ( spyDisplay ) ] ,
162163 progressEventListeners : [ ] ,
163164 viewer : new ConfigStyledYamlViewer ( spyDisplay ) ,
164165 configFactory : stubConfigFactory ,
@@ -332,25 +333,44 @@ describe('ConfigAction tests', () => {
332333 expect ( output ) . toContain ( 'disable_engine: true # Modified from: false' ) ;
333334 } ) ;
334335
335- it ( 'Edge Case: When plugin throws error when attempting to create engine config and engine is enabled , then error' , async ( ) => {
336+ it ( 'Edge Case: When plugin throws error when attempting to create engine config but engine is disabled , then do not error' , async ( ) => {
336337 dependencies . pluginsFactory = new FactoryForThrowingEnginePlugin ( ) ;
337- dependencies . configFactory = new StubCodeAnalyzerConfigFactory ( ) ;
338+ dependencies . configFactory = new StubCodeAnalyzerConfigFactory ( CodeAnalyzerConfig . fromObject ( {
339+ engines : {
340+ uncreatableEngine : {
341+ disable_engine : true ,
342+ someField : 'some non default value'
343+ }
344+ }
345+ } ) ) ;
338346
339- await expect ( runActionAndGetDisplayedConfig ( dependencies , [ 'NoRuleHasThisTag' ] ) ) . rejects . toThrowError ( ) ;
347+ const output : string = await runActionAndGetDisplayedConfig ( dependencies , [ 'NoRuleHasThisTag' ] ) ;
348+
349+ expect ( spyDisplay . getDisplayEvents ( ) . filter ( e => e . type == DisplayEventType . ERROR ) ) . toHaveLength ( 0 ) ;
350+
351+ expect ( output ) . toContain ( 'disable_engine: true # Modified from: false' ) ;
352+ expect ( output ) . toContain ( 'someField: some non default value # Modified from: "someDefault"' ) ;
340353 } ) ;
341354
342- it ( 'Edge Case: When plugin thrown error when attempting to create engine config but engine is disabled , then do not error' , async ( ) => {
355+ it ( 'Edge Case: When plugin throws error when attempting to create engine config, but engine is enabled , then issue error log but continue with whatever is in the users config for that engine ' , async ( ) => {
343356 dependencies . pluginsFactory = new FactoryForThrowingEnginePlugin ( ) ;
344357 dependencies . configFactory = new StubCodeAnalyzerConfigFactory ( CodeAnalyzerConfig . fromObject ( {
345358 engines : {
346359 uncreatableEngine : {
347- disable_engine : true
360+ disable_engine : false ,
361+ someField : 'some non default value'
348362 }
349363 }
350364 } ) ) ;
351365
352- const output : string = await runActionAndGetDisplayedConfig ( dependencies , [ 'NoRuleHasThisTag' ] ) ;
353- expect ( output ) . toContain ( 'disable_engine: true # Modified from: false' ) ;
366+ const output : string = await runActionAndGetDisplayedConfig ( dependencies , [ 'uncreatableEngine' ] ) ;
367+
368+ const errorEvents : DisplayEvent [ ] = spyDisplay . getDisplayEvents ( ) . filter ( e => e . type == DisplayEventType . ERROR ) ;
369+ expect ( errorEvents ) . toHaveLength ( 1 ) ;
370+ expect ( errorEvents [ 0 ] . data ) . toContain ( 'Error thrown by createEngineConfig' ) ;
371+
372+ expect ( output ) . toContain ( 'disable_engine: false' ) ;
373+ expect ( output ) . toContain ( 'someField: some non default value # Modified from: "someDefault"' ) ;
354374 } ) ;
355375
356376 it . each ( [
@@ -515,8 +535,13 @@ describe('ConfigAction tests', () => {
515535
516536 // ==== OUTPUT PROCESSING ====
517537 const displayEvents = spyDisplay . getDisplayEvents ( ) ;
518- expect ( displayEvents [ 4 ] . type ) . toEqual ( DisplayEventType . LOG ) ;
519- return ansis . strip ( displayEvents [ 4 ] . data ) ;
538+ if ( displayEvents [ 4 ] . type === DisplayEventType . LOG ) {
539+ return ansis . strip ( displayEvents [ 4 ] . data ) ;
540+ } else if ( displayEvents [ 5 ] . type === DisplayEventType . LOG ) {
541+ return ansis . strip ( displayEvents [ 5 ] . data ) ;
542+ } else {
543+ return 'Could Not Get Specific Output' ;
544+ }
520545 }
521546} ) ;
522547
@@ -806,6 +831,19 @@ class ThrowingEnginePlugin extends EngineApi.EnginePluginV1 {
806831 return [ 'uncreatableEngine' ] ;
807832 }
808833
834+ describeEngineConfig ( ) : EngineApi . ConfigDescription {
835+ return {
836+ overview : 'Some Overview' ,
837+ fieldDescriptions : {
838+ someField : {
839+ descriptionText : 'some description' ,
840+ valueType : 'string' ,
841+ defaultValue : 'someDefault'
842+ }
843+ }
844+ }
845+ }
846+
809847 createEngineConfig ( _engineName : string , _configValueExtractor : EngineApi . ConfigValueExtractor ) : Promise < EngineApi . ConfigObject > {
810848 throw new Error ( 'Error thrown by createEngineConfig' ) ;
811849 }
0 commit comments