From 1ab33c5caf323d25bd21b3b3afaf8af3686207b4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 20:40:52 +0200 Subject: [PATCH 1/2] chore(deps): update pnpm/action-setup action to v2.2.3 (#1433) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 12 ++++++------ .github/workflows/pr.yml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 909d861d87e..b1af3f9032e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: uses: actions/checkout@v3 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 @@ -62,7 +62,7 @@ jobs: uses: actions/checkout@v3 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 @@ -90,7 +90,7 @@ jobs: fetch-depth: 0 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 @@ -121,7 +121,7 @@ jobs: fetch-depth: 0 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 @@ -149,7 +149,7 @@ jobs: fetch-depth: 0 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 @@ -177,7 +177,7 @@ jobs: fetch-depth: 0 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a4e52d9b933..db65a938861 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -19,7 +19,7 @@ jobs: fetch-depth: 0 - name: Install pnpm - uses: pnpm/action-setup@v2.2.2 + uses: pnpm/action-setup@v2.2.3 with: version: 7 From 9c1437d6034ef5537c079746761c4c71347f768b Mon Sep 17 00:00:00 2001 From: Shinigami Date: Sat, 15 Oct 2022 03:29:21 +0800 Subject: [PATCH 2/2] refactor!: cleanup deprecations (#1440) --- docs/.vitepress/api-pages.ts | 3 - scripts/apidoc.ts | 2 - scripts/apidoc/apiDocsWriter.ts | 35 +---- scripts/apidoc/directMethods.ts | 68 --------- src/faker.ts | 7 +- src/index.ts | 7 +- src/modules/address/index.ts | 132 +---------------- src/modules/commerce/index.ts | 24 --- src/modules/company/index.ts | 46 +----- src/modules/datatype/index.ts | 21 +-- src/modules/fake/index.ts | 75 ---------- src/modules/helpers/index.ts | 26 ---- src/modules/image/providers/lorempicsum.ts | 22 --- src/modules/image/providers/lorempixel.ts | 22 --- src/modules/image/providers/unsplash.ts | 36 ----- src/modules/mersenne/index.ts | 2 +- src/modules/name/index.ts | 77 +--------- src/modules/phone/index.ts | 83 ----------- src/modules/random/index.ts | 26 +--- src/modules/unique/index.ts | 72 --------- test/__snapshots__/address.spec.ts.snap | 42 +----- test/__snapshots__/commerce.spec.ts.snap | 6 - test/__snapshots__/company.spec.ts.snap | 24 +-- test/__snapshots__/helpers.spec.ts.snap | 18 --- test/__snapshots__/name.spec.ts.snap | 84 +++-------- test/__snapshots__/phone.spec.ts.snap | 54 ------- test/__snapshots__/random.spec.ts.snap | 12 +- test/address.spec.ts | 9 +- test/commerce.spec.ts | 8 - test/company.spec.ts | 66 +-------- test/fake.spec.ts | 123 ---------------- test/helpers.spec.ts | 24 +-- test/image.spec.ts | 24 --- test/name.spec.ts | 139 +++--------------- test/phone.spec.ts | 49 +----- test/random.spec.ts | 17 ++- .../apidoc/examplesAndDeprecations.spec.ts | 5 +- test/unique.spec.ts | 125 ---------------- 38 files changed, 98 insertions(+), 1517 deletions(-) delete mode 100644 scripts/apidoc/directMethods.ts delete mode 100644 src/modules/fake/index.ts delete mode 100644 src/modules/unique/index.ts delete mode 100644 test/fake.spec.ts delete mode 100644 test/unique.spec.ts diff --git a/docs/.vitepress/api-pages.ts b/docs/.vitepress/api-pages.ts index 4c507f62185..230eb2fdd28 100644 --- a/docs/.vitepress/api-pages.ts +++ b/docs/.vitepress/api-pages.ts @@ -10,7 +10,6 @@ export const apiPages = [ { text: 'Database', link: '/api/database.html' }, { text: 'Datatype', link: '/api/datatype.html' }, { text: 'Date', link: '/api/date.html' }, - { text: 'Fake', link: '/api/fake.html' }, { text: 'Finance', link: '/api/finance.html' }, { text: 'Git', link: '/api/git.html' }, { text: 'Hacker', link: '/api/hacker.html' }, @@ -18,14 +17,12 @@ export const apiPages = [ { text: 'Image', link: '/api/image.html' }, { text: 'Internet', link: '/api/internet.html' }, { text: 'Lorem', link: '/api/lorem.html' }, - { text: 'Mersenne', link: '/api/mersenne.html' }, { text: 'Music', link: '/api/music.html' }, { text: 'Name', link: '/api/name.html' }, { text: 'Phone', link: '/api/phone.html' }, { text: 'Random', link: '/api/random.html' }, { text: 'Science', link: '/api/science.html' }, { text: 'System', link: '/api/system.html' }, - { text: 'Unique', link: '/api/unique.html' }, { text: 'Vehicle', link: '/api/vehicle.html' }, { text: 'Word', link: '/api/word.html' }, ]; diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts index 0ad01248542..921859e7a77 100644 --- a/scripts/apidoc.ts +++ b/scripts/apidoc.ts @@ -3,7 +3,6 @@ import { writeApiPagesIndex, writeApiSearchIndex, } from './apidoc/apiDocsWriter'; -import { processDirectMethods } from './apidoc/directMethods'; import { processModuleMethods } from './apidoc/moduleMethods'; import { initMarkdownRenderer } from './apidoc/signature'; import type { PageIndex } from './apidoc/utils'; @@ -35,7 +34,6 @@ async function build(): Promise { const modulesPages: PageIndex = []; modulesPages.push(...processModuleMethods(project)); - modulesPages.push(...processDirectMethods(project)); writeApiPagesIndex(modulesPages); writeApiSearchIndex(project); diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts index 74caa4251ca..1f0709bb170 100644 --- a/scripts/apidoc/apiDocsWriter.ts +++ b/scripts/apidoc/apiDocsWriter.ts @@ -4,7 +4,6 @@ import type { ProjectReflection } from 'typedoc'; import { ReflectionKind } from 'typedoc'; import type { Method } from '../../docs/.vitepress/components/api-docs/method'; import type { APIGroup, APIItem } from '../../docs/api/api-types'; -import { selectDirectMethods } from './directMethods'; import { extractModuleName, selectApiModules } from './moduleMethods'; import type { PageIndex } from './utils'; import { @@ -78,37 +77,6 @@ export function writeApiDocsModulePage( writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.md`), content); } -/** - * Writes the api page for the given method to the correct location. - * - * @param methodName The name of the method to write the docs for. - * @param capitalizedMethodName The capitalized name of the method. - */ -export function writeApiDocsDirectPage( - methodName: string, - capitalizedMethodName: string -): void { - let content = ` - - - - - - # ${capitalizedMethodName} - - ## ${methodName} - - - `.replace(/\n +/g, '\n'); - - content = vitePressInFileOptions + formatMarkdown(content); - - writeFileSync(resolve(pathOutputDir, `${methodName}.md`), content); -} - /** * Writes the api docs data to correct location. * @@ -164,9 +132,8 @@ export function writeApiSearchIndex(project: ProjectReflection): void { apiIndex.push(moduleApiSection); const apiModules = selectApiModules(project); - const directMethods = selectDirectMethods(project); - moduleApiSection.items = [...apiModules, ...directMethods] + moduleApiSection.items = apiModules .map((module) => { const moduleName = extractModuleName(module); const apiSection: APIItem = { diff --git a/scripts/apidoc/directMethods.ts b/scripts/apidoc/directMethods.ts deleted file mode 100644 index f8268f5c5d7..00000000000 --- a/scripts/apidoc/directMethods.ts +++ /dev/null @@ -1,68 +0,0 @@ -import type { - DeclarationReflection, - ProjectReflection, - ReflectionType, -} from 'typedoc'; -import { ReflectionKind } from 'typedoc'; -import { writeApiDocsData, writeApiDocsDirectPage } from './apiDocsWriter'; -import { analyzeSignature } from './signature'; -import type { Page, PageIndex } from './utils'; - -/** - * Selects the direct methods from the project that needs to be documented. - * - * @param project The project used to extract the direct methods. - * @returns The direct methods to document. - */ -export function selectDirectMethods( - project: ProjectReflection -): DeclarationReflection[] { - return project - .getChildrenByKind(ReflectionKind.Class) - .filter((ref) => ref.name === 'Faker')[0] - .getChildrenByKind(ReflectionKind.Property) - .filter((ref) => ['fake', 'unique'].includes(ref.name)); -} - -/** - * Analyzes and writes the documentation for direct methods such as `faker.fake()`. - * - * @param project The project used to extract the direct methods. - * @returns The generated pages. - */ -export function processDirectMethods(project: ProjectReflection): PageIndex { - const pages: PageIndex = []; - - // Generate direct method files - for (const direct of selectDirectMethods(project)) { - pages.push(processDirectMethod(direct)); - } - - return pages; -} - -/** - * Analyzes and writes the documentation for a direct method such as `faker.fake()`. - * - * @param direct The direct method to process. - * @returns The generated pages. - */ -export function processDirectMethod(direct: DeclarationReflection): Page { - const methodName = direct.name; - const capitalizedMethodName = - methodName.substring(0, 1).toUpperCase() + methodName.substring(1); - console.log(`Processing Direct: ${capitalizedMethodName}`); - - const signatures = (direct.type as ReflectionType).declaration.signatures; - const signature = signatures[signatures.length - 1]; - - writeApiDocsDirectPage(methodName, capitalizedMethodName); - writeApiDocsData(methodName, [ - analyzeSignature(signature, undefined, methodName), - ]); - - return { - text: capitalizedMethodName, - link: `/api/${methodName}.html`, - }; -} diff --git a/src/faker.ts b/src/faker.ts index bf4a0d62a06..c42c313e787 100644 --- a/src/faker.ts +++ b/src/faker.ts @@ -9,7 +9,6 @@ import { CompanyModule } from './modules/company'; import { DatabaseModule } from './modules/database'; import { DatatypeModule } from './modules/datatype'; import { DateModule } from './modules/date'; -import { FakeModule } from './modules/fake'; import { FinanceModule } from './modules/finance'; import { GitModule } from './modules/git'; import { HackerModule } from './modules/hacker'; @@ -24,7 +23,6 @@ import { PhoneModule } from './modules/phone'; import { RandomModule } from './modules/random'; import { ScienceModule } from './modules/science'; import { SystemModule } from './modules/system'; -import { UniqueModule } from './modules/unique'; import { VehicleModule } from './modules/vehicle'; import { WordModule } from './modules/word'; import type { LiteralUnion } from './utils/types'; @@ -76,11 +74,8 @@ export class Faker { readonly definitions: LocaleDefinition = this.initDefinitions(); - readonly fake: FakeModule['fake'] = new FakeModule(this).fake; - readonly unique: UniqueModule['unique'] = new UniqueModule(this).unique; - /** - * @deprecated Internal. Use faker.datatype.number() or faker.seed() instead. + * @internal */ readonly mersenne: MersenneModule = new MersenneModule(); readonly random: RandomModule = new RandomModule(this); diff --git a/src/index.ts b/src/index.ts index 984a8c758d5..0a0eaef1f65 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,7 +45,6 @@ export type { CompanyModule } from './modules/company'; export type { DatabaseModule } from './modules/database'; export type { DatatypeModule } from './modules/datatype'; export type { DateModule } from './modules/date'; -export type { FakeModule } from './modules/fake'; export type { FinanceModule } from './modules/finance'; export type { GitModule } from './modules/git'; export type { HackerModule } from './modules/hacker'; @@ -53,15 +52,13 @@ export type { HelpersModule } from './modules/helpers'; export type { ImageModule } from './modules/image'; export type { InternetModule } from './modules/internet'; export type { LoremModule } from './modules/lorem'; -export type { MersenneModule } from './modules/mersenne'; export type { MusicModule } from './modules/music'; -export { Gender, Sex } from './modules/name'; -export type { GenderType, NameModule, SexType } from './modules/name'; +export { Sex } from './modules/name'; +export type { NameModule, SexType } from './modules/name'; export type { PhoneModule } from './modules/phone'; export type { RandomModule } from './modules/random'; export type { ChemicalElement, ScienceModule, Unit } from './modules/science'; export type { SystemModule } from './modules/system'; -export type { UniqueModule } from './modules/unique'; export type { VehicleModule } from './modules/vehicle'; export type { WordModule } from './modules/word'; export { Faker }; diff --git a/src/modules/address/index.ts b/src/modules/address/index.ts index 695d8249169..f0ad8644168 100644 --- a/src/modules/address/index.ts +++ b/src/modules/address/index.ts @@ -1,5 +1,4 @@ import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; /** * Module to generate addresses and locations. @@ -69,80 +68,16 @@ export class AddressModule { /** * Generates a random localized city name. * - * @param format The index of the format to use. Deprecated do not use. - * * @example * faker.address.city() // 'East Jarretmouth' * * @since 2.0.1 */ - city(format?: string | number): string { - if (format != null) { - deprecated({ - deprecated: 'faker.address.city(format)', - proposed: 'faker.address.city() or faker.helpers.fake(format)', - since: '7.0', - until: '8.0', - }); - } - const formats = this.faker.definitions.address.city; - - if (typeof format !== 'number') { - format = this.faker.datatype.number(formats.length - 1); - } - - return this.faker.helpers.fake(formats[format]); - } - - /** - * Returns a random localized city prefix. - * - * @see faker.address.city() - * - * @example - * faker.address.cityPrefix() // 'East' - * - * @since 2.0.1 - * - * @deprecated - * Use `faker.address.city()` instead. - */ - cityPrefix(): string { - deprecated({ - deprecated: 'faker.address.cityPrefix()', - proposed: "faker.address.city() or faker.fake('{{address.city_prefix}}')", - since: '7.2', - until: '8.0', - }); - return this.faker.helpers.arrayElement( - this.faker.definitions.address.city_prefix - ); - } - - /** - * Returns a random localized city suffix. - * - * @see faker.address.city() - * - * @example - * faker.address.citySuffix() // 'mouth' - * - * @since 2.0.1 - * - * @deprecated - * Use `faker.address.city()` instead. - */ - citySuffix(): string { - deprecated({ - deprecated: 'faker.address.citySuffix()', - proposed: - "faker.address.city() or faker.helpers.fake('{{address.city_suffix}}')", - since: '7.2', - until: '8.0', - }); - return this.faker.helpers.arrayElement( - this.faker.definitions.address.city_suffix + city(): string { + const pattern = this.faker.helpers.arrayElement( + this.faker.definitions.address.city ); + return this.faker.helpers.fake(pattern); } /** @@ -199,17 +134,6 @@ export class AddressModule { * @since 2.0.1 */ streetName(): string { - if (this.faker.definitions.address.street_name == null) { - deprecated({ - deprecated: - 'faker.address.streetName() without address.street_name definitions', - proposed: - 'faker.address.street() or provide address.street_name definitions', - since: '7.0', - until: '8.0', - }); - return this.street(); - } return this.faker.helpers.arrayElement( this.faker.definitions.address.street_name ); @@ -235,54 +159,6 @@ export class AddressModule { return this.faker.helpers.fake(format); } - /** - * Returns a random localized street suffix. - * - * @see faker.address.street() - * - * @example - * faker.address.streetSuffix() // 'Streets' - * - * @since 2.0.1 - * - * @deprecated Use faker.address.street() instead. - */ - streetSuffix(): string { - deprecated({ - deprecated: 'faker.address.streetSuffix()', - proposed: 'faker.address.street()', - since: '7.4', - until: '8.0', - }); - return this.faker.helpers.arrayElement( - this.faker.definitions.address.street_suffix - ); - } - - /** - * Returns a random localized street prefix. - * - * @see faker.address.street() - * - * @example - * fakerGH.address.streetPrefix() // 'Boame' - * - * @since 3.0.0 - * - * @deprecated Use faker.address.street() instead. - */ - streetPrefix(): string { - deprecated({ - deprecated: 'faker.address.streetPrefix()', - proposed: 'faker.address.street()', - since: '7.4', - until: '8.0', - }); - return this.faker.helpers.arrayElement( - this.faker.definitions.address.street_prefix - ); - } - /** * Generates a random localized secondary address. This refers to a specific location at a given address * such as an apartment or room number. diff --git a/src/modules/commerce/index.ts b/src/modules/commerce/index.ts index 11ed8d7bd03..088112c1577 100644 --- a/src/modules/commerce/index.ts +++ b/src/modules/commerce/index.ts @@ -1,5 +1,4 @@ import type { Faker } from '../../faker'; -import { deprecated } from '../../internal/deprecated'; /** * Module to generate commerce and product related entries. @@ -15,29 +14,6 @@ export class CommerceModule { } } - /** - * Returns a human readable color name. - * - * @see faker.color.human() - * - * @example - * faker.commerce.color() // 'red' - * - * @since 3.0.0 - * - * @deprecated - * Use `faker.color.human()` instead. - */ - color(): string { - deprecated({ - deprecated: 'faker.commerce.color()', - proposed: 'faker.color.human()', - since: '7.0', - until: '8.0', - }); - return this.faker.color.human(); - } - /** * Returns a department inside a shop. * diff --git a/src/modules/company/index.ts b/src/modules/company/index.ts index 2b17a6ed419..73b059b4928 100644 --- a/src/modules/company/index.ts +++ b/src/modules/company/index.ts @@ -1,5 +1,4 @@ import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; /** * Module to generate company related entries. @@ -31,23 +30,12 @@ export class CompanyModule { /** * Generates a random company name. * - * @param format The optional format index used to select a format. Deprecated, do not use. - * * @example * faker.company.name() // 'Zieme, Hauck and McClure' * * @since 7.4.0 */ - name(format?: number): string { - if (format != null) { - deprecated({ - deprecated: 'faker.company.name(format)', - proposed: 'faker.company.name() or faker.helpers.fake(format)', - since: '7.4', - until: '8.0', - }); - } - + name(): string { // ToDo: This `staticFormats` pattern should be removed in the future. It is only used to maintain backwards compatibility. const staticFormats = [ '{{name.lastName}} {{company.companySuffix}}', @@ -57,36 +45,8 @@ export class CompanyModule { const formats = this.faker.definitions.company.name_patterns ?? staticFormats; - if (typeof format !== 'number') { - format = this.faker.datatype.number(formats.length - 1); - } - - return this.faker.helpers.fake(formats[format]); - } - - /** - * Generates a random company name. - * - * @param format The optional format index used to select a format. - * - * @see faker.company.name() - * - * @example - * faker.company.companyName() // 'Zieme, Hauck and McClure' - * - * @since 2.0.1 - * - * @deprecated Use `faker.company.name()` instead - */ - companyName(format?: number): string { - deprecated({ - deprecated: 'faker.company.companyName()', - proposed: 'faker.company.name()', - since: '7.4', - until: '8.0', - }); - - return this.name(format); + const pattern = this.faker.helpers.arrayElement(formats); + return this.faker.helpers.fake(pattern); } /** diff --git a/src/modules/datatype/index.ts b/src/modules/datatype/index.ts index 9991175d55d..336f8f9f119 100644 --- a/src/modules/datatype/index.ts +++ b/src/modules/datatype/index.ts @@ -1,6 +1,5 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; /** * Module to generate various primitive values and data types. @@ -218,22 +217,12 @@ export class DatatypeModule { * @since 6.1.2 */ hexadecimal( - options: - | { length?: number; prefix?: string; case?: 'lower' | 'upper' | 'mixed' } - | number = {} + options: { + length?: number; + prefix?: string; + case?: 'lower' | 'upper' | 'mixed'; + } = {} ): string { - if (typeof options === 'number') { - deprecated({ - deprecated: 'faker.datatype.hexadecimal(length)', - proposed: 'faker.datatype.hexadecimal({ length })', - since: '7.5', - until: '8.0', - }); - options = { - length: options, - }; - } - const { length = 1, prefix = '0x', case: letterCase = 'mixed' } = options; let wholeString = ''; diff --git a/src/modules/fake/index.ts b/src/modules/fake/index.ts deleted file mode 100644 index 94ad4325149..00000000000 --- a/src/modules/fake/index.ts +++ /dev/null @@ -1,75 +0,0 @@ -import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; - -/** - * Generator method for combining faker methods based on string input. - * - * @deprecated - */ -export class FakeModule { - constructor(private readonly faker: Faker) { - // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(FakeModule.prototype)) { - if (name === 'constructor' || typeof this[name] !== 'function') { - continue; - } - this[name] = this[name].bind(this); - } - } - - /** - * Generator for combining faker methods based on a static string input. - * - * Note: We recommend using string template literals instead of `fake()`, - * which are faster and strongly typed (if you are using TypeScript), - * e.g. ``const address = `${faker.address.zipCode()} ${faker.address.city()}`;`` - * - * This method is useful if you have to build a random string from a static, non-executable source - * (e.g. string coming from a user, stored in a database or a file). - * - * It checks the given string for placeholders and replaces them by calling faker methods: - * - * ```js - * const hello = faker.fake('Hi, my name is {{name.firstName}} {{name.lastName}}!') - * ``` - * - * This would use the `faker.name.firstName()` and `faker.name.lastName()` method to resolve the placeholders respectively. - * - * It is also possible to provide parameters. At first, they will be parsed as json, - * and if that isn't possible, we will fall back to string: - * - * ```js - * const message = faker.fake(`You can call me at {{phone.number(+!# !## #### #####!)}}.') - * ``` - * - * Currently it is not possible to set more than a single parameter. - * - * It is also NOT possible to use any non-faker methods or plain javascript in such templates. - * - * @param str The template string that will get interpolated. Must not be empty. - * - * @see faker.helpers.mustache() to use custom functions for resolution. - * @see faker.helpers.fake() - * - * @example - * faker.fake('{{name.lastName}}') // 'Barrows' - * faker.fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}') // 'Durgan, Noe MD' - * faker.fake('This is static test.') // 'This is static test.' - * faker.fake('Good Morning {{name.firstName}}!') // 'Good Morning Estelle!' - * faker.fake('You can call me at {{phone.number(!## ### #####!)}}.') // 'You can call me at 202 555 973722.' - * faker.fake('I flipped the coin and got: {{helpers.arrayElement(["heads", "tails"])}}') // 'I flipped the coin and got: tails' - * - * @since 3.0.0 - * - * @deprecated Use faker.helpers.fake() instead. - */ - fake(str: string): string { - deprecated({ - deprecated: 'faker.fake()', - proposed: 'faker.helpers.fake()', - since: '7.4', - until: '8.0', - }); - return this.faker.helpers.fake(str); - } -} diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index f6aa55ac985..5f90027dda9 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1,6 +1,5 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; import { luhnCheckValue } from './luhn-check'; import type { RecordKey } from './unique'; import * as uniqueExec from './unique'; @@ -161,31 +160,6 @@ export class HelpersModule { return string.replace('L', String(checkNum)); } - /** - * Repeats the given string the given number of times. - * - * @param string The string to repeat. Defaults to `''`. - * @param num The number of times to repeat it. Defaults to `0`. - * - * @example - * faker.helpers.repeatString('Hello world! ') // '' - * faker.helpers.repeatString('Hello world! ', 1) // 'Hello world! ' - * faker.helpers.repeatString('Hello world! ', 2) // 'Hello world! Hello world! ' - * - * @since 5.0.0 - * - * @deprecated Use [String.prototype.repeat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat) instead. - */ - repeatString(string = '', num = 0): string { - deprecated({ - deprecated: 'faker.helpers.repeatString()', - proposed: 'String.prototype.repeat()', - since: '7.5', - until: '8.0', - }); - return string.repeat(num); - } - /** * Replaces the regex like expressions in the given string with matching values. * diff --git a/src/modules/image/providers/lorempicsum.ts b/src/modules/image/providers/lorempicsum.ts index 77f5d0c6976..d44673bdb42 100644 --- a/src/modules/image/providers/lorempicsum.ts +++ b/src/modules/image/providers/lorempicsum.ts @@ -1,5 +1,4 @@ import type { Faker } from '../../..'; -import { deprecated } from '../../../internal/deprecated'; /** * Module to generate links to random images on `https://picsum.photos/`. @@ -71,27 +70,6 @@ export class LoremPicsum { return this.imageUrl(width, height, grayscale, blur, seed); } - /** - * Returns a random avatar url. - * - * @see faker.internet.avatar() - * - * @example - * faker.internet.avatar() - * // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/315.jpg' - * - * @deprecated - */ - avatar(): string { - deprecated({ - deprecated: 'faker.image.lorempicsum.avatar()', - proposed: 'faker.internet.avatar()', - since: '7.3', - until: '8.0', - }); - return this.faker.internet.avatar(); - } - /** * Generates a new picsum image url. * diff --git a/src/modules/image/providers/lorempixel.ts b/src/modules/image/providers/lorempixel.ts index e645ff46318..a172517b609 100644 --- a/src/modules/image/providers/lorempixel.ts +++ b/src/modules/image/providers/lorempixel.ts @@ -1,5 +1,4 @@ import type { Faker } from '../../..'; -import { deprecated } from '../../../internal/deprecated'; import type { MethodsOf } from '../../../utils/types'; /** @@ -38,27 +37,6 @@ export class Lorempixel { ); } - /** - * Returns a random avatar url. - * - * @see faker.internet.avatar() - * - * @example - * faker.internet.avatar() - * // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/315.jpg' - * - * @deprecated - */ - avatar(): string { - deprecated({ - deprecated: 'faker.image.lorempixel.avatar()', - proposed: 'faker.internet.avatar()', - since: '7.3', - until: '8.0', - }); - return this.faker.internet.avatar(); - } - /** * Generates a new lorempixel image url. * diff --git a/src/modules/image/providers/unsplash.ts b/src/modules/image/providers/unsplash.ts index f682718cf0a..8fc2e324d93 100644 --- a/src/modules/image/providers/unsplash.ts +++ b/src/modules/image/providers/unsplash.ts @@ -1,24 +1,9 @@ import type { Faker } from '../../..'; -import { deprecated } from '../../../internal/deprecated'; /** * Module to generate links to random images on `https://source.unsplash.com/`. */ export class Unsplash { - /** - * Gets the list of supported unsplash categories. - * - * @deprecated - */ - get categories(): string[] { - deprecated({ - deprecated: 'faker.image.unsplash.categories', - since: '7.3', - until: '8.0', - }); - return ['food', 'nature', 'people', 'technology', 'objects', 'buildings']; - } - constructor(private readonly faker: Faker) {} /** @@ -32,27 +17,6 @@ export class Unsplash { return this.imageUrl(width, height, undefined, keyword); } - /** - * Returns a random avatar url. - * - * @see faker.internet.avatar() - * - * @example - * faker.internet.avatar() - * // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/315.jpg' - * - * @deprecated - */ - avatar(): string { - deprecated({ - deprecated: 'faker.image.unsplash.avatar()', - proposed: 'faker.internet.avatar()', - since: '7.3', - until: '8.0', - }); - return this.faker.internet.avatar(); - } - /** * Generates a new unsplash image url. * diff --git a/src/modules/mersenne/index.ts b/src/modules/mersenne/index.ts index 7bc9c7f7da9..16019e2925a 100644 --- a/src/modules/mersenne/index.ts +++ b/src/modules/mersenne/index.ts @@ -4,7 +4,7 @@ import Gen from './twister'; /** * Module to generate seed based random numbers. * - * @deprecated Internal. Use faker.datatype.number() or faker.seed() instead. + * @internal */ export class MersenneModule { private gen = new Gen(); diff --git a/src/modules/name/index.ts b/src/modules/name/index.ts index bdd3bd37795..99d25f8fc9b 100644 --- a/src/modules/name/index.ts +++ b/src/modules/name/index.ts @@ -1,21 +1,4 @@ import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; - -/** - * @deprecated Use Sex enum instead. - */ -export enum Gender { - // disabled until renamed to Sex - // eslint-disable-next-line @typescript-eslint/naming-convention - female = 'female', - // eslint-disable-next-line @typescript-eslint/naming-convention - male = 'male', -} - -/** - * @deprecated Use SexType instead. - */ -export type GenderType = SexType; export enum Sex { Female = 'female', @@ -158,37 +141,6 @@ export class NameModule { }); } - /** - * Generates a random full name. - * - * @param firstName The optional first name to use. If not specified a random one will be chosen. - * @param lastName The optional last name to use. If not specified a random one will be chosen. - * @param sex The optional sex to use. Can be either `'female'` or `'male'`. - * - * @see faker.name.fullName() - * - * @example - * faker.name.findName() // 'Allen Brown' - * faker.name.findName('Joann') // 'Joann Osinski' - * faker.name.findName('Marcella', '', 'female') // 'Mrs. Marcella Huels' - * faker.name.findName(undefined, 'Beer') // 'Mr. Alfonso Beer' - * faker.name.findName(undefined, undefined, 'male') // 'Fernando Schaefer' - * - * @since 2.0.1 - * - * @deprecated Use faker.name.fullName() instead. - */ - findName(firstName?: string, lastName?: string, sex?: SexType): string { - deprecated({ - deprecated: 'faker.name.findName()', - proposed: 'faker.name.fullName()', - since: '7.4', - until: '8.0', - }); - - return this.fullName({ firstName, lastName, sex }); - } - /** * Generates a random full name. * @@ -196,7 +148,6 @@ export class NameModule { * @param options.firstName The optional first name to use. If not specified a random one will be chosen. * @param options.lastName The optional last name to use. If not specified a random one will be chosen. * @param options.sex The optional sex to use. Can be either `'female'` or `'male'`. - * @param options.gender Deprecated. Use `sex` instead. * * @example * faker.name.fullName() // 'Allen Brown' @@ -211,26 +162,15 @@ export class NameModule { options: { firstName?: string; lastName?: string; - gender?: GenderType; sex?: SexType; } = {} ): string { const { - gender, - sex = gender || this.faker.helpers.arrayElement([Sex.Female, Sex.Male]), + sex = this.faker.helpers.arrayElement([Sex.Female, Sex.Male]), firstName = this.firstName(sex), lastName = this.lastName(sex), } = options; - if (gender) { - deprecated({ - deprecated: `faker.name.fullName({ gender: '...' })`, - proposed: `faker.name.fullName({ sex: '...' })`, - since: '7.4', - until: '8.0', - }); - } - const nameParts: string[] = []; const prefix = this.faker.helpers.maybe(() => this.prefix(sex), { probability: 0.125, @@ -257,8 +197,6 @@ export class NameModule { /** * Returns a random gender. * - * @param binary (deprecated) Whether to return only binary gender names. Defaults to `false`. - * * @see faker.name.sex() if you would like to generate binary-gender value * * @example @@ -266,18 +204,7 @@ export class NameModule { * * @since 5.0.0 */ - gender(binary?: boolean): string { - if (binary) { - deprecated({ - deprecated: 'faker.name.gender(true)', - proposed: 'faker.name.sex()', - since: '7.5', - until: '8.0', - }); - - return this.faker.name.sex(); - } - + gender(): string { return this.faker.helpers.arrayElement(this.faker.definitions.name.gender); } diff --git a/src/modules/phone/index.ts b/src/modules/phone/index.ts index 1f0d16a3e77..3e6d9815df5 100644 --- a/src/modules/phone/index.ts +++ b/src/modules/phone/index.ts @@ -1,5 +1,4 @@ import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; /** * Module to generate phone-related data. @@ -15,32 +14,6 @@ export class PhoneModule { } } - /** - * Generates a random phone number. - * - * @param format Format of the phone number. Defaults to a random phone number format. - * - * @see faker.phone.number() - * - * @example - * faker.phone.phoneNumber() // '961-770-7727' - * faker.phone.phoneNumber('501-###-###') // '501-039-841' - * faker.phone.phoneNumber('+48 91 ### ## ##') // '+48 91 463 61 70' - * - * @since 2.0.1 - * - * @deprecated Use faker.phone.number() instead. - */ - phoneNumber(format?: string): string { - deprecated({ - deprecated: 'faker.phone.phoneNumber()', - proposed: 'faker.phone.number()', - since: '7.3', - until: '8.0', - }); - return this.faker.phone.number(format); - } - /** * Generates a random phone number. * @@ -62,62 +35,6 @@ export class PhoneModule { return this.faker.helpers.replaceSymbolWithNumber(format); } - /** - * Returns phone number in a format of the given index from `faker.definitions.phone_number.formats`. - * - * @param phoneFormatsArrayIndex Index in the `faker.definitions.phone_number.formats` array. Defaults to `0`. - * - * @see faker.phone.phoneNumber() - * @see faker.helpers.replaceSymbolWithNumber() - * - * @example - * faker.phone.phoneNumberFormat() // '943-627-0355' - * faker.phone.phoneNumberFormat(3) // '282.652.3201' - * - * @since 2.0.1 - * - * @deprecated - * Use faker.phone.phoneNumber() instead. - */ - phoneNumberFormat(phoneFormatsArrayIndex = 0): string { - deprecated({ - deprecated: 'faker.phone.phoneNumberFormat()', - proposed: - 'faker.phone.phoneNumber() or faker.helpers.replaceSymbolWithNumber(format)', - since: '7.0', - until: '8.0', - }); - return this.faker.helpers.replaceSymbolWithNumber( - this.faker.definitions.phone_number.formats[phoneFormatsArrayIndex] - ); - } - - /** - * Returns a random phone number format. - * - * @see faker.phone.phoneNumber() - * @see faker.definitions.phone_number.formats() - * - * @example - * faker.phone.phoneFormats() // '!##.!##.####' - * - * @since 2.0.1 - * - * @deprecated - * Use `faker.phone.phoneNumber()` instead. - */ - phoneFormats(): string { - deprecated({ - deprecated: 'faker.phone.phoneFormats()', - proposed: 'faker.phone.phoneNumber()', - since: '7.0', - until: '8.0', - }); - return this.faker.helpers.arrayElement( - this.faker.definitions.phone_number.formats - ); - } - /** * Generates IMEI number. * diff --git a/src/modules/random/index.ts b/src/modules/random/index.ts index b4034343d88..7ce4df75140 100644 --- a/src/modules/random/index.ts +++ b/src/modules/random/index.ts @@ -1,6 +1,5 @@ import type { Faker } from '../..'; import { FakerError } from '../../errors/faker-error'; -import { deprecated } from '../../internal/deprecated'; import type { LiteralUnion } from '../../utils/types'; export type Casing = 'upper' | 'lower' | 'mixed'; @@ -263,10 +262,9 @@ export class RandomModule { /** * Generating a string consisting of letters in the English alphabet. * - * @param options Either the number of characters or an options instance. Defaults to `{ count: 1, casing: 'lower', bannedChars: [] }`. + * @param options Either the number of characters or an options instance. Defaults to `{ count: 1, casing: 'mixed', bannedChars: [] }`. * @param options.count The number of characters to generate. Defaults to `1`. - * @param options.casing The casing of the characters. Defaults to `'lower'`. - * @param options.upcase Deprecated, use `casing: 'upper'` instead. + * @param options.casing The casing of the characters. Defaults to `'mixed'`. * @param options.bannedChars An array with characters to exclude. Defaults to `[]`. * * @example @@ -281,10 +279,6 @@ export class RandomModule { | number | { count?: number; - /** - * @deprecated Use `casing` instead. - */ - upcase?: boolean; casing?: Casing; bannedChars?: readonly LiteralUnion[] | string; } = {} @@ -295,7 +289,7 @@ export class RandomModule { }; } - const { count = 1, upcase } = options; + const { count = 1 } = options; let { bannedChars = [] } = options; if (typeof bannedChars === 'string') { @@ -306,19 +300,7 @@ export class RandomModule { return ''; } - const { - // Switch to 'mixed' with v8.0 - casing = upcase ? 'upper' : 'lower', - } = options; - - if (upcase != null) { - deprecated({ - deprecated: 'faker.random.alpha({ upcase: true })', - proposed: "faker.random.alpha({ casing: 'upper' })", - since: '7.0', - until: '8.0', - }); - } + const { casing = 'mixed' } = options; let charsArray: string[]; switch (casing) { diff --git a/src/modules/unique/index.ts b/src/modules/unique/index.ts deleted file mode 100644 index fd817ec498b..00000000000 --- a/src/modules/unique/index.ts +++ /dev/null @@ -1,72 +0,0 @@ -import type { Faker } from '../..'; -import { deprecated } from '../../internal/deprecated'; -import type { RecordKey } from '../helpers/unique'; - -/** - * Module to generate unique entries. - * - * @deprecated - */ -export class UniqueModule { - constructor(private readonly faker: Faker) { - // Bind `this` so namespaced is working correctly - for (const name of Object.getOwnPropertyNames(UniqueModule.prototype)) { - if ( - name === 'constructor' || - name === 'maxTime' || - name === 'maxRetries' || - typeof this[name] !== 'function' - ) { - continue; - } - this[name] = this[name].bind(this); - } - } - - /** - * Generates a unique result using the results of the given method. - * Used unique entries will be stored internally and filtered from subsequent calls. - * - * @template Method The type of the method to execute. - * @param method The method used to generate the values. - * @param args The arguments used to call the method. - * @param options The optional options used to configure this method. - * @param options.startTime This parameter does nothing. - * @param options.maxTime The time in milliseconds this method may take before throwing an error. Defaults to `50`. - * @param options.maxRetries The total number of attempts to try before throwing an error. Defaults to `50`. - * @param options.currentIterations This parameter does nothing. - * @param options.exclude The value or values that should be excluded/skipped. Defaults to `[]`. - * @param options.compare The function used to determine whether a value was already returned. Defaults to check the existence of the key. - * @param options.store The store of unique entries. Defaults to a global store. - * - * @see faker.helpers.unique() - * - * @example - * faker.unique(faker.name.firstName) // 'Corbin' - * - * @since 5.0.0 - * - * @deprecated Use faker.helpers.unique() instead. - */ - unique RecordKey>( - method: Method, - args?: Parameters, - options: { - startTime?: number; - maxTime?: number; - maxRetries?: number; - currentIterations?: number; - exclude?: RecordKey | RecordKey[]; - compare?: (obj: Record, key: RecordKey) => 0 | -1; - store?: Record; - } = {} - ): ReturnType { - deprecated({ - deprecated: 'faker.unique()', - proposed: 'faker.helpers.unique()', - since: '7.5', - until: '8.0', - }); - return this.faker.helpers.unique(method, args, options); - } -} diff --git a/test/__snapshots__/address.spec.ts.snap b/test/__snapshots__/address.spec.ts.snap index 705eeb979d0..7ea2cde3c64 100644 --- a/test/__snapshots__/address.spec.ts.snap +++ b/test/__snapshots__/address.spec.ts.snap @@ -8,16 +8,10 @@ exports[`address > 42 > cardinalDirection > with abbr = false 1`] = `"East"`; exports[`address > 42 > cardinalDirection > with abbr = true 1`] = `"E"`; -exports[`address > 42 > city > noArgs 1`] = `"Port Valentine"`; - -exports[`address > 42 > city > with given index 1`] = `"West Peyton"`; +exports[`address > 42 > city 1`] = `"Port Valentine"`; exports[`address > 42 > cityName 1`] = `"Hamilton"`; -exports[`address > 42 > cityPrefix 1`] = `"West"`; - -exports[`address > 42 > citySuffix 1`] = `"bury"`; - exports[`address > 42 > country 1`] = `"Haiti"`; exports[`address > 42 > countryCode > noArgs 1`] = `"GY"`; @@ -72,11 +66,7 @@ exports[`address > 42 > streetAddress > with useFullAddress = false 1`] = `"7917 exports[`address > 42 > streetAddress > with useFullAddress = true 1`] = `"7917 Miller Park Apt. 410"`; -exports[`address > 42 > streetName 1`] = `"Peyton Villages"`; - -exports[`address > 42 > streetPrefix 1`] = `"b"`; - -exports[`address > 42 > streetSuffix 1`] = `"Highway"`; +exports[`address > 42 > streetName 1`] = `"b"`; exports[`address > 42 > timeZone 1`] = `"Europe/Brussels"`; @@ -96,16 +86,10 @@ exports[`address > 1211 > cardinalDirection > with abbr = false 1`] = `"West"`; exports[`address > 1211 > cardinalDirection > with abbr = true 1`] = `"W"`; -exports[`address > 1211 > city > noArgs 1`] = `"La Crosse"`; - -exports[`address > 1211 > city > with given index 1`] = `"Fort Jadyn"`; +exports[`address > 1211 > city 1`] = `"La Crosse"`; exports[`address > 1211 > cityName 1`] = `"Utica"`; -exports[`address > 1211 > cityPrefix 1`] = `"Fort"`; - -exports[`address > 1211 > citySuffix 1`] = `"shire"`; - exports[`address > 1211 > country 1`] = `"Uganda"`; exports[`address > 1211 > countryCode > noArgs 1`] = `"UM"`; @@ -160,11 +144,7 @@ exports[`address > 1211 > streetAddress > with useFullAddress = false 1`] = `"48 exports[`address > 1211 > streetAddress > with useFullAddress = true 1`] = `"487 Breana Wells Apt. 616"`; -exports[`address > 1211 > streetName 1`] = `"Koelpin Turnpike"`; - -exports[`address > 1211 > streetPrefix 1`] = `"c"`; - -exports[`address > 1211 > streetSuffix 1`] = `"Viaduct"`; +exports[`address > 1211 > streetName 1`] = `"c"`; exports[`address > 1211 > timeZone 1`] = `"Asia/Magadan"`; @@ -184,16 +164,10 @@ exports[`address > 1337 > cardinalDirection > with abbr = false 1`] = `"East"`; exports[`address > 1337 > cardinalDirection > with abbr = true 1`] = `"E"`; -exports[`address > 1337 > city > noArgs 1`] = `"New Carmella"`; - -exports[`address > 1337 > city > with given index 1`] = `"West Kellen"`; +exports[`address > 1337 > city 1`] = `"New Carmella"`; exports[`address > 1337 > cityName 1`] = `"East Hartford"`; -exports[`address > 1337 > cityPrefix 1`] = `"West"`; - -exports[`address > 1337 > citySuffix 1`] = `"boro"`; - exports[`address > 1337 > country 1`] = `"Equatorial Guinea"`; exports[`address > 1337 > countryCode > noArgs 1`] = `"EH"`; @@ -248,11 +222,7 @@ exports[`address > 1337 > streetAddress > with useFullAddress = false 1`] = `"51 exports[`address > 1337 > streetAddress > with useFullAddress = true 1`] = `"51225 Alexys Gateway Apt. 552"`; -exports[`address > 1337 > streetName 1`] = `"Kellen Crest"`; - -exports[`address > 1337 > streetPrefix 1`] = `"a"`; - -exports[`address > 1337 > streetSuffix 1`] = `"Ford"`; +exports[`address > 1337 > streetName 1`] = `"a"`; exports[`address > 1337 > timeZone 1`] = `"Europe/London"`; diff --git a/test/__snapshots__/commerce.spec.ts.snap b/test/__snapshots__/commerce.spec.ts.snap index 868ff10d63e..de1569a9752 100644 --- a/test/__snapshots__/commerce.spec.ts.snap +++ b/test/__snapshots__/commerce.spec.ts.snap @@ -1,7 +1,5 @@ // Vitest Snapshot v1 -exports[`commerce > 42 > color 1`] = `"grey"`; - exports[`commerce > 42 > department 1`] = `"Tools"`; exports[`commerce > 42 > price > noArgs 1`] = `"375.00"`; @@ -26,8 +24,6 @@ exports[`commerce > 42 > productMaterial 1`] = `"Plastic"`; exports[`commerce > 42 > productName 1`] = `"Fantastic Soft Sausages"`; -exports[`commerce > 1211 > color 1`] = `"azure"`; - exports[`commerce > 1211 > department 1`] = `"Automotive"`; exports[`commerce > 1211 > price > noArgs 1`] = `"929.00"`; @@ -52,8 +48,6 @@ exports[`commerce > 1211 > productMaterial 1`] = `"Frozen"`; exports[`commerce > 1211 > productName 1`] = `"Unbranded Cotton Salad"`; -exports[`commerce > 1337 > color 1`] = `"black"`; - exports[`commerce > 1337 > department 1`] = `"Computers"`; exports[`commerce > 1337 > price > noArgs 1`] = `"263.00"`; diff --git a/test/__snapshots__/company.spec.ts.snap b/test/__snapshots__/company.spec.ts.snap index 24d8212fcc3..446376372dc 100644 --- a/test/__snapshots__/company.spec.ts.snap +++ b/test/__snapshots__/company.spec.ts.snap @@ -16,15 +16,9 @@ exports[`company > 42 > catchPhraseDescriptor 1`] = `"explicit"`; exports[`company > 42 > catchPhraseNoun 1`] = `"framework"`; -exports[`company > 42 > companyName > noArgs 1`] = `"Schinner - Wiegand"`; - -exports[`company > 42 > companyName > with index 1`] = `"Schinner - Wiegand"`; - exports[`company > 42 > companySuffix 1`] = `"and Sons"`; -exports[`company > 42 > name > noArgs 1`] = `"Schinner - Wiegand"`; - -exports[`company > 42 > name > with index 1`] = `"Schinner - Wiegand"`; +exports[`company > 42 > name 1`] = `"Schinner - Wiegand"`; exports[`company > 42 > suffixes 1`] = ` [ @@ -51,15 +45,9 @@ exports[`company > 1211 > catchPhraseDescriptor 1`] = `"upward-trending"`; exports[`company > 1211 > catchPhraseNoun 1`] = `"system engine"`; -exports[`company > 1211 > companyName > noArgs 1`] = `"Koelpin, Trantow and Satterfield"`; - -exports[`company > 1211 > companyName > with index 1`] = `"Koelpin, Trantow and Satterfield"`; - exports[`company > 1211 > companySuffix 1`] = `"Group"`; -exports[`company > 1211 > name > noArgs 1`] = `"Koelpin, Trantow and Satterfield"`; - -exports[`company > 1211 > name > with index 1`] = `"Koelpin, Trantow and Satterfield"`; +exports[`company > 1211 > name 1`] = `"Koelpin, Trantow and Satterfield"`; exports[`company > 1211 > suffixes 1`] = ` [ @@ -86,15 +74,9 @@ exports[`company > 1337 > catchPhraseDescriptor 1`] = `"demand-driven"`; exports[`company > 1337 > catchPhraseNoun 1`] = `"data-warehouse"`; -exports[`company > 1337 > companyName > noArgs 1`] = `"MacGyver Inc"`; - -exports[`company > 1337 > companyName > with index 1`] = `"MacGyver Inc"`; - exports[`company > 1337 > companySuffix 1`] = `"and Sons"`; -exports[`company > 1337 > name > noArgs 1`] = `"MacGyver Inc"`; - -exports[`company > 1337 > name > with index 1`] = `"MacGyver Inc"`; +exports[`company > 1337 > name 1`] = `"MacGyver Inc"`; exports[`company > 1337 > suffixes 1`] = ` [ diff --git a/test/__snapshots__/helpers.spec.ts.snap b/test/__snapshots__/helpers.spec.ts.snap index 0fa011fa041..2cab313d133 100644 --- a/test/__snapshots__/helpers.spec.ts.snap +++ b/test/__snapshots__/helpers.spec.ts.snap @@ -51,12 +51,6 @@ exports[`helpers > 42 > regexpStyleStringParse > only symbols 1`] = `"###test2"` exports[`helpers > 42 > regexpStyleStringParse > some string 1`] = `"Hello !###test2"`; -exports[`helpers > 42 > repeatString > noArgs 1`] = `""`; - -exports[`helpers > 42 > repeatString > with only text 1`] = `""`; - -exports[`helpers > 42 > repeatString > with text and repetitions 1`] = `"Hello World! Hello World! Hello World! "`; - exports[`helpers > 42 > replaceCreditCardSymbols > noArgs 1`] = `"6453-3791-7755-1410-0489"`; exports[`helpers > 42 > replaceCreditCardSymbols > only symbols 1`] = `"7917-6-7563-4"`; @@ -173,12 +167,6 @@ exports[`helpers > 1211 > regexpStyleStringParse > only symbols 1`] = `"###test5 exports[`helpers > 1211 > regexpStyleStringParse > some string 1`] = `"Hello !###test5"`; -exports[`helpers > 1211 > repeatString > noArgs 1`] = `""`; - -exports[`helpers > 1211 > repeatString > with only text 1`] = `""`; - -exports[`helpers > 1211 > repeatString > with text and repetitions 1`] = `"Hello World! Hello World! Hello World! "`; - exports[`helpers > 1211 > replaceCreditCardSymbols > noArgs 1`] = `"6453-9487-2190-6162-7434"`; exports[`helpers > 1211 > replaceCreditCardSymbols > only symbols 1`] = `"4872-9-1927-1"`; @@ -285,12 +273,6 @@ exports[`helpers > 1337 > regexpStyleStringParse > only symbols 1`] = `"###test2 exports[`helpers > 1337 > regexpStyleStringParse > some string 1`] = `"Hello !###test2"`; -exports[`helpers > 1337 > repeatString > noArgs 1`] = `""`; - -exports[`helpers > 1337 > repeatString > with only text 1`] = `""`; - -exports[`helpers > 1337 > repeatString > with text and repetitions 1`] = `"Hello World! Hello World! Hello World! "`; - exports[`helpers > 1337 > replaceCreditCardSymbols > noArgs 1`] = `"6453-2512-2540-3255-2399"`; exports[`helpers > 1337 > replaceCreditCardSymbols > only symbols 1`] = `"5122-5-5424-8"`; diff --git a/test/__snapshots__/name.spec.ts.snap b/test/__snapshots__/name.spec.ts.snap index 5b3ceb1915c..c1edb1d4a23 100644 --- a/test/__snapshots__/name.spec.ts.snap +++ b/test/__snapshots__/name.spec.ts.snap @@ -1,34 +1,20 @@ // Vitest Snapshot v1 -exports[`name > 42 > findName > noArgs 1`] = `"Sadie Wiegand"`; - -exports[`name > 42 > findName > with gender 1`] = `"Melanie Schinner"`; - -exports[`name > 42 > findName > with name 1`] = `"John Doe"`; - -exports[`name > 42 > findName > with name and gender 1`] = `"John Doe"`; - exports[`name > 42 > firstName > noArgs 1`] = `"Garnet"`; -exports[`name > 42 > firstName > with gender 1`] = `"Glen"`; +exports[`name > 42 > firstName > with sex 1`] = `"Glen"`; exports[`name > 42 > fullName > noArgs 1`] = `"Sadie Wiegand"`; -exports[`name > 42 > fullName > with all (gender) 1`] = `"John Doe"`; - exports[`name > 42 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`name > 42 > fullName > with firstName 1`] = `"John Schinner"`; -exports[`name > 42 > fullName > with gender 1`] = `"Melanie Schinner"`; - exports[`name > 42 > fullName > with lastName 1`] = `"Sadie Doe"`; exports[`name > 42 > fullName > with sex 1`] = `"Melanie Schinner"`; -exports[`name > 42 > gender > noArgs 1`] = `"Gender nonconforming"`; - -exports[`name > 42 > gender > with gender 1`] = `"female"`; +exports[`name > 42 > gender 1`] = `"Gender nonconforming"`; exports[`name > 42 > jobArea 1`] = `"Identity"`; @@ -40,55 +26,41 @@ exports[`name > 42 > jobType 1`] = `"Coordinator"`; exports[`name > 42 > lastName > noArgs 1`] = `"Hirthe"`; -exports[`name > 42 > lastName > with gender 1`] = `"Hirthe"`; +exports[`name > 42 > lastName > with sex 1`] = `"Hirthe"`; exports[`name > 42 > middleName > noArgs 1`] = `"Greer"`; -exports[`name > 42 > middleName > with gender 1`] = `"Houston"`; +exports[`name > 42 > middleName > with sex 1`] = `"Houston"`; exports[`name > 42 > prefix > noArgs 1`] = `"Mrs."`; -exports[`name > 42 > prefix > with gender 1`] = `"Mrs."`; +exports[`name > 42 > prefix > with sex 1`] = `"Mrs."`; exports[`name > 42 > sex > noArgs 1`] = `"female"`; -exports[`name > 42 > sex > with gender 1`] = `"female"`; +exports[`name > 42 > sex > with sex 1`] = `"female"`; exports[`name > 42 > sexType 1`] = `"female"`; exports[`name > 42 > suffix > noArgs 1`] = `"III"`; -exports[`name > 42 > suffix > with gender 1`] = `"III"`; - -exports[`name > 1211 > findName > noArgs 1`] = `"Claude Trantow"`; - -exports[`name > 1211 > findName > with gender 1`] = `"Patti Koelpin"`; - -exports[`name > 1211 > findName > with name 1`] = `"John Doe"`; - -exports[`name > 1211 > findName > with name and gender 1`] = `"John Doe"`; +exports[`name > 42 > suffix > with sex 1`] = `"III"`; exports[`name > 1211 > firstName > noArgs 1`] = `"Tito"`; -exports[`name > 1211 > firstName > with gender 1`] = `"Percy"`; +exports[`name > 1211 > firstName > with sex 1`] = `"Percy"`; exports[`name > 1211 > fullName > noArgs 1`] = `"Claude Trantow"`; -exports[`name > 1211 > fullName > with all (gender) 1`] = `"John Doe"`; - exports[`name > 1211 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`name > 1211 > fullName > with firstName 1`] = `"John Koelpin"`; -exports[`name > 1211 > fullName > with gender 1`] = `"Patti Koelpin"`; - exports[`name > 1211 > fullName > with lastName 1`] = `"Claude Doe"`; exports[`name > 1211 > fullName > with sex 1`] = `"Patti Koelpin"`; -exports[`name > 1211 > gender > noArgs 1`] = `"Trigender"`; - -exports[`name > 1211 > gender > with gender 1`] = `"male"`; +exports[`name > 1211 > gender 1`] = `"Trigender"`; exports[`name > 1211 > jobArea 1`] = `"Factors"`; @@ -100,55 +72,41 @@ exports[`name > 1211 > jobType 1`] = `"Representative"`; exports[`name > 1211 > lastName > noArgs 1`] = `"Ward"`; -exports[`name > 1211 > lastName > with gender 1`] = `"Ward"`; +exports[`name > 1211 > lastName > with sex 1`] = `"Ward"`; exports[`name > 1211 > middleName > noArgs 1`] = `"Sawyer"`; -exports[`name > 1211 > middleName > with gender 1`] = `"Walter"`; +exports[`name > 1211 > middleName > with sex 1`] = `"Walter"`; exports[`name > 1211 > prefix > noArgs 1`] = `"Dr."`; -exports[`name > 1211 > prefix > with gender 1`] = `"Dr."`; +exports[`name > 1211 > prefix > with sex 1`] = `"Dr."`; exports[`name > 1211 > sex > noArgs 1`] = `"male"`; -exports[`name > 1211 > sex > with gender 1`] = `"male"`; +exports[`name > 1211 > sex > with sex 1`] = `"male"`; exports[`name > 1211 > sexType 1`] = `"male"`; exports[`name > 1211 > suffix > noArgs 1`] = `"DVM"`; -exports[`name > 1211 > suffix > with gender 1`] = `"DVM"`; - -exports[`name > 1337 > findName > noArgs 1`] = `"Leona Cronin"`; - -exports[`name > 1337 > findName > with gender 1`] = `"Esther MacGyver"`; - -exports[`name > 1337 > findName > with name 1`] = `"John Doe"`; - -exports[`name > 1337 > findName > with name and gender 1`] = `"John Doe"`; +exports[`name > 1211 > suffix > with sex 1`] = `"DVM"`; exports[`name > 1337 > firstName > noArgs 1`] = `"Devyn"`; -exports[`name > 1337 > firstName > with gender 1`] = `"Ray"`; +exports[`name > 1337 > firstName > with sex 1`] = `"Ray"`; exports[`name > 1337 > fullName > noArgs 1`] = `"Leona Cronin"`; -exports[`name > 1337 > fullName > with all (gender) 1`] = `"John Doe"`; - exports[`name > 1337 > fullName > with all (sex) 1`] = `"John Doe"`; exports[`name > 1337 > fullName > with firstName 1`] = `"John MacGyver"`; -exports[`name > 1337 > fullName > with gender 1`] = `"Esther MacGyver"`; - exports[`name > 1337 > fullName > with lastName 1`] = `"Leona Doe"`; exports[`name > 1337 > fullName > with sex 1`] = `"Esther MacGyver"`; -exports[`name > 1337 > gender > noArgs 1`] = `"Demigender"`; - -exports[`name > 1337 > gender > with gender 1`] = `"female"`; +exports[`name > 1337 > gender 1`] = `"Demigender"`; exports[`name > 1337 > jobArea 1`] = `"Functionality"`; @@ -160,22 +118,22 @@ exports[`name > 1337 > jobType 1`] = `"Engineer"`; exports[`name > 1337 > lastName > noArgs 1`] = `"Gibson"`; -exports[`name > 1337 > lastName > with gender 1`] = `"Gibson"`; +exports[`name > 1337 > lastName > with sex 1`] = `"Gibson"`; exports[`name > 1337 > middleName > noArgs 1`] = `"Dakota"`; -exports[`name > 1337 > middleName > with gender 1`] = `"Ethan"`; +exports[`name > 1337 > middleName > with sex 1`] = `"Ethan"`; exports[`name > 1337 > prefix > noArgs 1`] = `"Mrs."`; -exports[`name > 1337 > prefix > with gender 1`] = `"Mrs."`; +exports[`name > 1337 > prefix > with sex 1`] = `"Mrs."`; exports[`name > 1337 > sex > noArgs 1`] = `"female"`; -exports[`name > 1337 > sex > with gender 1`] = `"female"`; +exports[`name > 1337 > sex > with sex 1`] = `"female"`; exports[`name > 1337 > sexType 1`] = `"female"`; exports[`name > 1337 > suffix > noArgs 1`] = `"I"`; -exports[`name > 1337 > suffix > with gender 1`] = `"I"`; +exports[`name > 1337 > suffix > with sex 1`] = `"I"`; diff --git a/test/__snapshots__/phone.spec.ts.snap b/test/__snapshots__/phone.spec.ts.snap index 485b2ccbcee..2fd27bd33e6 100644 --- a/test/__snapshots__/phone.spec.ts.snap +++ b/test/__snapshots__/phone.spec.ts.snap @@ -6,68 +6,14 @@ exports[`phone > 42 > number > format 1`] = `"379-177-5514"`; exports[`phone > 42 > number > noArgs 1`] = `"(891) 775-5141 x004"`; -exports[`phone > 42 > phoneFormats 1`] = `"(!##) !##-#### x###"`; - -exports[`phone > 42 > phoneNumber > format 1`] = `"379-177-5514"`; - -exports[`phone > 42 > phoneNumber > noArgs 1`] = `"(891) 775-5141 x004"`; - -exports[`phone > 42 > phoneNumberFormat > noArgs 1`] = `"479-377-5514"`; - -exports[`phone > 42 > phoneNumberFormat > with index = 0 1`] = `"479-377-5514"`; - -exports[`phone > 42 > phoneNumberFormat > with index = 1 1`] = `"(479) 377-5514"`; - -exports[`phone > 42 > phoneNumberFormat > with index = 2 1`] = `"1-479-377-5514"`; - -exports[`phone > 42 > phoneNumberFormat > with index = 3 1`] = `"479.377.5514"`; - -exports[`phone > 42 > phoneNumberFormat > with index = 4 1`] = `"479-377-5514 x100"`; - exports[`phone > 1211 > imei 1`] = `"94-872190-616274-4"`; exports[`phone > 1211 > number > format 1`] = `"948-721-9061"`; exports[`phone > 1211 > number > noArgs 1`] = `"1-587-319-0616 x27431"`; -exports[`phone > 1211 > phoneFormats 1`] = `"1-!##-!##-#### x#####"`; - -exports[`phone > 1211 > phoneNumber > format 1`] = `"948-721-9061"`; - -exports[`phone > 1211 > phoneNumber > noArgs 1`] = `"1-587-319-0616 x27431"`; - -exports[`phone > 1211 > phoneNumberFormat > noArgs 1`] = `"948-821-9061"`; - -exports[`phone > 1211 > phoneNumberFormat > with index = 0 1`] = `"948-821-9061"`; - -exports[`phone > 1211 > phoneNumberFormat > with index = 1 1`] = `"(948) 821-9061"`; - -exports[`phone > 1211 > phoneNumberFormat > with index = 2 1`] = `"1-948-821-9061"`; - -exports[`phone > 1211 > phoneNumberFormat > with index = 3 1`] = `"948.821.9061"`; - -exports[`phone > 1211 > phoneNumberFormat > with index = 4 1`] = `"948-821-9061 x627"`; - exports[`phone > 1337 > imei 1`] = `"25-122540-325523-4"`; exports[`phone > 1337 > number > format 1`] = `"251-225-4032"`; exports[`phone > 1337 > number > noArgs 1`] = `"612-454-0325 x523"`; - -exports[`phone > 1337 > phoneFormats 1`] = `"!##-!##-#### x###"`; - -exports[`phone > 1337 > phoneNumber > format 1`] = `"251-225-4032"`; - -exports[`phone > 1337 > phoneNumber > noArgs 1`] = `"612-454-0325 x523"`; - -exports[`phone > 1337 > phoneNumberFormat > noArgs 1`] = `"451-325-4032"`; - -exports[`phone > 1337 > phoneNumberFormat > with index = 0 1`] = `"451-325-4032"`; - -exports[`phone > 1337 > phoneNumberFormat > with index = 1 1`] = `"(451) 325-4032"`; - -exports[`phone > 1337 > phoneNumberFormat > with index = 2 1`] = `"1-451-325-4032"`; - -exports[`phone > 1337 > phoneNumberFormat > with index = 3 1`] = `"451.325.4032"`; - -exports[`phone > 1337 > phoneNumberFormat > with index = 4 1`] = `"451-325-4032 x552"`; diff --git a/test/__snapshots__/random.spec.ts.snap b/test/__snapshots__/random.spec.ts.snap index 240e5f265c0..1a9b2dff10a 100644 --- a/test/__snapshots__/random.spec.ts.snap +++ b/test/__snapshots__/random.spec.ts.snap @@ -1,8 +1,8 @@ // Vitest Snapshot v1 -exports[`random > 42 > alpha > noArgs 1`] = `"j"`; +exports[`random > 42 > alpha > noArgs 1`] = `"t"`; -exports[`random > 42 > alpha > withLength 1`] = `"juyet"`; +exports[`random > 42 > alpha > withLength 1`] = `"tPXjM"`; exports[`random > 42 > alphaNumeric > noArgs 1`] = `"d"`; @@ -20,9 +20,9 @@ exports[`random > 42 > words > noArgs 1`] = `"lavender Shoes"`; exports[`random > 42 > words > withLength 1`] = `"responsive comeback Neptunium Hip deposit"`; -exports[`random > 1211 > alpha > noArgs 1`] = `"y"`; +exports[`random > 1211 > alpha > noArgs 1`] = `"W"`; -exports[`random > 1211 > alpha > withLength 1`] = `"ylxuf"`; +exports[`random > 1211 > alpha > withLength 1`] = `"WxUOl"`; exports[`random > 1211 > alphaNumeric > noArgs 1`] = `"x"`; @@ -40,9 +40,9 @@ exports[`random > 1211 > words > noArgs 1`] = `"invoice Cyclocross assault"`; exports[`random > 1211 > words > withLength 1`] = `"gah strictly Rustic assault Manager"`; -exports[`random > 1337 > alpha > noArgs 1`] = `"g"`; +exports[`random > 1337 > alpha > noArgs 1`] = `"n"`; -exports[`random > 1337 > alpha > withLength 1`] = `"goefh"`; +exports[`random > 1337 > alpha > withLength 1`] = `"nDilo"`; exports[`random > 1337 > alphaNumeric > noArgs 1`] = `"9"`; diff --git a/test/address.spec.ts b/test/address.spec.ts index 2c724806c02..fa639b074b0 100644 --- a/test/address.spec.ts +++ b/test/address.spec.ts @@ -43,7 +43,7 @@ describe('address', () => { }); seededTests(faker, 'address', (t) => { - t.itEach('street', 'streetName', 'streetPrefix', 'streetSuffix'); + t.itEach('street', 'streetName'); t.it('buildingNumber'); @@ -54,12 +54,7 @@ describe('address', () => { .it('with useFullAddress = false', false); }); - t.it('cityName') - .it('cityPrefix') - .it('citySuffix') - .describe('city', (t) => { - t.it('noArgs').it('with given index', 1); - }); + t.itEach('city', 'cityName'); t.it('county'); diff --git a/test/commerce.spec.ts b/test/commerce.spec.ts index 55606462ad9..781b6431e5c 100644 --- a/test/commerce.spec.ts +++ b/test/commerce.spec.ts @@ -11,7 +11,6 @@ describe('commerce', () => { seededTests(faker, 'commerce', (t) => { t.itEach( - 'color', 'department', 'productName', 'productAdjective', @@ -32,13 +31,6 @@ describe('commerce', () => { describe(`random seeded tests for seed ${faker.seed()}`, () => { for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { - describe(`color()`, () => { - it('should return random value from color array', () => { - const actual = faker.commerce.color(); - expect(faker.definitions.color.human).toContain(actual); - }); - }); - describe(`department()`, () => { it('should return random value from department array', () => { const department = faker.commerce.department(); diff --git a/test/company.spec.ts b/test/company.spec.ts index ae7ea03930b..4a57f118a23 100644 --- a/test/company.spec.ts +++ b/test/company.spec.ts @@ -12,6 +12,7 @@ describe('company', () => { seededTests(faker, 'company', (t) => { t.itEach( 'suffixes', + 'name', 'companySuffix', 'catchPhrase', 'bs', @@ -22,12 +23,6 @@ describe('company', () => { 'bsBuzz', 'bsNoun' ); - t.describeEach( - 'companyName', - 'name' - )((t) => { - t.it('noArgs').it('with index'); - }); }); describe(`random seeded tests for seed ${faker.seed()}`, () => { @@ -48,65 +43,6 @@ describe('company', () => { expect(actual).toBeTruthy(); expect(actual).toBeTypeOf('string'); }); - - it('should return a random company name with format 0', () => { - const actual = faker.company.name(0); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - expect(actual).includes(' '); - }); - - it('should return a random company name with format 1', () => { - const actual = faker.company.name(1); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - expect(actual).includes(' - '); - }); - - it('should return a random company name with format 2', () => { - const actual = faker.company.name(2); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - expect(actual).includes(', '); - expect(actual).includes(' and '); - }); - }); - - describe('companyName()', () => { - it('should return a random company name', () => { - const actual = faker.company.companyName(); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - }); - - it('should return a random company name with format 0', () => { - const actual = faker.company.companyName(0); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - expect(actual).includes(' '); - }); - - it('should return a random company name with format 1', () => { - const actual = faker.company.companyName(1); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - expect(actual).includes(' - '); - }); - - it('should return a random company name with format 2', () => { - const actual = faker.company.companyName(2); - - expect(actual).toBeTruthy(); - expect(actual).toBeTypeOf('string'); - expect(actual).includes(', '); - expect(actual).includes(' and '); - }); }); describe('companySuffix()', () => { diff --git a/test/fake.spec.ts b/test/fake.spec.ts deleted file mode 100644 index 8c0a0a8bf29..00000000000 --- a/test/fake.spec.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { describe, expect, it } from 'vitest'; -import { faker } from '../src'; -import { FakerError } from '../src/errors/faker-error'; - -describe('fake', () => { - describe('fake()', () => { - it('replaces a token with a random value for a method with no parameters', () => { - const name = faker.fake('{{phone.number}}'); - expect(name).toMatch(/\d/); - }); - - it('replaces multiple tokens with random values for methods with no parameters', () => { - const name = faker.fake( - '{{helpers.arrayElement}}{{helpers.arrayElement}}{{helpers.arrayElement}}' - ); - expect(name).toMatch(/[abc]{3}/); - }); - - it('replaces a token with a random value for a methods with a simple parameter', () => { - const random = faker.fake('{{helpers.slugify("Will This Work")}}'); - expect(random).toBe('Will-This-Work'); - }); - - it('replaces a token with a random value for a method with an array parameter', () => { - const arr = ['one', 'two', 'three']; - const random = faker.fake( - '{{helpers.arrayElement(["one", "two", "three"])}}' - ); - expect(arr).toContain(random); - }); - - it('does not allow undefined parameters', () => { - expect(() => - // @ts-expect-error: The parameter is required - faker.fake() - ).toThrowError(new FakerError('string parameter is required!')); - }); - - it('does not allow invalid module name', () => { - expect(() => faker.fake('{{foo.bar}}')).toThrowError( - new FakerError(`Invalid module method or definition: foo.bar -- faker.foo.bar is not a function -- faker.definitions.foo.bar is not an array`) - ); - }); - - it('does not allow missing method name', () => { - expect(() => faker.fake('{{address}}')).toThrowError( - new FakerError(`Invalid module method or definition: address -- faker.address is not a function -- faker.definitions.address is not an array`) - ); - }); - - it('does not allow invalid method name', () => { - expect(() => faker.fake('{{address.foo}}')).toThrowError( - new FakerError(`Invalid module method or definition: address.foo -- faker.address.foo is not a function -- faker.definitions.address.foo is not an array`) - ); - }); - - it('does not allow invalid definitions data', () => { - expect(() => faker.fake('{{finance.credit_card}}')).toThrowError( - new FakerError(`Invalid module method or definition: finance.credit_card -- faker.finance.credit_card is not a function -- faker.definitions.finance.credit_card is not an array`) - ); - }); - - it('should be able to return empty strings', () => { - expect(faker.fake('{{helpers.repeatString}}')).toBe(''); - }); - - it('should be able to return locale definition strings', () => { - expect(faker.definitions.cell_phone.formats).toContain( - faker.fake('{{cell_phone.formats}}') - ); - }); - - it('should be able to return locale definition strings that starts with the name of an existing module', () => { - expect(faker.definitions.address.city_name).toContain( - faker.fake('{{address.city_name}}') - ); - }); - - it('should be able to handle only {{ brackets', () => { - expect(faker.fake('{{hello')).toBe('{{hello'); - expect(faker.fake('hello{{')).toBe('hello{{'); - }); - - it('should be able to handle only }} brackets', () => { - expect(faker.fake('hello}}')).toBe('hello}}'); - expect(faker.fake('}}hello')).toBe('}}hello'); - }); - - it('should be able to handle reverted brackets', () => { - expect(faker.fake('}}hello{{')).toBe('}}hello{{'); - }); - - it('should be able to handle random }} brackets', () => { - expect(faker.fake('}}hello{{random.alpha}}')).toMatch(/^}}hello[a-z]$/); - }); - - it('should be able to handle connected brackets', () => { - expect(faker.fake('{{{random.alpha}}}')).toMatch(/^{[a-z]}$/); - }); - - it('should be able to handle empty brackets', () => { - expect(faker.fake('{{}}')).toBe('{{}}'); - }); - - it('should be able to handle special replacement patterns', () => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (faker.random as any).special = () => '$&'; - - expect(faker.fake('{{random.special}}')).toBe('$&'); - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - delete (faker.random as any).special; - }); - }); -}); diff --git a/test/helpers.spec.ts b/test/helpers.spec.ts index 15c26874d2f..2d63b67bce7 100644 --- a/test/helpers.spec.ts +++ b/test/helpers.spec.ts @@ -55,12 +55,6 @@ describe('helpers', () => { ); }); - t.describe('repeatString', (t) => { - t.it('noArgs') - .it('with only text', 'Hello World!') - .it('with text and repetitions', 'Hello World! ', 3); - }); - t.describe('arrayElement', (t) => { t.it('noArgs').it('with array', 'Hello World!'.split('')); }); @@ -252,12 +246,6 @@ describe('helpers', () => { }); }); - describe('repeatString()', () => { - it('returns empty string with no arguments', () => { - expect(faker.helpers.repeatString()).toBe(''); - }); - }); - describe('regexpStyleStringParse()', () => { it('returns an empty string when called without param', () => { expect(faker.helpers.regexpStyleStringParse()).toBe(''); @@ -279,13 +267,13 @@ describe('helpers', () => { it('repeats string {n} number of times', () => { expect(faker.helpers.regexpStyleStringParse('%{10}')).toBe( - faker.helpers.repeatString('%', 10) + '%'.repeat(10) ); expect(faker.helpers.regexpStyleStringParse('%{30}')).toBe( - faker.helpers.repeatString('%', 30) + '%'.repeat(30) ); expect(faker.helpers.regexpStyleStringParse('%{5}')).toBe( - faker.helpers.repeatString('%', 5) + '%'.repeat(5) ); }); @@ -569,7 +557,7 @@ describe('helpers', () => { }); it('should be able to return empty strings', () => { - expect(faker.helpers.fake('{{helpers.repeatString}}')).toBe(''); + expect(faker.helpers.fake('{{random.alphaNumeric(0)}}')).toBe(''); }); it('should be able to return locale definition strings', () => { @@ -605,7 +593,9 @@ describe('helpers', () => { }); it('should be able to handle connected brackets', () => { - expect(faker.helpers.fake('{{{random.alpha}}}')).toMatch(/^{[a-z]}$/); + expect(faker.helpers.fake('{{{random.alpha}}}')).toMatch( + /^{[a-zA-Z]}$/ + ); }); it('should be able to handle empty brackets', () => { diff --git a/test/image.spec.ts b/test/image.spec.ts index 36503efa3eb..b38edae8e82 100644 --- a/test/image.spec.ts +++ b/test/image.spec.ts @@ -52,18 +52,6 @@ describe('image', () => { }); }); - describe('avatar()', () => { - it('should return a random avatar from cloudflare-ipfs', () => { - expect( - faker.image.lorempicsum - .avatar() - .includes( - 'cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar' - ) - ).toBeTruthy(); - }); - }); - describe('imageGrayscale()', () => { it('should return a random URL with grayscale image', () => { const imageUrl = faker.image.lorempicsum.imageGrayscale(100, 100, true); @@ -116,18 +104,6 @@ describe('image', () => { }); }); - describe('avatar()', () => { - it('should return a random avatar from cloudflare-ipfs', () => { - expect( - faker.image.lorempixel - .avatar() - .includes( - 'cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar' - ) - ).toBeTruthy(); - }); - }); - const categories = [ 'abstract', 'animals', diff --git a/test/name.spec.ts b/test/name.spec.ts index 35cca232875..d47a1a45e5b 100644 --- a/test/name.spec.ts +++ b/test/name.spec.ts @@ -11,37 +11,29 @@ describe('name', () => { }); seededTests(faker, 'name', (t) => { - t.itEach('sexType', 'jobTitle', 'jobDescriptor', 'jobArea', 'jobType'); + t.itEach( + 'sexType', + 'gender', + 'jobTitle', + 'jobDescriptor', + 'jobArea', + 'jobType' + ); t.describeEach( 'firstName', 'lastName', 'middleName', - 'gender', 'prefix', 'sex', 'suffix' - )((t) => t.it('noArgs').it('with gender', 'male')); - - t.describe('findName', (t) => { - t.it('noArgs') - .it('with name', 'John', 'Doe') - .it('with gender', undefined, undefined, 'female') - .it('with name and gender', 'John', 'Doe', 'female'); - }); + )((t) => t.it('noArgs').it('with sex', 'male')); t.describe('fullName', (t) => { t.it('noArgs') .it('with firstName', { firstName: 'John' }) .it('with lastName', { lastName: 'Doe' }) - .it('with gender', { gender: 'female' }) // deprecated .it('with sex', { sex: 'female' }) - .it('with all (gender)', { - firstName: 'John', - lastName: 'Doe', - // deprecated - gender: 'female', - }) .it('with all (sex)', { firstName: 'John', lastName: 'Doe', @@ -146,96 +138,6 @@ describe('name', () => { }); }); - describe('findName()', () => { - beforeEach(() => { - faker.locale = 'en'; - faker.localeFallback = 'en'; - }); - - it('should return a name with firstName and lastName', () => { - const fullName = faker.name.findName(); - - expect(fullName).toBeTypeOf('string'); - expect(fullName).toContain(' '); - }); - - it('should return a female sex-specific name with firstName and lastName', () => { - faker.locale = 'mk'; - - const female_specific = [ - ...faker.definitions.name.female_prefix, - ...faker.definitions.name.female_first_name, - ...faker.definitions.name.female_last_name, - ...faker.definitions.name.suffix, - ]; - - const fullName = faker.name.findName(undefined, undefined, 'female'); - - const parts = fullName.split(' '); - for (const part of parts) { - expect(female_specific).toContain(part); - } - }); - - it('should return a male sex-specific name with firstName and lastName', () => { - faker.locale = 'mk'; - - const male_specific = [ - ...faker.definitions.name.male_prefix, - ...faker.definitions.name.male_first_name, - ...faker.definitions.name.male_last_name, - ...faker.definitions.name.suffix, - ]; - - const fullName = faker.name.findName(undefined, undefined, 'male'); - - const parts = fullName.split(' '); - for (const part of parts) { - expect(male_specific).toContain(part); - } - }); - - it('should return a female sex-specific name with given firstName and lastName', () => { - faker.locale = 'mk'; - - const male_specific = [ - ...faker.definitions.name.female_prefix, - 'firstName', - 'lastName', - ...faker.definitions.name.suffix, - ]; - - const fullName = faker.name.findName( - 'firstName', - 'lastName', - 'female' - ); - - const parts = fullName.split(' '); - for (const part of parts) { - expect(male_specific).toContain(part); - } - }); - - it('should return a male sex-specific name with given firstName and lastName', () => { - faker.locale = 'mk'; - - const male_specific = [ - ...faker.definitions.name.male_prefix, - 'firstName', - 'lastName', - ...faker.definitions.name.suffix, - ]; - - const fullName = faker.name.findName('firstName', 'lastName', 'male'); - - const parts = fullName.split(' '); - for (const part of parts) { - expect(male_specific).toContain(part); - } - }); - }); - describe('fullName()', () => { beforeEach(() => { faker.locale = 'en'; @@ -249,7 +151,7 @@ describe('name', () => { expect(fullName).toContain(' '); }); - it('should return a female gender-specific name without firstName and lastName', () => { + it('should return a female sex-specific name without firstName and lastName', () => { faker.locale = 'mk'; const female_specific = [ @@ -259,7 +161,7 @@ describe('name', () => { ...faker.definitions.name.suffix, ]; - const fullName = faker.name.fullName({ gender: 'female' }); + const fullName = faker.name.fullName({ sex: 'female' }); const parts = fullName.split(' '); for (const part of parts) { @@ -267,7 +169,7 @@ describe('name', () => { } }); - it('should return a male gender-specific name without firstName and lastName', () => { + it('should return a male sex-specific name without firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -277,7 +179,7 @@ describe('name', () => { ...faker.definitions.name.suffix, ]; - const fullName = faker.name.fullName({ gender: 'male' }); + const fullName = faker.name.fullName({ sex: 'male' }); const parts = fullName.split(' '); for (const part of parts) { @@ -285,7 +187,7 @@ describe('name', () => { } }); - it('should return a female gender-specific name with given firstName and lastName', () => { + it('should return a female sex-specific name with given firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -298,7 +200,7 @@ describe('name', () => { const fullName = faker.name.fullName({ firstName: 'firstName', lastName: 'lastName', - gender: 'female', + sex: 'female', }); const parts = fullName.split(' '); @@ -307,7 +209,7 @@ describe('name', () => { } }); - it('should return a male gender-specific name with given firstName and lastName', () => { + it('should return a male sex-specific name with given firstName and lastName', () => { faker.locale = 'mk'; const male_specific = [ @@ -320,7 +222,7 @@ describe('name', () => { const fullName = faker.name.fullName({ firstName: 'firstName', lastName: 'lastName', - gender: 'male', + sex: 'male', }); const parts = fullName.split(' '); @@ -342,13 +244,6 @@ describe('name', () => { expect(gender).toBeTypeOf('string'); expect(faker.definitions.name.gender).toContain(gender); }); - - it('should return a binary gender', () => { - const gender = faker.name.gender(true); - - expect(gender).toBeTypeOf('string'); - expect(faker.definitions.name.sex).toContain(gender); - }); }); describe('sex()', () => { diff --git a/test/phone.spec.ts b/test/phone.spec.ts index ee44457ddd3..7431476b9bd 100644 --- a/test/phone.spec.ts +++ b/test/phone.spec.ts @@ -11,33 +11,15 @@ describe('phone', () => { }); seededTests(faker, 'phone', (t) => { - t.itEach('phoneFormats', 'imei'); + t.it('imei'); - t.describeEach( - 'phoneNumber', - 'number' - )((t) => { + t.describe('number', (t) => { t.it('noArgs').it('format', '###-###-####'); }); - - t.describe('phoneNumberFormat', (t) => { - t.it('noArgs'); - for (const index of [0, 1, 2, 3, 4]) { - t.it(`with index = ${index}`, index); - } - }); }); describe(`random seeded tests for seed ${faker.seed()}`, () => { for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { - describe('phoneNumber()', () => { - it('should return a random phoneNumber with a random format', () => { - const phoneNumber = faker.phone.phoneNumber(); - - expect(phoneNumber).toMatch(/\d/); - }); - }); - describe('number()', () => { it('should return a random phoneNumber with a random format', () => { const phoneNumber = faker.phone.number(); @@ -46,33 +28,6 @@ describe('phone', () => { }); }); - describe('phoneNumberFormat()', () => { - it('should return phone number with proper US format (Array index)', () => { - faker.locale = 'en'; - const phoneNumber = faker.phone.phoneNumberFormat(1); - expect(phoneNumber).toMatch(/\([2-9]\d\d\) [2-9]\d\d-\d\d\d\d/); - }); - - it('should return phone number with proper CA format (Array index)', () => { - faker.locale = 'en_CA'; - const phoneNumber = faker.phone.phoneNumberFormat(1); - expect(phoneNumber).toMatch(/\([2-9]\d\d\)[2-9]\d\d-\d\d\d\d/); - }); - - it('should return phone number with proper PL format (Array index)', () => { - faker.locale = 'pl'; - const phoneNumber = faker.phone.phoneNumberFormat(1); - expect(phoneNumber).toMatch(/13-\d{3}-\d{2}-\d{2}/); - }); - }); - - describe('phoneFormats()', () => { - it('should return random phone number format', () => { - const phoneFormat = faker.phone.phoneFormats(); - expect(faker.definitions.phone_number.formats).contain(phoneFormat); - }); - }); - describe('imei()', () => { it('should return a string', () => { const imei = faker.phone.imei(); diff --git a/test/random.spec.ts b/test/random.spec.ts index 6e64f5f1ee8..b387d000a3c 100644 --- a/test/random.spec.ts +++ b/test/random.spec.ts @@ -130,7 +130,7 @@ describe('random', () => { it('should return lowercase letter when no upcase option provided', () => { const actual = faker.random.alpha(); - expect(actual).toMatch(/^[a-z]$/); + expect(actual).toMatch(/^[a-z]$/i); }); it.each([ @@ -160,35 +160,36 @@ describe('random', () => { it('should be able to ban some characters', () => { const actual = faker.random.alpha({ count: 5, - bannedChars: ['a', 'p'], + bannedChars: ['a', 'p', 'A', 'P'], }); expect(actual).toHaveLength(5); - expect(actual).toMatch(/^[b-oq-z]{5}$/); + expect(actual).toMatch(/^[b-oq-z]{5}$/i); }); it('should be able to ban some characters via string', () => { const actual = faker.random.alpha({ count: 5, - bannedChars: 'ap', + bannedChars: 'apAP', }); expect(actual).toHaveLength(5); - expect(actual).toMatch(/^[b-oq-z]{5}$/); + expect(actual).toMatch(/^[b-oq-z]{5}$/i); }); it('should be able handle mistake in banned characters array', () => { const alphaText = faker.random.alpha({ count: 5, - bannedChars: ['a', 'a', 'p'], + bannedChars: ['a', 'a', 'p', 'A', 'A', 'P'], }); expect(alphaText).toHaveLength(5); - expect(alphaText).toMatch(/^[b-oq-z]{5}$/); + expect(alphaText).toMatch(/^[b-oq-z]{5}$/i); }); it('should throw if all possible characters being banned', () => { - const bannedChars = 'abcdefghijklmnopqrstuvwxyz'.split(''); + const bannedChars = + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); expect(() => faker.random.alpha({ count: 5, diff --git a/test/scripts/apidoc/examplesAndDeprecations.spec.ts b/test/scripts/apidoc/examplesAndDeprecations.spec.ts index 72a947838fc..37d61399acb 100644 --- a/test/scripts/apidoc/examplesAndDeprecations.spec.ts +++ b/test/scripts/apidoc/examplesAndDeprecations.spec.ts @@ -4,7 +4,6 @@ import type { DeclarationReflection, SignatureReflection } from 'typedoc'; import { ReflectionKind } from 'typedoc'; import type { SpyInstance } from 'vitest'; import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { selectDirectMethods } from '../../../scripts/apidoc/directMethods'; import { selectApiModules } from '../../../scripts/apidoc/moduleMethods'; import { extractRawExamples, @@ -31,8 +30,6 @@ const locales: Record = { describe('examples and deprecations', () => { const project = loadProject(); - const directs: DeclarationReflection[] = selectDirectMethods(project); - const modules: Record = selectApiModules( project ) @@ -42,7 +39,7 @@ describe('examples and deprecations', () => { ...a, [v.name]: v.getChildrenByKind(ReflectionKind.Method), }), - { directs } + {} ); const consoleSpies: Array = Object.keys(console) diff --git a/test/unique.spec.ts b/test/unique.spec.ts deleted file mode 100644 index e603939d2de..00000000000 --- a/test/unique.spec.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { afterEach, describe, expect, it } from 'vitest'; -import { faker } from '../src'; -import { FakerError } from '../src/errors/faker-error'; -import { seededRuns } from './support/seededRuns'; - -const NON_SEEDED_BASED_RUN = 5; - -const MOCK_ARRAY = Array.from( - { length: 500 }, - (_, index) => `Test-${index + 1}` -); - -function customMethod(prefix: string = ''): string { - const element = faker.helpers.arrayElement(MOCK_ARRAY); - return `${prefix}${element}`; -} - -describe('unique', () => { - afterEach(() => { - faker.locale = 'en'; - }); - - for (const seed of seededRuns) { - describe(`seed: ${seed}`, () => { - it('unique(customMethod)', () => { - faker.seed(seed); - - const actual = faker.unique(customMethod); - - expect(actual).toMatchSnapshot(); - }); - - it('unique(customMethod, args)', () => { - faker.seed(seed); - - const prefix = 'prefix-1-'; - - const actual = faker.unique(customMethod, [prefix]); - - expect(actual).toMatchSnapshot(); - }); - - it('unique(() => number)', () => { - faker.seed(seed); - - const actual = faker.unique(faker.datatype.number); - - expect(actual).toMatchSnapshot(); - }); - - it('unique(() => number), args)', () => { - faker.seed(seed); - - const actual = faker.unique(faker.datatype.number, [50]); - - expect(actual).toMatchSnapshot(); - }); - }); - } - - describe(`random seeded tests for seed ${faker.seed()}`, () => { - for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) { - describe('unique()', () => { - it('should be possible to call a function with no arguments and return a result', () => { - const result = faker.unique(faker.internet.email); - expect(result).toBeTypeOf('string'); - }); - - it('should be possible to call a function with arguments and return a result', () => { - const result = faker.unique(faker.internet.email, [ - 'fName', - 'lName', - 'domain', - ]); // third argument is provider, or domain for email - expect(result).toMatch(/\@domain/); - }); - - it('should be possible to limit unique call by maxTime in ms', () => { - expect(() => { - faker.unique(faker.internet.protocol, [], { - maxTime: 1, - maxRetries: 9999, - exclude: ['https', 'http'], - }); - }).toThrowError( - new FakerError(`Exceeded maxTime: 1 for uniqueness check. - -May not be able to generate any more unique values with current settings. -Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`) - ); - }); - - it('should be possible to limit unique call by maxRetries', () => { - expect(() => { - faker.unique(faker.internet.protocol, [], { - maxTime: 5000, - maxRetries: 5, - exclude: ['https', 'http'], - }); - }).toThrowError( - new FakerError(`Exceeded maxRetries: 5 for uniqueness check. - -May not be able to generate any more unique values with current settings. -Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`) - ); - }); - - it('should throw a FakerError instance on error', () => { - expect(() => { - faker.unique(faker.internet.protocol, [], { - maxTime: 5000, - maxRetries: 5, - exclude: ['https', 'http'], - }); - }).toThrowError( - new FakerError(`Exceeded maxRetries: 5 for uniqueness check. - -May not be able to generate any more unique values with current settings. -Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().`) - ); - }); - }); - } - }); -});