Skip to content

Commit

Permalink
test: fix lint warning and simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Oct 12, 2022
1 parent f124bfb commit 9b7fb04
Showing 1 changed file with 14 additions and 44 deletions.
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);
});

0 comments on commit 9b7fb04

Please sign in to comment.