Skip to content

Commit 0ea21d6

Browse files
authored
fix(cts): skip generating unknown language (#117)
1 parent 771e455 commit 0ea21d6

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

tests/src/client/main.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
import { parseCLI } from '../utils';
1+
import { parseCLI, checkIfLanguageExists } from '../utils';
22

33
import { generateTests } from './generate';
44

55
async function main(): Promise<void> {
66
const { lang, client } = parseCLI(process.argv, 'generate:client');
7+
8+
if (!checkIfLanguageExists(lang)) {
9+
// eslint-disable-next-line no-console
10+
console.log(
11+
`Skipping CTS generation > generate:client for ${lang}-${client}: Language not present in the config.json file`
12+
);
13+
14+
return;
15+
}
16+
717
// eslint-disable-next-line no-console
818
console.log(`Generating CTS > generate:client for ${lang}-${client}`);
919

tests/src/methods/requests/main.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
import { parseCLI } from '../../utils';
1+
import { parseCLI, checkIfLanguageExists } from '../../utils';
22

33
import { generateTests } from './generate';
44

55
async function main(): Promise<void> {
66
const { lang, client } = parseCLI(process.argv, 'generate:methods:requests');
7+
8+
if (!checkIfLanguageExists(lang)) {
9+
// eslint-disable-next-line no-console
10+
console.log(
11+
`Skipping CTS generation > generate:methods:requests for ${lang}-${client}: Language not present in the config.json file`
12+
);
13+
14+
return;
15+
}
16+
717
// eslint-disable-next-line no-console
818
console.log(
919
`Generating CTS > generate:methods:requests for ${lang}-${client}`

tests/src/utils.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
capitalize,
3+
checkIfLanguageExists,
34
createClientName,
45
removeEnumType,
56
removeObjectName,
@@ -103,4 +104,14 @@ describe('utils', () => {
103104
});
104105
});
105106
});
107+
108+
describe('checkIfLanguageExists', () => {
109+
it('returns `true` if the language is present in the config', () => {
110+
expect(checkIfLanguageExists('javascript')).toBe(true);
111+
});
112+
113+
it('returns `false` if the language is not present in the config', () => {
114+
expect(checkIfLanguageExists('algo')).toBe(false);
115+
});
116+
});
106117
});

tests/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export function removeObjectName(obj: any): any {
7676
return obj;
7777
}
7878

79+
export function checkIfLanguageExists(language: string): boolean {
80+
return Boolean(ctsConfig[language]);
81+
}
82+
7983
export function removeEnumType(obj: any): any {
8084
if (typeof obj === 'object') {
8185
if (Array.isArray(obj)) {

0 commit comments

Comments
 (0)