Skip to content

Commit

Permalink
test(i18nTagSchema): optimized test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skolmer committed Nov 1, 2016
1 parent a21658c commit e9b98f6
Show file tree
Hide file tree
Showing 9 changed files with 400 additions and 243 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cli
__tests__/samples
__tests__/samples
dist
243 changes: 130 additions & 113 deletions __tests__/exportTranslationKeys.test.js
Original file line number Diff line number Diff line change
@@ -1,125 +1,142 @@
import path from 'path'
import { exportTranslationKeys } from '../lib'
import silentLogger from './samples/silentLogger'

global.console = silentLogger

describe('exportTranslationKeys', () => {
it('should fail if rootPath param is missing', (done) => {
const filePath = './samples/grouped.js'
exportTranslationKeys({
filePath,
logger: { toConsole: true },
callback: (status, templates) => {
expect(status).toEqual(1)
expect(templates).toEqual('rootPath is not defined.')
done()
}
})
it('should fail if rootPath param is missing', (done) => {
const filePath = './samples/grouped.js'
exportTranslationKeys({
filePath,
logger: { toConsole: true },
callback: (status, templates) => {
expect(status).toEqual(1)
expect(templates).toEqual('rootPath is not defined.')
done()
}
})
})

it('should export all templates from a directory', (done) => {
const rootPath = path.resolve(__dirname, './samples')
exportTranslationKeys({
rootPath,
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',
{
'group': 'custom group',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom group 2',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom inline group',
'items': [
'Hello!',
'Welcome!'
]
},
{
'group': 'grouped.js',
'items': [
'Hello ${0}, you have ${1} in your bank account.',
'Hello!'
]
}
])
done()
}
})
})

it('should export all templates from a directory', (done) => {
const rootPath = path.resolve(__dirname, './samples')
exportTranslationKeys({
rootPath,
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',
{
'group': 'custom group',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom group 2',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom inline group',
'items': [
'Hello!',
'Welcome!'
]
},
{
'group': 'grouped.js',
'items': [
'Hello ${0}, you have ${1} in your bank account.',
'Hello!'
]
}
])
done()
}
})
it('should export grouped templates as array', (done) => {
const rootPath = path.resolve(__dirname, './samples')
const filePath = path.resolve(__dirname, './samples/grouped.js')
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',
{
'group': 'custom group',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom group 2',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom inline group',
'items': [
'Hello!',
'Welcome!'
]
},
{
'group': 'grouped.js',
'items': [
'Hello ${0}, you have ${1} in your bank account.',
'Hello!'
]
}
])
done()
}
})
})

it('should export grouped templates as array', (done) => {
const rootPath = path.resolve(__dirname, './samples')
const filePath = path.resolve(__dirname, './samples/grouped.js')
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',
{
'group': 'custom group',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom group 2',
'items': [
'Hello ${0}, you have ${1} in your bank account.'
]
},
{
'group': 'custom inline group',
'items': [
'Hello!',
'Welcome!'
]
},
{
'group': 'grouped.js',
'items': [
'Hello ${0}, you have ${1} in your bank account.',
'Hello!'
]
}
])
done()
}
})
it('should export multiline templates as array', (done) => {
const rootPath = path.resolve(__dirname, './samples')
const filePath = path.resolve(__dirname, './samples/multiline.js')
exportTranslationKeys({
rootPath,
filePath,
callback: (status, templates) => {
expect(status).toEqual(0)
expect(templates).toEqual([
'\n <user name="${0}">${1}</user>\n ',
'\n <users>\n ${0}\n </users>\n',
{
'group': 'custom inline group',
'items': ['Hello!']
}
])
done()
}
})
})

it('should export multiline templates as array', (done) => {
const rootPath = path.resolve(__dirname, './samples')
const filePath = path.resolve(__dirname, './samples/multiline.js')
exportTranslationKeys({
rootPath,
filePath,
callback: (status, templates) => {
expect(status).toEqual(0)
expect(templates).toEqual([
'\n <user name="${0}">${1}</user>\n ',
'\n <users>\n ${0}\n </users>\n',
{
'group': 'custom inline group',
'items': ['Hello!']
}
])
done()
}
})
it('should fail if file does not exist', (done) => {
const rootPath = path.resolve(__dirname, './samples')
const filePath = path.resolve(__dirname, './samples/unknown.js')
exportTranslationKeys({
rootPath,
filePath,
callback: (status, templates) => {
expect(status).toEqual(1)
expect(templates).toEqual(`ENOENT: no such file or directory, lstat '${filePath}'`)
done()
}
})

})

})

0 comments on commit e9b98f6

Please sign in to comment.