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

fix: testbeats command line mode #189

Merged
merged 2 commits into from
Jun 2, 2024
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
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();
});
});

});;
Loading