This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add script to extract faker.js locales
- add and split tests - update faker.js to latest version, make setSeed null safe Closes #8
- Loading branch information
Guillaume
committed
May 7, 2021
1 parent
c5d081a
commit 8047d1f
Showing
7 changed files
with
435 additions
and
342 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
const fakerLocales = require('../node_modules/faker/lib/locales.js'); | ||
|
||
/** | ||
* Extract locales list from Faker.js to be used in the commons librairy and main app | ||
*/ | ||
const localesList = Object.keys(fakerLocales); | ||
const locales = []; | ||
|
||
localesList.forEach((locale) => { | ||
locales.push({ | ||
code: locale, | ||
label: fakerLocales[locale].title | ||
}); | ||
}); | ||
|
||
console.log(localesList); | ||
console.log(locales.sort((a, b) => (a.label < b.label ? -1 : 1))); |
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,70 @@ | ||
import { expect } from 'chai'; | ||
import faker from 'faker'; | ||
import { TemplateParser } from '../../src/libs/template-parser'; | ||
|
||
faker.seed(1); | ||
|
||
describe('Template parser: Faker wrapper', () => { | ||
it('should return value for simple helper', () => { | ||
const parseResult = TemplateParser( | ||
"{{faker 'name.firstName'}}", | ||
{} as any, | ||
{} as any | ||
); | ||
expect(parseResult).to.be.equal('Hayden'); | ||
}); | ||
|
||
it('should return value for helper with named parameters', () => { | ||
const parseResult = TemplateParser( | ||
"{{faker 'random.number' min=10 max=20}}", | ||
{} as any, | ||
{} as any | ||
); | ||
expect(parseResult).to.be.equal('20'); | ||
}); | ||
|
||
it('should return value for helper with arguments', () => { | ||
const parseResult = TemplateParser( | ||
"{{faker 'random.alphaNumeric' 1}}", | ||
{} as any, | ||
{} as any | ||
); | ||
expect(parseResult).to.be.equal('p'); | ||
}); | ||
|
||
it('should throw if helper name is missing', () => { | ||
expect(() => { | ||
TemplateParser('{{faker}}', {} as any, {} as any); | ||
}).to.throw( | ||
'Faker method name is missing (valid: "address.zipCode", "date.past", etc) line 1' | ||
); | ||
}); | ||
|
||
it('should throw if helper name is malformed', () => { | ||
expect(() => { | ||
TemplateParser("{{faker 'random'}}", {} as any, {} as any); | ||
}).to.throw( | ||
'random is not a valid Faker method (valid: "address.zipCode", "date.past", etc) line 1' | ||
); | ||
}); | ||
|
||
it('should throw if helper name is malformed', () => { | ||
expect(() => { | ||
TemplateParser("{{faker 'random.'}}", {} as any, {} as any); | ||
}).to.throw( | ||
'random. is not a valid Faker method (valid: "address.zipCode", "date.past", etc) line 1' | ||
); | ||
}); | ||
|
||
it('should throw if helper name does not exists', () => { | ||
expect(() => { | ||
TemplateParser( | ||
"{{faker 'donotexists.donotexists'}}", | ||
{} as any, | ||
{} as any | ||
); | ||
}).to.throw( | ||
'donotexists.donotexists is not a valid Faker method (valid: "address.zipCode", "date.past", etc) line 1' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.