Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

test: repair all functional test #1718

Merged
merged 12 commits into from
Jan 10, 2023
27 changes: 21 additions & 6 deletions test/all_functional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { describe, expect, it } from 'vitest';
import { faker } from '../src';
import type { KnownLocale } from '../src/locales';

const IGNORED_MODULES = [
'locales',
'locale',
'localeFallback',
'definitions',
'fake',
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
'helpers',
'_locale',
'_localeFallback',
'_mersenne',
];

Expand All @@ -22,6 +23,7 @@ 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: {
Expand All @@ -34,7 +36,7 @@ const BROKEN_LOCALE_METHODS = {
prefix: ['az', 'id_ID', 'ru'],
suffix: ['az', 'it', 'mk', 'pt_PT', 'ru'],
},
};
} satisfies Record<string, Record<string, '*' | KnownLocale[]>>;

// @ts-expect-error: ignore also the aliases
BROKEN_LOCALE_METHODS.name = BROKEN_LOCALE_METHODS.person;
Expand All @@ -46,7 +48,8 @@ function isWorkingLocaleForMethod(
meth: string,
locale: string
): boolean {
return (BROKEN_LOCALE_METHODS[mod]?.[meth] ?? []).indexOf(locale) === -1;
const exclude = BROKEN_LOCALE_METHODS[mod]?.[meth] ?? [];
return exclude !== '*' && exclude.indexOf(locale) === -1;
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
}

// Basic smoke tests to make sure each method is at least implemented and returns a value.
Expand Down Expand Up @@ -88,6 +91,7 @@ describe('functional tests', () => {
expect(result).toBeTypeOf('boolean');
} else {
expect(result).toBeTruthy();
expect(result).not.toEqual([]);
}
};

Expand All @@ -111,14 +115,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');
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
};

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);
}
});
});
});
Expand Down