diff options
| author | ST-DDT <[email protected]> | 2023-01-10 19:48:25 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-10 19:48:25 +0100 |
| commit | 7e0de02decf87e6b57e3ecf06276391dedc77c31 (patch) | |
| tree | 7331fe8ca5b69198e99e07f12085eeef8a94c8e3 | |
| parent | 1e7534e92ac002c0281a47336343f39e29065630 (diff) | |
| download | faker-7e0de02decf87e6b57e3ecf06276391dedc77c31.tar.xz faker-7e0de02decf87e6b57e3ecf06276391dedc77c31.zip | |
test: repair all functional test (#1718)
| -rw-r--r-- | test/all_functional.spec.ts | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/test/all_functional.spec.ts b/test/all_functional.spec.ts index 26b15144..cc784660 100644 --- a/test/all_functional.spec.ts +++ b/test/all_functional.spec.ts @@ -1,13 +1,13 @@ import { describe, expect, it } from 'vitest'; import { faker } from '../src'; +import type { KnownLocale } from '../src/locales'; const IGNORED_MODULES = [ 'locales', - 'locale', - 'localeFallback', 'definitions', - 'fake', 'helpers', + '_locale', + '_localeFallback', '_mersenne', ]; @@ -22,11 +22,10 @@ function isMethodOf(mod: string) { const BROKEN_LOCALE_METHODS = { // TODO ST-DDT 2022-03-28: these are TODOs (usually broken locale files) company: { + suffixes: ['az'], companySuffix: ['az'], }, location: { - cityPrefix: ['pt_BR', 'pt_PT'], - citySuffix: ['pt_PT'], state: ['az', 'cz', 'nb_NO', 'sk'], stateAbbr: ['cz', 'sk'], }, @@ -34,19 +33,15 @@ const BROKEN_LOCALE_METHODS = { prefix: ['az', 'id_ID', 'ru', 'zh_CN', 'zh_TW'], suffix: ['az', 'it', 'mk', 'pt_PT', 'ru'], }, -}; - -// @ts-expect-error: ignore also the aliases -BROKEN_LOCALE_METHODS.name = BROKEN_LOCALE_METHODS.person; -// @ts-expect-error: ignore also the aliases -BROKEN_LOCALE_METHODS.address = BROKEN_LOCALE_METHODS.location; +} satisfies Record<string, Record<string, '*' | KnownLocale[]>>; function isWorkingLocaleForMethod( mod: string, meth: string, locale: string ): boolean { - return (BROKEN_LOCALE_METHODS[mod]?.[meth] ?? []).indexOf(locale) === -1; + const broken = BROKEN_LOCALE_METHODS[mod]?.[meth] ?? []; + return broken !== '*' && !broken.includes(locale); } // Basic smoke tests to make sure each method is at least implemented and returns a value. @@ -72,6 +67,35 @@ function modulesList(): { [module: string]: string[] } { const modules = modulesList(); +describe('BROKEN_LOCALE_METHODS test', () => { + it('should not contain obsolete configuration (modules)', () => { + const existingModules = Object.keys(modules); + const configuredModules = Object.keys(BROKEN_LOCALE_METHODS ?? {}); + const obsoleteModules = configuredModules.filter( + (module) => !existingModules.includes(module) + ); + + expect(obsoleteModules, 'No obsolete configuration').toEqual([]); + }); + + Object.keys(modules).forEach((module) => { + describe(module, () => { + it('should not contain obsolete configuration (methods)', () => { + const existingMethods = modules[module]; + const configuredMethods = Object.keys( + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + BROKEN_LOCALE_METHODS[module] ?? {} + ); + const obsoleteMethods = configuredMethods.filter( + (method) => !existingMethods.includes(method) + ); + + expect(obsoleteMethods, 'No obsolete configuration').toEqual([]); + }); + }); + }); +}); + describe('functional tests', () => { for (const locale in faker.locales) { describe(locale, () => { @@ -88,6 +112,7 @@ describe('functional tests', () => { expect(result).toBeTypeOf('boolean'); } else { expect(result).toBeTruthy(); + expect(result).not.toEqual([]); } }; @@ -111,14 +136,25 @@ describe('faker.helpers.fake functional tests', () => { Object.keys(modules).forEach((module) => { describe(module, () => { modules[module].forEach((meth) => { - it(`${meth}()`, () => { + const testAssertion = () => { faker.locale = locale; // TODO ST-DDT 2022-03-28: Use random seed once there are no more failures faker.seed(1); const result = faker.helpers.fake(`{{${module}.${meth}}}`); expect(result).toBeTypeOf('string'); - }); + expect(result).not.toBe(''); + expect(result).not.toBe('null'); + expect(result).not.toBe('undefined'); + }; + + if (isWorkingLocaleForMethod(module, meth, locale)) { + it(`${meth}()`, testAssertion); + } else { + // TODO ST-DDT 2022-03-28: Remove once there are no more failures + // We expect a failure here to ensure we remove the exclusions when fixed + it.fails(`${meth}()`, testAssertion); + } }); }); }); |
