Skip to content

Refactor cli tests - #2287

Open
Ford544 wants to merge 1 commit into
mainfrom
test_refactor
Open

Refactor cli tests#2287
Ford544 wants to merge 1 commit into
mainfrom
test_refactor

Conversation

@Ford544

@Ford544 Ford544 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator
  • extracted common operations to functions in index_test_base
  • extracted shared setup to beforeEach in some suites
  • made suite structure more consistent

Note: this PR does not cover splitting larger test files into several seperate ones, this is planned but will be done in a seperate PR.

@Ford544
Ford544 requested a review from apilaskowski September 8, 2026 14:52
@Ford544
Ford544 requested a review from a team as a code owner September 8, 2026 14:52
Base automatically changed from integration-tests-config to main September 8, 2026 19:01
* extracted common operations to functions in index_test_base
* extracted shared setup to beforeEach in some suites
* made suite structure more consistent
Comment thread cli/index_test_base.ts
...workflowSettings,
...workflowSettingsOverrides
});
fs.writeFileSync(workflowSettingsPath, dumpYaml(workflowSettingsNew));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direct YAML dumping of a protobufjs instance: dumpYaml(workflowSettingsNew) dumps the class instance directly without calling dataform.WorkflowSettings.toObject(..., { enums: String }). This can serialize protobuf internal properties or dump enum values as numeric integers instead of string names.

Comment thread cli/index_test_base.ts
loadYaml(fs.readFileSync(workflowSettingsPath, "utf8"))
);
const workflowSettingsNew = dataform.WorkflowSettings.create({
...workflowSettings,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object spread on proto instance: Spreading ...workflowSettings into dataform.WorkflowSettings.create(...) copies instance-level own properties rather than pure schema values. Spreading the plain object loaded from YAML is cleaner.

Comment thread cli/index_test_base.ts
fs.writeFileSync(fullPath, content);
}

export async function alterWorkflowSettings(projectDir: string, workflowSettingsOverrides: Partial<dataform.IWorkflowSettings>): Promise<void> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All file system calls are synchronous; no await is used

Comment thread cli/index_test_base.ts
fs.writeFileSync(fullPath, content);
}

export async function alterWorkflowSettings(projectDir: string, workflowSettingsOverrides: Partial<dataform.IWorkflowSettings>): Promise<void> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested fix accommodating mentioned issues:

    export function alterWorkflowSettings(
      projectDir: string,
      workflowSettingsOverrides: Partial<dataform.IWorkflowSettings>
    ): void {
      const workflowSettingsPath = path.join(projectDir, "workflow_settings.yaml");
      const existingSettings = loadYaml(fs.readFileSync(workflowSettingsPath, "utf8")) as dataform.IWorkflowSettings;
      const workflowSettings = dataform.WorkflowSettings.create({
        ...existingSettings,
        ...workflowSettingsOverrides
      });
      fs.writeFileSync(
        workflowSettingsPath,
        dumpYaml(dataform.WorkflowSettings.toObject(workflowSettings, { enums: String }))
      );
    }

This also aligns with what is currently proposed in setupProject.

Comment thread cli/index_help_test.ts

test("shows help for 'init' command", async () => {
const result = await getProcessResult(execFile(nodePath, [cliEntryPointPath, "help", "init"]));
const result = await runCli("help", "init");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here "init" is passed as dir, which is second parameter of runCli.

Either pass subcommands via options or provide an overload. I am not a fan of argsOrDir options, so lets figure out a way to solve this cleanly.

Comment thread cli/index_test_base.ts
stderr: string;
}> {
const args = [cliEntryPointPath, cmd, ...(dir !== undefined ? [dir] : []), ...options];
return await getProcessResult(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can drop await here, and return getProcessResult(...) will be sufficient.

Comment thread cli/index_run_e2e_test.ts
])
);
beforeEach("setup test project", async () => {
projectDir = tmpDirFixture.createNewTmpDir()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ;

Comment thread cli/index_run_e2e_test.ts

test("with --disable-assertions flag", async () => {
await setUpWorkflowSettings(false);
await alterWorkflowSettings(projectDir, { disableAssertions : false });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter should have fixed that, but lets be consistent and not have spaces before colons.

Comment thread cli/index_run_e2e_test.ts

test("with --job-labels flag", async () => {
await setUpWorkflowSettings(false);
await alterWorkflowSettings(projectDir, { disableAssertions : false });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no space before colon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants