Skip to content

chore: restructure folder #89

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

Merged
merged 10 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"build": "tsc",
"lint:fix": "yarn workspace javascript-tests lint:fix",
"generate": "node dist/tests/src/main.js ${0:-javascript} ${1:-search}",
"generate": "yarn generate:methods:requets ${0:-javascript} ${1:-search}",
"generate:methods:requets": "node dist/tests/src/methods/requests/main.js ${0:-javascript} ${1:-search}",
"start": "yarn build && yarn generate ${0:-javascript} ${1:-search} && yarn lint:fix"
},
"devDependencies": {
Expand Down
Empty file added tests/src/client/.gitkeep
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions tests/src/cts.ts → tests/src/methods/requests/cts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SwaggerParser from '@apidevtools/swagger-parser';
import type { OpenAPIV3 } from 'openapi-types';

import type { CTS, CTSBlock, Tests } from './types';
import { removeObjectName, walk } from './utils';
import { removeObjectName, walk } from '../../utils';

async function loadRequestsCTS(client: string): Promise<CTSBlock[]> {
// load the list of operations from the spec
Expand All @@ -19,7 +19,7 @@ async function loadRequestsCTS(client: string): Promise<CTSBlock[]> {

const ctsClient: CTSBlock[] = [];

for await (const file of walk(`./CTS/clients/${client}/requests`)) {
for await (const file of walk(`./CTS/methods/requests/${client}`)) {
if (!file.name.endsWith('json')) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import Mustache from 'mustache';
import { loadCTS } from './cts';
import { loadRequestsTemplate } from './templates';
import type { CTSBlock } from './types';
import { extensionForLanguage } from './types';
import { createClientName, packageNames } from './utils';
import {
createClientName,
packageNames,
extensionForLanguage,
} from '../../utils';

async function createOutputDir(language: string): Promise<void> {
await fsp.mkdir(`output/${language}`, { recursive: true });
await fsp.mkdir(`output/${language}/tests`, { recursive: true });
await fsp.mkdir(`output/${language}/tests/methods/requests`, {
recursive: true,
});
}

async function generateRequestsTests(
Expand All @@ -35,7 +39,7 @@ async function generateRequestsTests(
].includes(client),
});
await fsp.writeFile(
`output/${language}/tests/${client}Requests.${extensionForLanguage[language]}`,
`output/${language}/tests/methods/requests/${client}.${extensionForLanguage[language]}`,
code
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/main.ts → tests/src/methods/requests/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

import { generateTests } from './generate';
import { packageNames } from './utils';
import { packageNames } from '../../utils';

function printUsage(): void {
console.log(`usage: generateCTS language client`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import fsp from 'fs/promises';

export async function loadRequestsTemplate(language: string): Promise<string> {
return (
await fsp.readFile(`CTS/templates/${language}/requests.mustache`)
await fsp.readFile(`CTS/methods/templates/${language}/requests.mustache`)
).toString();
}
5 changes: 0 additions & 5 deletions tests/src/types.ts → tests/src/methods/requests/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,3 @@ export type CTSBlock = {
export type CTS = {
requests: CTSBlock[];
};

export const extensionForLanguage: Record<string, string> = {
javascript: 'test.ts',
java: 'java',
};
5 changes: 5 additions & 0 deletions tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ export function removeObjectName(obj: Record<string, any>): void {
}
}
}

export const extensionForLanguage: Record<string, string> = {
javascript: 'test.ts',
java: 'java',
};