-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(messages): support custom messages
- Loading branch information
Showing
8 changed files
with
110 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as fs from 'fs'; | ||
import { isAllOK, getMessages } from '../results'; | ||
import { RawResult } from '../types'; | ||
|
||
describe('results', () => { | ||
describe('all results OK', () => { | ||
it('should indicate all results are OK', async () => { | ||
const rawResults: RawResult[] = [ | ||
{ | ||
bin: 'mvn', | ||
satisfies: true | ||
} as RawResult | ||
]; | ||
|
||
const result = isAllOK(rawResults); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should indicate all results are OK', async () => { | ||
const rawResults: RawResult[] = [ | ||
{ | ||
bin: 'mvn', | ||
satisfies: false | ||
} as RawResult | ||
]; | ||
|
||
const result = isAllOK(rawResults); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('custom messages', () => { | ||
it('should return messages', async () => { | ||
const rawResults: RawResult[] = [ | ||
{ | ||
bin: 'mvn', | ||
installed: false, | ||
installMessage: '<mvn install instructions>' | ||
} as RawResult, | ||
{ | ||
bin: 'nginx', | ||
satisfies: false, | ||
updateMessage: '<nginx update instructions>' | ||
} as RawResult | ||
]; | ||
|
||
const result = getMessages(rawResults); | ||
const expectation = ['<mvn install instructions>', '<nginx update instructions>']; | ||
expect(result).toEqual(expectation); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { RawResult } from './types'; | ||
|
||
export function isAllOK(rawResults: RawResult[]) { | ||
return rawResults.filter(result => !result.optional).every(result => result.satisfies === true); | ||
} | ||
|
||
export function getMessages(rawResults: RawResult[]) { | ||
const notInstalledItems = rawResults.filter(item => !item.installed && item.installMessage); | ||
const unsatisfiedInstalledItems = rawResults.filter( | ||
item => !item.satisfies && item.updateMessage | ||
); | ||
|
||
const messages = [...notInstalledItems, ...unsatisfiedInstalledItems].map(item => { | ||
return item.installMessage || item.updateMessage; | ||
}); | ||
|
||
return messages; | ||
} |
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