Skip to content

Commit

Permalink
test: 💍 split test case
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharkazaz committed Jun 14, 2024
1 parent aa4baf7 commit 39d8f4b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions __tests__/resolveConfig/resolveConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ describe('resolveConfig', () => {
function resolvePath(configPath: string): string;
function resolvePath(configPath: string, asArray: true): string[];
function resolvePath(configPath: string | string[], asArray = false) {
const resolve = (p) => path.resolve(process.cwd(), sourceRoot, p);
const resolve = (p: string) => path.resolve(process.cwd(), sourceRoot, p);
if (Array.isArray(configPath)) {
return configPath.map(resolve);
}

return asArray ? [resolve(configPath)] : resolve(configPath);
}

function assertConfig(expected, inline = {}) {
function assertConfig<T>(expected: T, inline = {}) {
const { scopes, ...config } = resolveConfig(inline);
expect(config).toEqual(expected);
expect(scopes).toBeDefined();
Expand Down Expand Up @@ -169,8 +169,7 @@ describe('resolveConfig', () => {
shouldFail('Input', 'pathIsNotDir');
});

it('should fail on invalid translations path', () => {
/* should only fail translation path when in find mode */
it('should pass on invalid translations path in find mode', () => {
resolveConfig({
input: ['src/folder'],
translationsPath: 'noFolder',
Expand All @@ -183,6 +182,9 @@ describe('resolveConfig', () => {
command: 'extract',
});
shouldPass();
});

it('should fail on invalid translations path in extract mode', () => {
resolveConfig({
input: ['src/folder'],
translationsPath: 'noFolder',
Expand All @@ -201,12 +203,12 @@ describe('resolveConfig', () => {
describe('resolveConfigPaths', () => {
it('should prefix all the paths in the config with the process cwd', () => {
const config = resolveConfig({ input: ['folder'] });
const assertPath = (p) =>
const assertPath = (p: string) =>
expect(p.startsWith(path.resolve(process.cwd(), sourceRoot))).toBe(
true,
);
config.input.forEach(assertPath);
['output', 'translationsPath'].forEach((prop) =>
(['output', 'translationsPath'] as const).forEach((prop) =>
assertPath(config[prop]),
);
});
Expand Down

0 comments on commit 39d8f4b

Please sign in to comment.