Skip to content

fix: change random.word to be based on definitions.word.* #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
44 changes: 7 additions & 37 deletions src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,46 +249,16 @@ export class Random {
* @example
* faker.random.word() // 'Seamless'
*/
// TODO: have ability to return specific type of word? As in: noun, adjective, verb, etc
word(): string {
const wordMethods = [
'commerce.department',
'commerce.productName',
'commerce.productAdjective',
'commerce.productMaterial',
'commerce.product',
'commerce.color',

'company.catchPhraseAdjective',
'company.catchPhraseDescriptor',
'company.catchPhraseNoun',
'company.bsAdjective',
'company.bsBuzz',
'company.bsNoun',
'address.streetSuffix',
'address.county',
'address.country',
'address.state',

'finance.accountName',
'finance.transactionType',
'finance.currencyName',

'hacker.noun',
'hacker.verb',
'hacker.adjective',
'hacker.ingverb',
'hacker.abbreviation',

'name.jobDescriptor',
'name.jobArea',
'name.jobType',
const generators = [
this.faker.word.adjective,
this.faker.word.adverb,
this.faker.word.noun,
this.faker.word.preposition,
this.faker.word.verb,
];

// randomly pick from the many faker methods that can generate words
const randomWordMethod = this.faker.random.arrayElement(wordMethods);
const result = this.faker.fake('{{' + randomWordMethod + '}}');
return this.faker.random.arrayElement(result.split(' '));
return this.faker.random.arrayElement(generators)();
}

/**
Expand Down
21 changes: 12 additions & 9 deletions test/system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,48 @@ const seededRuns = [
{
seed: 42,
expectations: {
fileName: 'mobile_application.wad',
commonFileName: 'mobile_application.gif',
fileName: 'via_sheepishly.gif',
commonFileName: 'via_sheepishly.mpe',
mimeType: 'application/vnd.marlin.drm.license+xml',
commonFileType: 'audio',
commonFileExt: 'png',
fileType: 'image',
fileExt: 'chm',
directoryPath: '/opt/bin',
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
filePath: '/opt/bin/directives_multi_byte_table.p10.m21',
filePath: '/opt/bin/correspond_save_noir.atc.paw',
semver: '3.7.9',
},
},
{
seed: 1337,
expectations: {
fileName: 'delaware.vcg',
commonFileName: 'delaware.wav',
fileName: 'huzzah.uvvt',
commonFileName: 'huzzah.mp2',
mimeType: 'application/vnd.dxr',
commonFileType: 'audio',
commonFileExt: 'wav',
fileType: 'font',
fileExt: 'gxt',
directoryPath: '/Library',
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
filePath: '/Library/bike_kiribati.kpr.ez3',
filePath: '/Library/eventually_officially.qwt.ser',
semver: '2.5.1',
},
},
{
seed: 1211,
expectations: {
fileName: 'turnpike_cross_platform_handcrafted.mka',
commonFileName: 'turnpike_cross_platform_handcrafted.mp4v',
fileName: 'pish_astride_zany.json5',
commonFileName: 'pish_astride_zany.pdf',
mimeType: 'text/vnd.fmi.flexstor',
commonFileType: 'application',
commonFileExt: 'htm',
fileType: 'x-shader',
fileExt: 'opml',
directoryPath: '/var/log',
// TODO @prisis 2022-01-25: add a parameter to have the possibility to have one or two ext on file.
filePath: '/var/log/forward_frozen.swf.fcdt',
filePath: '/var/log/search_coolly.movie.json5',
semver: '9.4.8',
},
},
Expand Down Expand Up @@ -107,9 +107,12 @@ describe('system', () => {
'mp4v',
'mpeg',
'htm',
'html',
'm2a',
'mp4',
'mpg',
'mpg4',
'shtml',
];

expect(
Expand Down