-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(messages): add message-format for better messaging
Because we care about people who use this thing.
- Loading branch information
Kent C. Dodds
committed
Jan 29, 2017
1 parent
33d3f9c
commit 608dee8
Showing
7 changed files
with
130 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
module.exports = { | ||
readFile: jest.fn((filePath, encoding, callback) => { | ||
callback(null, `console.log('this is a mock thing for file: ${filePath}')`) | ||
}), | ||
writeFile: jest.fn((filePath, contents, callback) => { | ||
callback(null) | ||
}), | ||
} | ||
module.exports = {readFile: jest.fn((filePath, encoding, callback) => { | ||
callback(null, `console.log('this is a mock thing for file: ${filePath}')`) | ||
}), writeFile: jest.fn((filePath, contents, callback) => { | ||
callback(null) | ||
})} |
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
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,43 @@ | ||
/*eslint import/namespace: [2, { allowComputed: true }]*/ | ||
import * as messages from './messages' | ||
|
||
const tests = { | ||
success: [ | ||
{ | ||
input: {success: 'success', count: 1, countString: '1String'}, | ||
output: 'success formatting 1String file with prettier-eslint', | ||
}, | ||
{ | ||
input: {success: 'success', count: 3, countString: '3String'}, | ||
output: 'success formatting 3String files with prettier-eslint', | ||
}, | ||
], | ||
failure: [ | ||
{ | ||
input: {failure: 'failure', count: 1, countString: '1String'}, | ||
output: 'failure formatting 1String file with prettier-eslint', | ||
}, | ||
{ | ||
input: {failure: 'failure', count: 3, countString: '3String'}, | ||
output: 'failure formatting 3String files with prettier-eslint', | ||
}, | ||
], | ||
unchanged: [ | ||
{ | ||
input: {unchanged: 'unchanged', count: 1, countString: '1String'}, | ||
output: '1String file was unchanged', | ||
}, | ||
{ | ||
input: {unchanged: 'unchanged', count: 3, countString: '3String'}, | ||
output: '3String files were unchanged', | ||
}, | ||
], | ||
} | ||
|
||
Object.keys(tests).forEach(messageKey => { | ||
tests[messageKey].forEach(({input, output}) => { | ||
test(`${messageKey} ${JSON.stringify(input)}`, () => { | ||
expect(messages[messageKey](input)).toEqual(output) | ||
}) | ||
}) | ||
}) |
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,24 @@ | ||
import MessageFormat from 'messageformat' | ||
|
||
const mf = new MessageFormat('en') | ||
|
||
export {success, failure, unchanged} | ||
|
||
function success(data) { | ||
const files = `{count, plural, one{file} other{files}}` | ||
return mf.compile( | ||
`{success} formatting {countString} ${files} with prettier-eslint`, | ||
)(data) | ||
} | ||
|
||
function failure(data) { | ||
const files = `{count, plural, one{file} other{files}}` | ||
return mf.compile( | ||
`{failure} formatting {countString} ${files} with prettier-eslint`, | ||
)(data) | ||
} | ||
|
||
function unchanged(data) { | ||
const files = `{count, plural, one{file was} other{files were}}` | ||
return mf.compile(`{countString} ${files} {unchanged}`)(data) | ||
} |
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