Skip to content
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

core: debug config import issue #193

Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- run: npm run test
env:
CI: true
- run: node src/cli.js publish --slack {SLACK_MVP_URL} --title 'Unit Tests' --ci-info --chart-test-summary --junit 'results/junit.xml'
- run: node src/cli.js publish --slack '{SLACK_MVP_URL}' --title 'Unit Tests' --ci-info --chart-test-summary --junit 'results/junit.xml'
if: always()
env:
TEST_BEATS_API_KEY: ${{ secrets.TEST_BEATS_API_KEY }}
Expand Down
7 changes: 2 additions & 5 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ const sade = require('sade');
const prog = sade('testbeats');
const { PublishCommand } = require('./commands/publish.command');
const logger = require('./utils/logger');
const { ConfigBuilder } = require('./utils/config.builder');

prog
.version('2.0.3')
.option('-c, --config', 'path to config file')
.option('-l, --logLevel', 'Log Level', "INFO")
.option('--config', 'path to config file')
.option('--logLevel', 'Log Level', "INFO")
.option('--slack', 'slack webhook url')
.option('--teams', 'teams webhook url')
.option('--chat', 'chat webhook url')
Expand All @@ -30,8 +29,6 @@ prog.command('publish')
.action(async (opts) => {
try {
logger.setLevel(opts.logLevel);
const config_builder = new ConfigBuilder(opts);
config_builder.build();
const publish_command = new PublishCommand(opts);
await publish_command.publish();
} catch (error) {
Expand Down
13 changes: 11 additions & 2 deletions src/commands/publish.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const trp = require('test-results-parser');
const prp = require('performance-results-parser');

const beats = require('../beats');
const { ConfigBuilder } = require('../utils/config.builder');
const target_manager = require('../targets');
const logger = require('../utils/logger');
const { processData } = require('../helpers/helper');
Expand All @@ -19,6 +20,7 @@ class PublishCommand {

async publish() {
logger.info(`🥁 TestBeats v${pkg.version}`);
this.#buildConfig();
this.#validateOptions();
this.#setConfigFromFile();
this.#processConfig();
Expand All @@ -28,6 +30,11 @@ class PublishCommand {
logger.info('✅ Results published successfully!');
}

#buildConfig() {
const config_builder = new ConfigBuilder(this.opts);
config_builder.build();
}

#validateOptions() {
if (!this.opts) {
throw new Error('Missing publish options');
Expand All @@ -42,8 +49,10 @@ class PublishCommand {
const cwd = process.cwd();
const file_path = path.join(cwd, this.opts.config);
try {
this.opts.config = require(path.join(cwd, this.opts.config));
const config_json = require(path.join(cwd, this.opts.config));
this.opts.config = config_json;
} catch (error) {
logger.error({ error }, `Failed to read config file: '${file_path}' with error: '${error.message}'`);
throw new Error(`Config file not found: ${file_path}`);
}
}
Expand All @@ -63,7 +72,7 @@ class PublishCommand {
}

#validateConfig() {
logger.info("🛠️ Validating configuration...")
logger.info("🛠️ Validating configuration...")
for (const config of this.configs) {
this.#validateResults(config);
this.#validateTargets(config);
Expand Down
13 changes: 11 additions & 2 deletions src/utils/config.builder.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const path = require('path');
const logger = require('./logger');

class ConfigBuilder {

/**
Expand All @@ -11,16 +14,22 @@ class ConfigBuilder {
if (!this.opts) {
return;
}
if (this.opts.config) {
if (typeof this.opts.config === 'object') {
return
}
if (this.opts.config && typeof this.opts.config === 'string') {
return;
}

logger.info('🏗 Building config...')
this.#buildConfig();
this.#buildBeats();
this.#buildResults();
this.#buildTargets();
this.#buildExtensions();

logger.debug(`🛠️ Generated Config: \n${JSON.stringify(this.config, null, 2)}`);

this.opts.config = this.config;
}

Expand Down Expand Up @@ -67,7 +76,7 @@ class ConfigBuilder {
this.config.results = [
{
type,
files: [file]
files: [path.join(file)]
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('CLI', () => {
it('publish results with config file', (done) => {
mock.addInteraction('post test-summary to slack');
exec('node src/cli.js publish --config test/data/configs/slack.config.json', (error, stdout, stderr) => {
console.log(stdout);
assert.match(stdout, /✅ Results published successfully!/);
done();
});
Expand All @@ -15,6 +16,7 @@ describe('CLI', () => {
it('publish results with config builder', (done) => {
mock.addInteraction('post test-summary to slack');
exec('node src/cli.js publish --slack http://localhost:9393/message --testng test/data/testng/single-suite.xml', (error, stdout, stderr) => {
console.log(stdout);
assert.match(stdout, /✅ Results published successfully!/);
done();
});
Expand All @@ -23,6 +25,7 @@ describe('CLI', () => {
it('publish results with config builder and extension', (done) => {
mock.addInteraction('post test-summary to teams with qc-test-summary', { quickChartUrl: "https://quickchart.io" });
exec('node src/cli.js publish --teams http://localhost:9393/message --testng test/data/testng/single-suite-failures.xml --chart-test-summary', (error, stdout, stderr) => {
console.log(stdout);
assert.match(stdout, /✅ Results published successfully!/);
done();
});
Expand All @@ -32,6 +35,7 @@ describe('CLI', () => {
mock.addInteraction('post test results to beats');
mock.addInteraction('post test-summary with beats to teams');
exec('node src/cli.js publish --api-key api-key --project project-name --run build-name --teams http://localhost:9393/message --testng test/data/testng/single-suite.xml', (error, stdout, stderr) => {
console.log(stdout);
assert.match(stdout, /🚀 Publishing results to TestBeats Portal/);
assert.match(stdout, /✅ Results published successfully!/);
done();
Expand Down
2 changes: 1 addition & 1 deletion test/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Config', () => {
} catch (err) {
e = err;
}
assert.equal(e.message, 'Missing publish config');
assert.equal(e.message, 'Missing results properties in config');
});

it('should not allow missing config file', async () => {
Expand Down
Loading