-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Support for Test at Scale Badge, run [TAS] #7612
Changes from 5 commits
4b276b6
c5fb71c
cdfee73
93e9dfe
f56a2b5
070d737
8260f9e
f0d2146
810236e
39ee706
97f1e1d
aee1f14
4342757
dcccf30
98448e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import Joi from 'joi' | ||
import { BaseJsonService } from '../index.js' | ||
import { | ||
testResultQueryParamSchema, | ||
renderTestResultBadge, | ||
} from '../test-results.js' | ||
|
||
const commonAttrs = { | ||
namedParams: { | ||
provider: 'github', | ||
org: 'test-at-scale', | ||
repo: 'badge-demo', | ||
}, | ||
queryParams: { | ||
passed_label: 'passed', | ||
failed_label: 'failed', | ||
skipped_label: 'skipped', | ||
compact_message: null, | ||
}, | ||
} | ||
|
||
const schema = Joi.object({ | ||
badge: Joi.object({ | ||
passed: Joi.number().required(), | ||
failed: Joi.number().required(), | ||
skipped: Joi.number().required(), | ||
total_tests: Joi.number().required(), | ||
status: Joi.string().required(), | ||
calebcartwright marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}).required(), | ||
}).required() | ||
|
||
export default class TasBuildStatus extends BaseJsonService { | ||
static category = 'test-results' | ||
|
||
static route = { | ||
base: 'tas/tests', | ||
pattern: ':provider/:org/:repo', | ||
queryParamSchema: testResultQueryParamSchema, | ||
} | ||
|
||
static examples = [ | ||
{ | ||
title: 'TAS Tests', | ||
staticPreview: this.render({ | ||
passed: 20, | ||
failed: 1, | ||
skipped: 1, | ||
total: 22, | ||
}), | ||
...commonAttrs, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { label: 'tests' } | ||
|
||
static render({ | ||
passed, | ||
failed, | ||
skipped, | ||
total, | ||
passedLabel, | ||
failedLabel, | ||
skippedLabel, | ||
isCompact, | ||
}) { | ||
return renderTestResultBadge({ | ||
passed, | ||
failed, | ||
skipped, | ||
total, | ||
passedLabel, | ||
failedLabel, | ||
skippedLabel, | ||
isCompact, | ||
}) | ||
} | ||
|
||
async fetch({ provider, org, repo }) { | ||
return this._requestJson({ | ||
schema, | ||
url: `https://api.tas.lambdatest.com/repo/badge?git_provider=${provider}&org=${org}&repo=${repo}`, | ||
errorMessages: { | ||
401: 'private application not supported', | ||
404: 'application not found', | ||
}, | ||
}) | ||
} | ||
|
||
async handle( | ||
{ provider, org, repo }, | ||
{ | ||
compact_message: compactMessage, | ||
passed_label: passedLabel, | ||
failed_label: failedLabel, | ||
skipped_label: skippedLabel, | ||
} | ||
) { | ||
const { badge } = await this.fetch({ provider, org, repo }) | ||
return this.constructor.render({ | ||
passed: badge.passed, | ||
failed: badge.failed, | ||
skipped: badge.skipped, | ||
total: badge.total_tests, | ||
passedLabel, | ||
failedLabel, | ||
skippedLabel, | ||
isCompact: compactMessage !== undefined, | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||||||||||||||||||||||||||||||||||||
import Joi from 'joi' | ||||||||||||||||||||||||||||||||||||||||||
import { createServiceTester } from '../tester.js' | ||||||||||||||||||||||||||||||||||||||||||
export const t = await createServiceTester() | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
t.create('tas tests').get('/github/tasdemo/axios.json').expectBadge({ | ||||||||||||||||||||||||||||||||||||||||||
label: 'tests', | ||||||||||||||||||||||||||||||||||||||||||
message: Joi.string(), | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this more specific. This isn't really a useful test as an error message will match shields/services/test-validators.js Lines 135 to 154 in 6e80336
Also can we have a couple of tests for the behaviour in the 401 and 404 cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||||||||||||||||||||||||||||||||||||||||||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this before but is this a valid, public project? I'm not seeing it on GitHub and the badge is unsurprisingly showing a not found. We really like to have these examples be valid projects so that users can actually see/work with them in the modal window.
If it's something you all are planning on setting up in the near future that's alright, but otherwise it would probably be better to swap in a real target
https://shields-staging-pr-7612.herokuapp.com/tas/tests/github/test-at-scale/badge-demo?compact_message

Using the same target as the tests would suffice too:
https://shields-staging-pr-7612.herokuapp.com/tas/tests/github/tasdemo/axios

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@calebcartwright Thanks for pointing out. I've updated the example project.