aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorST-DDT <[email protected]>2023-11-07 17:26:27 +0100
committerGitHub <[email protected]>2023-11-07 16:26:27 +0000
commit8542ef30bd4eda3d9f04db2c4a79abf0369d57c3 (patch)
tree94f768aa2c1c48faedddb745843f6d0b34b19988 /test
parent9498203190e37a96114ddc8e861b02ccd94e517b (diff)
downloadfaker-8542ef30bd4eda3d9f04db2c4a79abf0369d57c3.tar.xz
faker-8542ef30bd4eda3d9f04db2c4a79abf0369d57c3.zip
infra(unicorn): no-array-reduce (#2479)
Diffstat (limited to 'test')
-rw-r--r--test/all-functional.spec.ts59
-rw-r--r--test/scripts/apidoc/verify-jsdoc-tags.spec.ts18
2 files changed, 39 insertions, 38 deletions
diff --git a/test/all-functional.spec.ts b/test/all-functional.spec.ts
index 91c310b2..c5bef114 100644
--- a/test/all-functional.spec.ts
+++ b/test/all-functional.spec.ts
@@ -10,12 +10,36 @@ const IGNORED_MODULES = new Set([
'_defaultRefDate',
]);
-function isTestableModule(mod: string) {
- return !IGNORED_MODULES.has(mod);
+function getMethodNamesByModules(faker: Faker): { [module: string]: string[] } {
+ return Object.fromEntries(
+ Object.keys(faker)
+ .filter(isTestableModule)
+ .sort()
+ .map<[string, string[]]>((moduleName) => [
+ moduleName,
+ getMethodNamesOf(faker[moduleName]),
+ ])
+ .filter(([module, methods]) => {
+ if (methods.length === 0) {
+ console.log(`Skipping ${module} - No testable methods`);
+ return false;
+ }
+
+ return true;
+ })
+ );
+}
+
+function isTestableModule(moduleName: string): moduleName is keyof Faker {
+ return !IGNORED_MODULES.has(moduleName);
+}
+
+function getMethodNamesOf(module: object): string[] {
+ return Object.keys(module).filter(isMethodOf(module));
}
-function isMethodOf(mod: string) {
- return (meth: string) => typeof fakerEN[mod][meth] === 'function';
+function isMethodOf(module: object): (method: string) => boolean {
+ return (method: string) => typeof module[method] === 'function';
}
type SkipConfig<TModule> = Partial<
@@ -53,36 +77,17 @@ const BROKEN_LOCALE_METHODS = {
};
function isWorkingLocaleForMethod(
- mod: string,
- meth: string,
+ module: string,
+ method: string,
locale: string
): boolean {
- const broken = BROKEN_LOCALE_METHODS[mod]?.[meth] ?? [];
+ const broken = BROKEN_LOCALE_METHODS[module]?.[method] ?? [];
return broken !== '*' && !broken.includes(locale);
}
// Basic smoke tests to make sure each method is at least implemented and returns a value.
-function modulesList(): { [module: string]: string[] } {
- const modules = Object.keys(fakerEN)
- .sort()
- .filter(isTestableModule)
- .reduce((result, mod) => {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
- const methods = Object.keys(fakerEN[mod]).filter(isMethodOf(mod));
- if (methods.length > 0) {
- result[mod] = methods;
- } else {
- console.log(`Skipping ${mod} - No testable methods`);
- }
-
- return result;
- }, {});
-
- return modules;
-}
-
-const modules = modulesList();
+const modules = getMethodNamesByModules(fakerEN);
describe('BROKEN_LOCALE_METHODS test', () => {
it('should not contain obsolete configuration (modules)', () => {
diff --git a/test/scripts/apidoc/verify-jsdoc-tags.spec.ts b/test/scripts/apidoc/verify-jsdoc-tags.spec.ts
index a924c268..47eca926 100644
--- a/test/scripts/apidoc/verify-jsdoc-tags.spec.ts
+++ b/test/scripts/apidoc/verify-jsdoc-tags.spec.ts
@@ -47,28 +47,24 @@ describe('verify JSDoc tags', () => {
}
const allowedReferences = new Set(
- Object.values(modules).reduce<string[]>((acc, [module, methods]) => {
+ Object.values(modules).flatMap(([module, methods]) => {
const moduleFieldName = extractModuleFieldName(module);
- return [
- ...acc,
- ...Object.keys(methods).map(
- (methodName) => `faker.${moduleFieldName}.${methodName}`
- ),
- ];
- }, [])
+ return Object.keys(methods).map(
+ (methodName) => `faker.${moduleFieldName}.${methodName}`
+ );
+ })
);
const allowedLinks = new Set(
- Object.values(modules).reduce<string[]>((acc, [module, methods]) => {
+ Object.values(modules).flatMap(([module, methods]) => {
const moduleFieldName = extractModuleFieldName(module);
return [
- ...acc,
`/api/${moduleFieldName}.html`,
...Object.keys(methods).map(
(methodName) =>
`/api/${moduleFieldName}.html#${methodName.toLowerCase()}`
),
];
- }, [])
+ })
);
function assertDescription(description: string, isHtml: boolean): void {