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: fix lint warning and simplify locales test #1430

Merged
merged 1 commit into from Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 14 additions & 44 deletions test/locales.spec.ts
@@ -1,5 +1,4 @@
import { describe, expect, it } from 'vitest';
import type { LocaleDefinition } from '../src';
import { faker } from '../src';
import allLocales from '../src/locales';
import './vitest-extensions';
Expand All @@ -16,50 +15,21 @@ describe('locale', () => {
});
});

for (const [localeName, moduleMap] of Object.entries(allLocales)) {
describe(localeName, () => {
for (const [
moduleName,
definitionMap,
] of Object.entries<LocaleDefinition>(moduleMap)) {
if (moduleName === 'title' || moduleName === 'separator') {
continue;
}

describe(moduleName, () => {
for (const [definitionName, entries] of Object.entries(
definitionMap
)) {
describe(definitionName, () => {
function testArraySample<T>(arr: T[]) {
it('should not have duplicate entries', () => {
expect(arr).not.toContainDuplicates();
});
}

if (Array.isArray(entries)) {
testArraySample(entries);
} else if (typeof entries === 'object') {
for (const [key, samples] of Object.entries(entries)) {
if (Array.isArray(samples)) {
describe(key, () => {
testArraySample(samples);
});
} else {
it('cant be tested', () => {
expect(true).toBe(true);
});
}
}
} else {
it('needs to be tested', () => {
expect(false).toBe(true);
});
}
});
}
function checkLocaleData(data: unknown) {
if (Array.isArray(data)) {
it('should not have duplicate entries', () => {
expect(data).not.toContainDuplicates();
});
} else if (typeof data === 'object' && data != null) {
for (const [nestedKey, nestedData] of Object.entries(data)) {
describe(nestedKey, () => {
checkLocaleData(nestedData);
});
}
});
} else {
it.skip(`primitives cannot be tested`);
}
}

checkLocaleData(allLocales);
});