Skip to content

Commit

Permalink
Cleanup duplicate and commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
leelaprasadv committed Dec 2, 2024
1 parent af8d7a9 commit 5071046
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/commands/generate-config.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ class GenerateConfigCommand {
/**
* TODO: [BETA / Experimental Mode]
* Generates initial TestBests configuration file
*
*/
constructor(opts) {
this.opts = opts
this.answers = {};
this.opts = opts;
this.configPath = '.testbeats.json';
this.config = {};
}

async execute() {
logger.setLevel(this.opts.logLevel);
this.#printBanner()
this.#printBanner();
logger.info(`🚧 Config generation is still in BETA mode, please report any issues at ${pkg.bugs.url}\n`);

await this.#buildConfigFilePath();
Expand All @@ -40,7 +39,7 @@ class GenerateConfigCommand {
v${pkg.version}
Config Generation [BETA]
`
`;
console.log(banner);
}

Expand All @@ -51,7 +50,7 @@ class GenerateConfigCommand {
message: 'Enter path for configuration file :',
initial: '.testbeats.json'
});
this.answers['configPath'] = configPath;
this.configPath = configPath;
}

async #buildTestResultsConfig() {
Expand Down Expand Up @@ -83,7 +82,6 @@ class GenerateConfigCommand {
choices: runnerChoices,
min: 1
});
this.answers['testResults'] = testResults;

// Handle result paths
this.config.results = []
Expand All @@ -97,7 +95,7 @@ class GenerateConfigCommand {
this.config.results.push({
files: path,
type: resultType
})
});
}
}

Expand All @@ -106,7 +104,7 @@ class GenerateConfigCommand {
{ title: 'Slack', value: 'slack' },
{ title: 'Microsoft Teams', value: 'teams' },
{ title: 'Google Chat', value: 'chat' }
]
];

const { includeTargets } = await prompts({
type: 'toggle',
Expand Down Expand Up @@ -160,7 +158,7 @@ class GenerateConfigCommand {
url: `{${webhookEnvVar}}`,
publish: 'test-summary'
}
}
};

if (useExtensions) {
targetConfig.extensions = [];
Expand Down Expand Up @@ -400,11 +398,7 @@ class GenerateConfigCommand {
message: 'Enter project name (optional):'
});

// testBeatsConfig.push({
// api_key: apiKey,
// project
// });
this.config.api_key = this.answers.apiKey;
this.config.api_key = apiKey;
// Add optional fields only if they have values
if (project?.trim()) {
this.config.project = project.trim();
Expand All @@ -424,8 +418,8 @@ class GenerateConfigCommand {
async #saveConfigFile() {
// Write config to file
try {
await fs.writeFile(this.answers.configPath, JSON.stringify(this.config, null, 2));
logger.info(`✅ Configuration file successfully generated: ${this.answers.configPath}`);
await fs.writeFile(this.configPath, JSON.stringify(this.config, null, 2));
logger.info(`✅ Configuration file successfully generated: ${this.configPath}`);
} catch (error) {
throw new Error(`Error: ${error.message}`)
}
Expand Down

0 comments on commit 5071046

Please sign in to comment.