-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(i18nTagSchema): optimized test coverage
- Loading branch information
Showing
9 changed files
with
400 additions
and
243 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,2 +1,3 @@ | ||
cli | ||
__tests__/samples | ||
__tests__/samples | ||
dist |
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,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() | ||
} | ||
}) | ||
|
||
}) | ||
|
||
}) |
Oops, something went wrong.