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

Support for Test at Scale Badge, run [TAS] #7612

Merged
merged 15 commits into from
Mar 5, 2022
110 changes: 110 additions & 0 deletions services/tas/tas-tests.service.js
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',
},
Copy link
Member

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

Copy link
Contributor Author

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.

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(),
}).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,
})
}
}
8 changes: 8 additions & 0 deletions services/tas/tas-tests.tester.js
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(),
Copy link
Member

Choose a reason for hiding this comment

The 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 Joi.string() too. There are some validators in services/test-validators.js for testing this type of test summary badge:

const isDefaultTestTotals = makeTestTotalsValidator({
passed: 'passed',
failed: 'failed',
skipped: 'skipped',
})
const isDefaultCompactTestTotals = makeCompactTestTotalsValidator({
passed: '✔',
failed: '✘',
skipped: '➟',
})
const isCustomTestTotals = makeTestTotalsValidator({
passed: 'good',
failed: 'bad',
skipped: 'n/a',
})
const isCustomCompactTestTotals = makeCompactTestTotalsValidator({
passed: '💃',
failed: '🤦‍♀️',
skipped: '🤷',
})

Also can we have a couple of tests for the behaviour in the 401 and 404 cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

})