Skip to content

Commit

Permalink
refactor(i18nTagSchema): Optimized logging and function parameters
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Added new options parameter to i18nTagSchema, exportTranslationKeys and

validateSchema
  • Loading branch information
skolmer committed Oct 31, 2016
1 parent 72a5ad9 commit 54a36ec
Show file tree
Hide file tree
Showing 3 changed files with 359 additions and 134 deletions.
73 changes: 43 additions & 30 deletions __tests__/i18n-tag-schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,38 +95,45 @@ describe('i18n-tag-schema', () => {
it('should match json string', (done) => {
const filter = '\\.jsx?$'
const srcPath = path.resolve(__dirname, './samples')
i18nTagSchema(srcPath, filter, null, (message, type) => {
switch (type) {
case 'success':
expect(JSON.parse(message)).toEqual(expected)
done()
break
}
i18nTagSchema({
srcPath,
filter,
callback: (status, result) => {
expect(status).toEqual(0)
expect(result).toEqual(expected)
done()
}
})
})

it('should match json file', (done) => {
const filter = '\\.jsx?$'
const srcPath = path.resolve(__dirname, './samples')
const schema = path.resolve(__dirname, './samples/schema.json')
i18nTagSchema(srcPath, filter, schema, (message, type) => {
const prevJson = fs.readFileSync(schema, 'utf-8')
switch (type) {
case 'success':
expect(JSON.parse(prevJson)).toEqual(expected)
done()
break
}
const schemaPath = path.resolve(__dirname, './samples/schema.json')
i18nTagSchema({
srcPath,
schemaPath,
filter,
callback: (status) => {
expect(status).toEqual(0)
const json = fs.readFileSync(schemaPath, 'utf-8')
expect(JSON.parse(json)).toEqual(expected)
done()
}
})
})

it('should export templates as array', (done) => {
const srcPath = path.resolve(__dirname, './samples')
const rootPath = path.resolve(__dirname, './samples')
const filePath = path.resolve(__dirname, './samples/grouped.js')
const filePath2 = path.resolve(__dirname, './samples/multiline.js')
exportTranslationKeys(srcPath, filePath, undefined,
(templates) => {
expect(JSON.parse(templates)).toEqual([
exportTranslationKeys({
rootPath,
filePath,
logger: { toConsole: true },
callback: (status, templates) => {
expect(status).toEqual(0)
expect(templates).toEqual([
'\n <user name="${0}">${1}</user>\n ',
'\n <users>\n ${0}\n </users>\n',
{
Expand Down Expand Up @@ -156,9 +163,12 @@ describe('i18n-tag-schema', () => {
]
}
])
exportTranslationKeys(srcPath, filePath2, undefined,
(templates) => {
expect(JSON.parse(templates)).toEqual([
exportTranslationKeys({
rootPath,
filePath: filePath2,
callback: (status, templates) => {
expect(status).toEqual(0)
expect(templates).toEqual([
'\n <user name="${0}">${1}</user>\n ',
'\n <users>\n ${0}\n </users>\n',
{
Expand All @@ -168,19 +178,22 @@ describe('i18n-tag-schema', () => {
])
done()
}
)
})
}
)
})
})

it('should validate translations', (done) => {
const schemaPath = path.resolve(__dirname, './samples/schema.json')
const translationPath = path.resolve(__dirname, './samples/translation.json')
validateSchema(translationPath, schemaPath, (message, type) => {
if (type === 'success' || type === 'error') {
expect(message).toEqual('translation.json has 3 missing translations; 63% translated.')
done()
}
validateSchema({
rootPath: translationPath,
schemaPath,
callback: (status, result) => {
expect(status).toEqual(1)
expect(result).toEqual('translation.json has 3 missing translations; 63% translated.')
done()
}
})
})
})
Expand Down
Loading

0 comments on commit 54a36ec

Please sign in to comment.