Skip to content

Commit

Permalink
try again
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Apr 21, 2024
1 parent 19460e6 commit c2e7bbf
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/seed/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function addTestCommand(cli: Argv) {
const tests: Promise<boolean>[] = [];

for (const generator of generators) {
if (argv.workspace != null && !argv.generator?.includes(generator.workspaceName)) {
if (argv.generator != null && !argv.generator.includes(generator.workspaceName)) {
continue;
}
const testRunner = new DockerTestRunner({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function rewriteInputsForWorkspace({
for (const fixture of fixtures) {
const fixtureConfig = generator.workspaceConfig.fixtures?.[fixture];
const docker = parseDockerOrThrow(generator.workspaceConfig.docker);
const absolutePathToFernDefinition = AbsoluteFilePath.of(
const absolutePathToAPIDefinition = AbsoluteFilePath.of(
path.join(__dirname, FERN_DIRECTORY, APIS_DIRECTORY, fixture)
);
const absolutePathToOutput = join(generator.absolutePathToWorkspace, RelativeFilePath.of(fixture));
Expand All @@ -41,7 +41,7 @@ export async function rewriteInputsForWorkspace({
`${generator.workspaceName}:${fixture} - ${fixtureConfigInstance.outputFolder}`
);
const fernWorkspace = await convertGeneratorWorkspaceToFernWorkspace({
absolutePathToWorkspace: absolutePathToFernDefinition,
absolutePathToAPIDefinition,
taskContext,
fixture
});
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function rewriteInputsForWorkspace({
} else {
const taskContext = taskContextFactory.create(`${generator.workspaceName}:${fixture}`);
const fernWorkspace = await convertGeneratorWorkspaceToFernWorkspace({
absolutePathToWorkspace: absolutePathToFernDefinition,
absolutePathToAPIDefinition,
taskContext,
fixture
});
Expand Down
2 changes: 1 addition & 1 deletion packages/seed/src/commands/run/runWithCustomFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function runWithCustomFixture({
});

const fernWorkspace = await convertGeneratorWorkspaceToFernWorkspace({
absolutePathToWorkspace: pathToFixture,
absolutePathToAPIDefinition: pathToFixture,
taskContext,
fixture: "custom"
});
Expand Down
3 changes: 2 additions & 1 deletion packages/seed/src/commands/test/printTestCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export function printTestCases(result: TestRunner.TestResult[]): void {
Result: r.type,
"Generation Time": r.metrics.generationTime,
"Compile Time": r.metrics.compileTime,
"Failure Type": r.type === "failure" ? r.cause : ""
"Failure Type": r.type === "failure" ? r.cause : "",
"Failure Message": r.type === "failure" ? r.message : ""
};
});
printTable(items);
Expand Down
17 changes: 12 additions & 5 deletions packages/seed/src/commands/test/test-runner/TestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export declare namespace TestRunner {
}

export abstract class TestRunner {
private built: boolean = false;
protected readonly generator: GeneratorWorkspace;
protected readonly lock: Semaphore;
protected readonly taskContextFactory: TaskContextFactory;
Expand All @@ -97,6 +98,11 @@ export abstract class TestRunner {
* Runs the generator.
*/
public async run({ fixture, configuration }: TestRunner.RunArgs): Promise<TestRunner.TestResult> {
if (!this.built) {
await this.build();
this.built = true;
}

const metrics: TestRunner.TestCaseMetrics = {};

const fixtureConfig = this.generator.workspaceConfig.fixtures?.[fixture];
Expand All @@ -110,13 +116,14 @@ export abstract class TestRunner {
};
}

const absolutePathToWorkspace = AbsoluteFilePath.of(
const id = configuration != null ? `${fixture}:${configuration.outputFolder}` : `${fixture}`;
const absolutePathToAPIDefinition = AbsoluteFilePath.of(
path.join(__dirname, FERN_DIRECTORY, APIS_DIRECTORY, fixture)
);
const taskContext = this.taskContextFactory.create(`${this.generator.workspaceName}:${fixture}`);
const taskContext = this.taskContextFactory.create(`${this.generator.workspaceName}:${id}`);
const outputFolder = configuration?.outputFolder ?? fixture;
const fernWorkspace = await convertGeneratorWorkspaceToFernWorkspace({
absolutePathToWorkspace,
absolutePathToAPIDefinition,
taskContext,
fixture
});
Expand All @@ -137,9 +144,9 @@ export abstract class TestRunner {
const generationStopwatch = new Stopwatch();
generationStopwatch.start();
await this.runGenerator({
id: configuration != null ? `${fixture}:${configuration.outputFolder}` : `${fixture}`,
id,
fernWorkspace,
absolutePathToWorkspace,
absolutePathToWorkspace: this.generator.absolutePathToWorkspace,
irVersion: this.generator.workspaceConfig.irVersion,
outputVersion: configuration?.outputVersion,
language: this.generator.workspaceConfig.language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { convertOpenApiWorkspaceToFernWorkspace, FernWorkspace, loadAPIWorkspace

export async function convertGeneratorWorkspaceToFernWorkspace({
fixture,
absolutePathToWorkspace,
absolutePathToAPIDefinition,
taskContext
}: {
fixture: string;
absolutePathToWorkspace: AbsoluteFilePath;
absolutePathToAPIDefinition: AbsoluteFilePath;
taskContext: TaskContext;
}): Promise<FernWorkspace | undefined> {
const workspace = await loadAPIWorkspace({
absolutePathToWorkspace,
absolutePathToWorkspace: absolutePathToAPIDefinition,
context: taskContext,
cliVersion: "DUMMY",
workspaceName: fixture
Expand Down
2 changes: 1 addition & 1 deletion seed/openapi/imdb/custom-overrides/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/openapi/imdb/json-format/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion seed/openapi/imdb/no-custom-config/.inputs/config.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c2e7bbf

Please sign in to comment.