Skip to content

Commit

Permalink
fix(cts): skip generating unknown language (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Feb 3, 2022
1 parent 771e455 commit 0ea21d6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
12 changes: 11 additions & 1 deletion tests/src/client/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { parseCLI } from '../utils';
import { parseCLI, checkIfLanguageExists } from '../utils';

import { generateTests } from './generate';

async function main(): Promise<void> {
const { lang, client } = parseCLI(process.argv, 'generate:client');

if (!checkIfLanguageExists(lang)) {
// eslint-disable-next-line no-console
console.log(
`Skipping CTS generation > generate:client for ${lang}-${client}: Language not present in the config.json file`
);

return;
}

// eslint-disable-next-line no-console
console.log(`Generating CTS > generate:client for ${lang}-${client}`);

Expand Down
12 changes: 11 additions & 1 deletion tests/src/methods/requests/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { parseCLI } from '../../utils';
import { parseCLI, checkIfLanguageExists } from '../../utils';

import { generateTests } from './generate';

async function main(): Promise<void> {
const { lang, client } = parseCLI(process.argv, 'generate:methods:requests');

if (!checkIfLanguageExists(lang)) {
// eslint-disable-next-line no-console
console.log(
`Skipping CTS generation > generate:methods:requests for ${lang}-${client}: Language not present in the config.json file`
);

return;
}

// eslint-disable-next-line no-console
console.log(
`Generating CTS > generate:methods:requests for ${lang}-${client}`
Expand Down
11 changes: 11 additions & 0 deletions tests/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
capitalize,
checkIfLanguageExists,
createClientName,
removeEnumType,
removeObjectName,
Expand Down Expand Up @@ -103,4 +104,14 @@ describe('utils', () => {
});
});
});

describe('checkIfLanguageExists', () => {
it('returns `true` if the language is present in the config', () => {
expect(checkIfLanguageExists('javascript')).toBe(true);
});

it('returns `false` if the language is not present in the config', () => {
expect(checkIfLanguageExists('algo')).toBe(false);
});
});
});
4 changes: 4 additions & 0 deletions tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export function removeObjectName(obj: any): any {
return obj;
}

export function checkIfLanguageExists(language: string): boolean {
return Boolean(ctsConfig[language]);
}

export function removeEnumType(obj: any): any {
if (typeof obj === 'object') {
if (Array.isArray(obj)) {
Expand Down

0 comments on commit 0ea21d6

Please sign in to comment.