Skip to content

Commit

Permalink
fix: testbeats command line mode (#189)
Browse files Browse the repository at this point in the history
* fix: testbeats command line mode

* dynamic results path
  • Loading branch information
ASaiAnudeep authored Jun 2, 2024
1 parent 070eeb3 commit 1a31c25
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node-version: [18.x, 20.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -27,8 +27,13 @@ jobs:
- run: npm run test
env:
CI: true
- run: node src/cli.js publish --project testbeats --run 'Unit Tests' --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 }}
SLACK_MVP_URL: ${{ secrets.SLACK_MVP_URL }}
SLACK_MVP_URL: ${{ secrets.SLACK_MVP_URL }}
- uses: actions/upload-artifact@v4
if: always()
with:
name: results-${{ matrix.os }}-${{ matrix.node-version }}
path: results/
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export interface CommandLineOptions {
config?: string;
project?: string;
run?: string;
api_key?: string;
'api-key'?: string;
slack?: string;
teams?: string;
chat?: string;
Expand Down
9 changes: 8 additions & 1 deletion src/utils/config.builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ConfigBuilder {
}

this.#buildConfig();
this.#buildBeats();
this.#buildResults();
this.#buildTargets();
this.#buildExtensions();
Expand All @@ -28,6 +29,12 @@ class ConfigBuilder {
this.config = {};
}

#buildBeats() {
this.config.project = this.opts.project || this.config.project;
this.config.run = this.opts.run || this.config.run;
this.config.api_key = this.opts['api-key'] || this.config.api_key;
}

#buildResults() {
if (this.opts.junit) {
this.#addResults('junit', this.opts.junit);
Expand Down Expand Up @@ -79,7 +86,7 @@ class ConfigBuilder {

#addTarget(name, url) {
this.config.targets = this.config.targets || [];
this.config.targets.push({ name, inputs: { url, title: this.opts.title || '' } })
this.config.targets.push({ name, inputs: { url, title: this.opts.title || '', only_failures: true } })
}

#buildExtensions() {
Expand Down
10 changes: 10 additions & 0 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ describe('CLI', () => {
});
});

it('publish results to beats', (done) => {
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) => {
assert.match(stdout, /🚀 Publishing results to TestBeats Portal/);
assert.match(stdout, /✅ Results published successfully!/);
done();
});
});

});;

0 comments on commit 1a31c25

Please sign in to comment.