Skip to content

Commit

Permalink
chore: improve variable naming of system module (#3315)
Browse files Browse the repository at this point in the history
* chore: improve variable naming of system module

* chore: rename variables in tests
  • Loading branch information
ST-DDT authored Dec 4, 2024
1 parent 1bfa1fa commit 2ba5edb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions src/modules/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,32 @@ export class SystemModule extends ModuleBase {
.toLowerCase()
.replaceAll(/\W/g, '_');

const extensionsStr = this.faker.helpers
const extensionsSuffix = this.faker.helpers
.multiple(() => this.fileExt(), { count: extensionCount })
.join('.');

if (extensionsStr.length === 0) {
if (extensionsSuffix.length === 0) {
return baseName;
}

return `${baseName}.${extensionsStr}`;
return `${baseName}.${extensionsSuffix}`;
}

/**
* Returns a random file name with a given extension or a commonly used extension.
*
* @param ext Extension. Empty string is considered to be not set.
* @param extension The file extension to use. Empty string is considered to be not set.
*
* @example
* faker.system.commonFileName() // 'dollar.jpg'
* faker.system.commonFileName('txt') // 'global_borders_wyoming.txt'
*
* @since 3.1.0
*/
commonFileName(ext?: string): string {
const str = this.fileName({ extensionCount: 0 });
commonFileName(extension?: string): string {
const fileName = this.fileName({ extensionCount: 0 });

return `${str}.${ext || this.commonFileExt()}`;
return `${fileName}.${extension || this.commonFileExt()}`;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions test/modules/system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ describe('system', () => {
() => {
describe('commonFileExt()', () => {
it('should return common file types', () => {
const fileExt = faker.system.commonFileExt();
const extList = [
const actual = faker.system.commonFileExt();
const extensions = [
'gif',
'htm',
'html',
Expand Down Expand Up @@ -96,11 +96,11 @@ describe('system', () => {
];

expect(
extList,
`generated common file ext should be one of [${extList.join(
extensions,
`generated common file ext should be one of [${extensions.join(
', '
)}]. Got "${fileExt}".`
).include(fileExt);
)}]. Got "${actual}".`
).include(actual);
});
});

Expand Down Expand Up @@ -164,15 +164,15 @@ describe('system', () => {

describe('fileExt()', () => {
it('should return file ext', () => {
const fileExt = faker.system.fileExt();
const actual = faker.system.fileExt();

expect(fileExt).toBeTypeOf('string');
expect(fileExt).not.toBe('');
expect(actual).toBeTypeOf('string');
expect(actual).not.toBe('');
});

it('should return file ext based on mimeType', () => {
const fileExt = faker.system.fileExt('text/plain');
const extList = [
const actual = faker.system.fileExt('text/plain');
const extensions = [
'txt',
'text',
'conf',
Expand All @@ -184,11 +184,11 @@ describe('system', () => {
];

expect(
extList,
`generated common file ext should be one of [${extList.join(
extensions,
`generated common file ext should be one of [${extensions.join(
','
)}]. Got "${fileExt}".`
).include(fileExt);
)}]. Got "${actual}".`
).include(actual);
});
});

Expand Down

0 comments on commit 2ba5edb

Please sign in to comment.