From 1a31c252280fc6dd1037aaa5161a17a52458ffe8 Mon Sep 17 00:00:00 2001 From: Anudeep Date: Sun, 2 Jun 2024 16:42:17 +0530 Subject: [PATCH] fix: testbeats command line mode (#189) * fix: testbeats command line mode * dynamic results path --- .github/workflows/build.yml | 11 ++++++++--- src/index.d.ts | 2 +- src/utils/config.builder.js | 9 ++++++++- test/cli.spec.js | 10 ++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f2f1c3..fb1fba5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 }} \ No newline at end of file + SLACK_MVP_URL: ${{ secrets.SLACK_MVP_URL }} + - uses: actions/upload-artifact@v4 + if: always() + with: + name: results-${{ matrix.os }}-${{ matrix.node-version }} + path: results/ \ No newline at end of file diff --git a/src/index.d.ts b/src/index.d.ts index 8a0846f..0f6210c 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -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; diff --git a/src/utils/config.builder.js b/src/utils/config.builder.js index 19c133e..4a6fe37 100644 --- a/src/utils/config.builder.js +++ b/src/utils/config.builder.js @@ -16,6 +16,7 @@ class ConfigBuilder { } this.#buildConfig(); + this.#buildBeats(); this.#buildResults(); this.#buildTargets(); this.#buildExtensions(); @@ -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); @@ -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() { diff --git a/test/cli.spec.js b/test/cli.spec.js index 3507fce..e6b4111 100644 --- a/test/cli.spec.js +++ b/test/cli.spec.js @@ -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(); + }); + }); + });; \ No newline at end of file