upgrade to prettier 2 (#5051)
* arrowParens: avoid * remove trailingComma setting
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
semi: false
|
||||
singleQuote: true
|
||||
trailingComma: es5
|
||||
bracketSpacing: true
|
||||
endOfLine: lf
|
||||
arrowParens: avoid
|
||||
|
||||
@@ -13,13 +13,13 @@ function runCli(args) {
|
||||
})
|
||||
}
|
||||
|
||||
describe('The CLI', function() {
|
||||
it('should provide a help message', async function() {
|
||||
describe('The CLI', function () {
|
||||
it('should provide a help message', async function () {
|
||||
const { stdout } = await runCli([])
|
||||
expect(stdout).to.startWith('Usage')
|
||||
})
|
||||
|
||||
it('should produce default badges', async function() {
|
||||
it('should produce default badges', async function () {
|
||||
const { stdout } = await runCli(['cactus', 'grown'])
|
||||
expect(stdout)
|
||||
.to.satisfy(isSvg)
|
||||
@@ -27,15 +27,13 @@ describe('The CLI', function() {
|
||||
.and.to.include('grown')
|
||||
})
|
||||
|
||||
it('should produce colorschemed badges', async function() {
|
||||
it('should produce colorschemed badges', async function () {
|
||||
const { stdout } = await runCli(['cactus', 'grown', ':green'])
|
||||
expect(stdout).to.satisfy(isSvg)
|
||||
})
|
||||
|
||||
it('should produce right-color badges', async function() {
|
||||
it('should produce right-color badges', async function () {
|
||||
const { stdout } = await runCli(['cactus', 'grown', '#abcdef'])
|
||||
expect(stdout)
|
||||
.to.satisfy(isSvg)
|
||||
.and.to.include('#abcdef')
|
||||
expect(stdout).to.satisfy(isSvg).and.to.include('#abcdef')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -131,10 +131,7 @@ function renderBadge({ links, leftWidth, rightWidth, height }, main) {
|
||||
}
|
||||
|
||||
function stripXmlWhitespace(xml) {
|
||||
return xml
|
||||
.replace(/>\s+/g, '>')
|
||||
.replace(/<\s+/g, '<')
|
||||
.trim()
|
||||
return xml.replace(/>\s+/g, '>').replace(/<\s+/g, '<').trim()
|
||||
}
|
||||
|
||||
class Badge {
|
||||
@@ -595,10 +592,11 @@ function forTheBadge({
|
||||
<g fill="#fff" text-anchor="middle" ${fontFamily} text-rendering="geometricPrecision" font-size="100">
|
||||
${renderedLogo}
|
||||
${hasLabel ? renderLabelText() : ''}
|
||||
<text x="${(labelWidth + messageWidth / 2) *
|
||||
10}" y="175" font-weight="bold" transform="scale(.1)" textLength="${(messageWidth -
|
||||
24) *
|
||||
10}">
|
||||
<text x="${
|
||||
(labelWidth + messageWidth / 2) * 10
|
||||
}" y="175" font-weight="bold" transform="scale(.1)" textLength="${
|
||||
(messageWidth - 24) * 10
|
||||
}">
|
||||
${escapeXml(message)}</text>
|
||||
</g>`
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ function _validate(format) {
|
||||
}
|
||||
|
||||
const stringFields = ['labelColor', 'color', 'message', 'label']
|
||||
stringFields.forEach(function(field) {
|
||||
stringFields.forEach(function (field) {
|
||||
if (field in format && typeof format[field] !== 'string') {
|
||||
throw new ValidationError(`Field \`${field}\` must be of type string`)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ const { expect } = require('chai')
|
||||
const isSvg = require('is-svg')
|
||||
const { makeBadge, ValidationError } = require('.')
|
||||
|
||||
describe('makeBadge function', function() {
|
||||
it('should produce badge with valid input', function() {
|
||||
describe('makeBadge function', function () {
|
||||
it('should produce badge with valid input', function () {
|
||||
expect(
|
||||
makeBadge({
|
||||
label: 'build',
|
||||
@@ -27,7 +27,7 @@ describe('makeBadge function', function() {
|
||||
).to.satisfy(isSvg)
|
||||
})
|
||||
|
||||
it('should throw a ValidationError with invalid inputs', function() {
|
||||
it('should throw a ValidationError with invalid inputs', function () {
|
||||
;[null, undefined, 7, 'foo', 4.25].forEach(x => {
|
||||
console.log(x)
|
||||
expect(() => makeBadge(x)).to.throw(
|
||||
|
||||
@@ -16,8 +16,8 @@ function testColor(color = '', colorAttr = 'color') {
|
||||
).color
|
||||
}
|
||||
|
||||
describe('The badge generator', function() {
|
||||
describe('color test', function() {
|
||||
describe('The badge generator', function () {
|
||||
describe('color test', function () {
|
||||
test(testColor, () => {
|
||||
// valid hex
|
||||
forCases([
|
||||
@@ -69,14 +69,14 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('color aliases', function() {
|
||||
describe('color aliases', function () {
|
||||
test(testColor, () => {
|
||||
forCases([given('#4c1', 'color')]).expect('#4c1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('SVG', function() {
|
||||
it('should produce SVG', function() {
|
||||
describe('SVG', function () {
|
||||
it('should produce SVG', function () {
|
||||
const svg = makeBadge({ text: ['cactus', 'grown'], format: 'svg' })
|
||||
expect(svg)
|
||||
.to.satisfy(isSvg)
|
||||
@@ -84,14 +84,14 @@ describe('The badge generator', function() {
|
||||
.and.to.include('grown')
|
||||
})
|
||||
|
||||
it('should match snapshot', function() {
|
||||
it('should match snapshot', function () {
|
||||
const svg = makeBadge({ text: ['cactus', 'grown'], format: 'svg' })
|
||||
snapshot(svg)
|
||||
})
|
||||
})
|
||||
|
||||
describe('JSON', function() {
|
||||
it('should produce the expected JSON', function() {
|
||||
describe('JSON', function () {
|
||||
it('should produce the expected JSON', function () {
|
||||
const json = makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
format: 'json',
|
||||
@@ -106,7 +106,7 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should replace undefined svg template with "flat"', function() {
|
||||
it('should replace undefined svg template with "flat"', function () {
|
||||
const jsonBadgeWithUnknownStyle = makeBadge({
|
||||
text: ['name', 'Bob'],
|
||||
format: 'svg',
|
||||
@@ -121,7 +121,7 @@ describe('The badge generator', function() {
|
||||
.and.to.satisfy(isSvg)
|
||||
})
|
||||
|
||||
it('should fail with unknown svg template', function() {
|
||||
it('should fail with unknown svg template', function () {
|
||||
expect(() =>
|
||||
makeBadge({
|
||||
text: ['name', 'Bob'],
|
||||
@@ -132,8 +132,8 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('"flat" template badge generation', function() {
|
||||
it('should match snapshots: message/label, no logo', function() {
|
||||
describe('"flat" template badge generation', function () {
|
||||
it('should match snapshots: message/label, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -145,7 +145,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with logo', function() {
|
||||
it('should match snapshots: message/label, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -158,7 +158,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, no logo', function() {
|
||||
it('should match snapshots: message only, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -169,7 +169,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo', function() {
|
||||
it('should match snapshots: message only, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -181,7 +181,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo and labelColor', function() {
|
||||
it('should match snapshots: message only, with logo and labelColor', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -194,7 +194,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with links', function() {
|
||||
it('should match snapshots: message/label, with links', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -208,8 +208,8 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('"flat-square" template badge generation', function() {
|
||||
it('should match snapshots: message/label, no logo', function() {
|
||||
describe('"flat-square" template badge generation', function () {
|
||||
it('should match snapshots: message/label, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -221,7 +221,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with logo', function() {
|
||||
it('should match snapshots: message/label, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -234,7 +234,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, no logo', function() {
|
||||
it('should match snapshots: message only, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -245,7 +245,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo', function() {
|
||||
it('should match snapshots: message only, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -257,7 +257,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo and labelColor', function() {
|
||||
it('should match snapshots: message only, with logo and labelColor', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -270,7 +270,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with links', function() {
|
||||
it('should match snapshots: message/label, with links', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -284,8 +284,8 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('"plastic" template badge generation', function() {
|
||||
it('should match snapshots: message/label, no logo', function() {
|
||||
describe('"plastic" template badge generation', function () {
|
||||
it('should match snapshots: message/label, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -297,7 +297,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with logo', function() {
|
||||
it('should match snapshots: message/label, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -310,7 +310,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, no logo', function() {
|
||||
it('should match snapshots: message only, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -321,7 +321,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo', function() {
|
||||
it('should match snapshots: message only, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -333,7 +333,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo and labelColor', function() {
|
||||
it('should match snapshots: message only, with logo and labelColor', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -346,7 +346,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with links', function() {
|
||||
it('should match snapshots: message/label, with links', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -360,31 +360,27 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('"for-the-badge" template badge generation', function() {
|
||||
describe('"for-the-badge" template badge generation', function () {
|
||||
// https://github.com/badges/shields/issues/1280
|
||||
it('numbers should produce a string', function() {
|
||||
it('numbers should produce a string', function () {
|
||||
const svg = makeBadge({
|
||||
text: [1998, 1999],
|
||||
format: 'svg',
|
||||
template: 'for-the-badge',
|
||||
})
|
||||
expect(svg)
|
||||
.to.include('1998')
|
||||
.and.to.include('1999')
|
||||
expect(svg).to.include('1998').and.to.include('1999')
|
||||
})
|
||||
|
||||
it('lowercase/mixedcase string should produce uppercase string', function() {
|
||||
it('lowercase/mixedcase string should produce uppercase string', function () {
|
||||
const svg = makeBadge({
|
||||
text: ['Label', '1 string'],
|
||||
format: 'svg',
|
||||
template: 'for-the-badge',
|
||||
})
|
||||
expect(svg)
|
||||
.to.include('LABEL')
|
||||
.and.to.include('1 STRING')
|
||||
expect(svg).to.include('LABEL').and.to.include('1 STRING')
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, no logo', function() {
|
||||
it('should match snapshots: message/label, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -396,7 +392,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with logo', function() {
|
||||
it('should match snapshots: message/label, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -409,7 +405,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, no logo', function() {
|
||||
it('should match snapshots: message only, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -420,7 +416,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo', function() {
|
||||
it('should match snapshots: message only, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -432,7 +428,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo and labelColor', function() {
|
||||
it('should match snapshots: message only, with logo and labelColor', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -445,7 +441,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with links', function() {
|
||||
it('should match snapshots: message/label, with links', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -459,31 +455,27 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('"social" template badge generation', function() {
|
||||
it('should produce capitalized string for badge key', function() {
|
||||
describe('"social" template badge generation', function () {
|
||||
it('should produce capitalized string for badge key', function () {
|
||||
const svg = makeBadge({
|
||||
text: ['some-key', 'some-value'],
|
||||
format: 'svg',
|
||||
template: 'social',
|
||||
})
|
||||
expect(svg)
|
||||
.to.include('Some-key')
|
||||
.and.to.include('some-value')
|
||||
expect(svg).to.include('Some-key').and.to.include('some-value')
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/issues/1606
|
||||
it('should handle empty strings used as badge keys', function() {
|
||||
it('should handle empty strings used as badge keys', function () {
|
||||
const svg = makeBadge({
|
||||
text: ['', 'some-value'],
|
||||
format: 'json',
|
||||
template: 'social',
|
||||
})
|
||||
expect(svg)
|
||||
.to.include('""')
|
||||
.and.to.include('some-value')
|
||||
expect(svg).to.include('""').and.to.include('some-value')
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, no logo', function() {
|
||||
it('should match snapshots: message/label, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -495,7 +487,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with logo', function() {
|
||||
it('should match snapshots: message/label, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -508,7 +500,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, no logo', function() {
|
||||
it('should match snapshots: message only, no logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -519,7 +511,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo', function() {
|
||||
it('should match snapshots: message only, with logo', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -531,7 +523,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message only, with logo and labelColor', function() {
|
||||
it('should match snapshots: message only, with logo and labelColor', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['', 'grown'],
|
||||
@@ -544,7 +536,7 @@ describe('The badge generator', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should match snapshots: message/label, with links', function() {
|
||||
it('should match snapshots: message/label, with links', function () {
|
||||
snapshot(
|
||||
makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
@@ -558,8 +550,8 @@ describe('The badge generator', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('badges with logos should always produce the same badge', function() {
|
||||
it('badge with logo', function() {
|
||||
describe('badges with logos should always produce the same badge', function () {
|
||||
it('badge with logo', function () {
|
||||
const svg = makeBadge({
|
||||
text: ['label', 'message'],
|
||||
format: 'svg',
|
||||
|
||||
@@ -10,7 +10,7 @@ const {
|
||||
dynamicBadgeUrl,
|
||||
} = require('./make-badge-url')
|
||||
|
||||
describe('Badge URL generation functions', function() {
|
||||
describe('Badge URL generation functions', function () {
|
||||
test(badgeUrlFromPath, () => {
|
||||
given({
|
||||
baseUrl: 'http://example.com',
|
||||
|
||||
@@ -5,20 +5,20 @@ const { test, given, forCases } = require('sazerac')
|
||||
const { AuthHelper } = require('./auth-helper')
|
||||
const { InvalidParameter } = require('./errors')
|
||||
|
||||
describe('AuthHelper', function() {
|
||||
describe('constructor checks', function() {
|
||||
it('throws without userKey or passKey', function() {
|
||||
describe('AuthHelper', function () {
|
||||
describe('constructor checks', function () {
|
||||
it('throws without userKey or passKey', function () {
|
||||
expect(() => new AuthHelper({}, {})).to.throw(
|
||||
Error,
|
||||
'Expected userKey or passKey to be set'
|
||||
)
|
||||
})
|
||||
it('throws without serviceKey or authorizedOrigins', function() {
|
||||
it('throws without serviceKey or authorizedOrigins', function () {
|
||||
expect(
|
||||
() => new AuthHelper({ userKey: 'myci_user', passKey: 'myci_pass' }, {})
|
||||
).to.throw(Error, 'Expected authorizedOrigins or serviceKey to be set')
|
||||
})
|
||||
it('throws when authorizedOrigins is not an array', function() {
|
||||
it('throws when authorizedOrigins is not an array', function () {
|
||||
expect(
|
||||
() =>
|
||||
new AuthHelper(
|
||||
@@ -33,7 +33,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('isValid', function() {
|
||||
describe('isValid', function () {
|
||||
function validate(config, privateConfig) {
|
||||
return new AuthHelper(
|
||||
{ authorizedOrigins: ['https://example.test'], ...config },
|
||||
@@ -89,7 +89,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_basicAuth', function() {
|
||||
describe('_basicAuth', function () {
|
||||
function validate(config, privateConfig) {
|
||||
return new AuthHelper(
|
||||
{ authorizedOrigins: ['https://example.test'], ...config },
|
||||
@@ -128,7 +128,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('_isInsecureSslRequest', function() {
|
||||
describe('_isInsecureSslRequest', function () {
|
||||
test(AuthHelper._isInsecureSslRequest, () => {
|
||||
forCases([
|
||||
given({ url: 'http://example.test' }),
|
||||
@@ -146,31 +146,31 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('enforceStrictSsl', function() {
|
||||
describe('enforceStrictSsl', function () {
|
||||
const authConfig = {
|
||||
userKey: 'myci_user',
|
||||
passKey: 'myci_pass',
|
||||
serviceKey: 'myci',
|
||||
}
|
||||
|
||||
context('by default', function() {
|
||||
context('by default', function () {
|
||||
const authHelper = new AuthHelper(authConfig, {
|
||||
public: {
|
||||
services: { myci: { authorizedOrigins: ['http://myci.test'] } },
|
||||
},
|
||||
private: { myci_user: 'admin', myci_pass: 'abc123' },
|
||||
})
|
||||
it('does not throw for secure requests', function() {
|
||||
it('does not throw for secure requests', function () {
|
||||
expect(() => authHelper.enforceStrictSsl({})).not.to.throw()
|
||||
})
|
||||
it('throws for insecure requests', function() {
|
||||
it('throws for insecure requests', function () {
|
||||
expect(() =>
|
||||
authHelper.enforceStrictSsl({ options: { strictSSL: false } })
|
||||
).to.throw(InvalidParameter)
|
||||
})
|
||||
})
|
||||
|
||||
context("when strict SSL isn't required", function() {
|
||||
context("when strict SSL isn't required", function () {
|
||||
const authHelper = new AuthHelper(authConfig, {
|
||||
public: {
|
||||
services: {
|
||||
@@ -182,10 +182,10 @@ describe('AuthHelper', function() {
|
||||
},
|
||||
private: { myci_user: 'admin', myci_pass: 'abc123' },
|
||||
})
|
||||
it('does not throw for secure requests', function() {
|
||||
it('does not throw for secure requests', function () {
|
||||
expect(() => authHelper.enforceStrictSsl({})).not.to.throw()
|
||||
})
|
||||
it('does not throw for insecure requests', function() {
|
||||
it('does not throw for insecure requests', function () {
|
||||
expect(() =>
|
||||
authHelper.enforceStrictSsl({ options: { strictSSL: false } })
|
||||
).not.to.throw()
|
||||
@@ -193,14 +193,14 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('shouldAuthenticateRequest', function() {
|
||||
describe('shouldAuthenticateRequest', function () {
|
||||
const authConfig = {
|
||||
userKey: 'myci_user',
|
||||
passKey: 'myci_pass',
|
||||
serviceKey: 'myci',
|
||||
}
|
||||
|
||||
context('by default', function() {
|
||||
context('by default', function () {
|
||||
const authHelper = new AuthHelper(authConfig, {
|
||||
public: {
|
||||
services: {
|
||||
@@ -213,12 +213,12 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
const shouldAuthenticateRequest = requestOptions =>
|
||||
authHelper.shouldAuthenticateRequest(requestOptions)
|
||||
describe('a secure request to an authorized origin', function() {
|
||||
describe('a secure request to an authorized origin', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
given({ url: 'https://myci.test/api' }).expect(true)
|
||||
})
|
||||
})
|
||||
describe('an insecure request', function() {
|
||||
describe('an insecure request', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
given({
|
||||
url: 'https://myci.test/api',
|
||||
@@ -226,7 +226,7 @@ describe('AuthHelper', function() {
|
||||
}).expect(false)
|
||||
})
|
||||
})
|
||||
describe('a request to an unauthorized origin', function() {
|
||||
describe('a request to an unauthorized origin', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
forCases([
|
||||
given({ url: 'http://myci.test/api' }),
|
||||
@@ -237,7 +237,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when auth over insecure SSL is allowed', function() {
|
||||
context('when auth over insecure SSL is allowed', function () {
|
||||
const authHelper = new AuthHelper(authConfig, {
|
||||
public: {
|
||||
services: {
|
||||
@@ -251,12 +251,12 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
const shouldAuthenticateRequest = requestOptions =>
|
||||
authHelper.shouldAuthenticateRequest(requestOptions)
|
||||
describe('a secure request to an authorized origin', function() {
|
||||
describe('a secure request to an authorized origin', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
given({ url: 'https://myci.test' }).expect(true)
|
||||
})
|
||||
})
|
||||
describe('an insecure request', function() {
|
||||
describe('an insecure request', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
given({
|
||||
url: 'https://myci.test',
|
||||
@@ -264,7 +264,7 @@ describe('AuthHelper', function() {
|
||||
}).expect(true)
|
||||
})
|
||||
})
|
||||
describe('a request to an unauthorized origin', function() {
|
||||
describe('a request to an unauthorized origin', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
forCases([
|
||||
given({ url: 'http://myci.test' }),
|
||||
@@ -275,7 +275,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when the service is partly configured', function() {
|
||||
context('when the service is partly configured', function () {
|
||||
const authHelper = new AuthHelper(authConfig, {
|
||||
public: {
|
||||
services: {
|
||||
@@ -289,7 +289,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
const shouldAuthenticateRequest = requestOptions =>
|
||||
authHelper.shouldAuthenticateRequest(requestOptions)
|
||||
describe('a secure request to an authorized origin', function() {
|
||||
describe('a secure request to an authorized origin', function () {
|
||||
test(shouldAuthenticateRequest, () => {
|
||||
given({ url: 'https://myci.test' }).expect(false)
|
||||
})
|
||||
@@ -297,7 +297,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('withBasicAuth', function() {
|
||||
describe('withBasicAuth', function () {
|
||||
const authHelper = new AuthHelper(
|
||||
{
|
||||
userKey: 'myci_user',
|
||||
@@ -318,7 +318,7 @@ describe('AuthHelper', function() {
|
||||
const withBasicAuth = requestOptions =>
|
||||
authHelper.withBasicAuth(requestOptions)
|
||||
|
||||
describe('authenticates a secure request to an authorized origin', function() {
|
||||
describe('authenticates a secure request to an authorized origin', function () {
|
||||
test(withBasicAuth, () => {
|
||||
given({
|
||||
url: 'https://myci.test/api',
|
||||
@@ -343,7 +343,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('does not authenticate a request to an unauthorized origin', function() {
|
||||
describe('does not authenticate a request to an unauthorized origin', function () {
|
||||
test(withBasicAuth, () => {
|
||||
given({
|
||||
url: 'https://other.test/api',
|
||||
@@ -364,7 +364,7 @@ describe('AuthHelper', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('throws on an insecure SSL request', function() {
|
||||
describe('throws on an insecure SSL request', function () {
|
||||
expect(() =>
|
||||
withBasicAuth({
|
||||
url: 'https://myci.test/api',
|
||||
|
||||
@@ -36,10 +36,10 @@ class DummyGraphqlService extends BaseGraphqlService {
|
||||
}
|
||||
}
|
||||
|
||||
describe('BaseGraphqlService', function() {
|
||||
describe('Making requests', function() {
|
||||
describe('BaseGraphqlService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '{"some": "json"}',
|
||||
@@ -48,7 +48,7 @@ describe('BaseGraphqlService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function() {
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
await DummyGraphqlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ handleInternalErrors: false }
|
||||
@@ -64,7 +64,7 @@ describe('BaseGraphqlService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function() {
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
class WithOptions extends DummyGraphqlService {
|
||||
async handle() {
|
||||
const { value } = await this._requestGraphql({
|
||||
@@ -98,8 +98,8 @@ describe('BaseGraphqlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Making badges', function() {
|
||||
it('handles valid json responses', async function() {
|
||||
describe('Making badges', function () {
|
||||
it('handles valid json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '{"requiredString": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
@@ -114,7 +114,7 @@ describe('BaseGraphqlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles json responses which do not match the schema', async function() {
|
||||
it('handles json responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '{"unexpectedKey": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
@@ -131,7 +131,7 @@ describe('BaseGraphqlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles unparseable json responses', async function() {
|
||||
it('handles unparseable json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: 'not json',
|
||||
res: { statusCode: 200 },
|
||||
@@ -149,8 +149,8 @@ describe('BaseGraphqlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Error handling', function() {
|
||||
it('handles generic error', async function() {
|
||||
describe('Error handling', function () {
|
||||
it('handles generic error', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '{ "errors": [ { "message": "oh noes!!" } ] }',
|
||||
res: { statusCode: 200 },
|
||||
@@ -167,7 +167,7 @@ describe('BaseGraphqlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles custom error', async function() {
|
||||
it('handles custom error', async function () {
|
||||
class WithErrorHandler extends DummyGraphqlService {
|
||||
async handle() {
|
||||
const { requiredString } = await this._requestGraphql({
|
||||
@@ -178,7 +178,7 @@ describe('BaseGraphqlService', function() {
|
||||
requiredString
|
||||
}
|
||||
`,
|
||||
transformErrors: function(errors) {
|
||||
transformErrors: function (errors) {
|
||||
if (errors[0].message === 'oh noes!!') {
|
||||
return new InvalidResponse({
|
||||
prettyMessage: 'a terrible thing has happened',
|
||||
|
||||
@@ -29,10 +29,10 @@ class DummyJsonService extends BaseJsonService {
|
||||
}
|
||||
}
|
||||
|
||||
describe('BaseJsonService', function() {
|
||||
describe('Making requests', function() {
|
||||
describe('BaseJsonService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '{"some": "json"}',
|
||||
@@ -41,7 +41,7 @@ describe('BaseJsonService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function() {
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
await DummyJsonService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ handleInternalErrors: false }
|
||||
@@ -55,7 +55,7 @@ describe('BaseJsonService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function() {
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
class WithOptions extends DummyJsonService {
|
||||
async handle() {
|
||||
const { value } = await this._requestJson({
|
||||
@@ -83,8 +83,8 @@ describe('BaseJsonService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Making badges', function() {
|
||||
it('handles valid json responses', async function() {
|
||||
describe('Making badges', function () {
|
||||
it('handles valid json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '{"requiredString": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
@@ -99,7 +99,7 @@ describe('BaseJsonService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles json responses which do not match the schema', async function() {
|
||||
it('handles json responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '{"unexpectedKey": "some-string"}',
|
||||
res: { statusCode: 200 },
|
||||
@@ -116,7 +116,7 @@ describe('BaseJsonService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles unparseable json responses', async function() {
|
||||
it('handles unparseable json responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: 'not json',
|
||||
res: { statusCode: 200 },
|
||||
|
||||
@@ -33,7 +33,7 @@ class DummySvgScrapingService extends BaseSvgScrapingService {
|
||||
}
|
||||
}
|
||||
|
||||
describe('BaseSvgScrapingService', function() {
|
||||
describe('BaseSvgScrapingService', function () {
|
||||
const exampleLabel = 'this is the label'
|
||||
const exampleMessage = 'this is the result!'
|
||||
const exampleSvg = makeExampleSvg({
|
||||
@@ -41,17 +41,17 @@ describe('BaseSvgScrapingService', function() {
|
||||
message: exampleMessage,
|
||||
})
|
||||
|
||||
describe('valueFromSvgBadge', function() {
|
||||
it('should find the correct value', function() {
|
||||
describe('valueFromSvgBadge', function () {
|
||||
it('should find the correct value', function () {
|
||||
expect(BaseSvgScrapingService.valueFromSvgBadge(exampleSvg)).to.equal(
|
||||
exampleMessage
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Making requests', function() {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: exampleSvg,
|
||||
@@ -60,7 +60,7 @@ describe('BaseSvgScrapingService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest with the expected header', async function() {
|
||||
it('invokes _sendAndCacheRequest with the expected header', async function () {
|
||||
await DummySvgScrapingService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ handleInternalErrors: false }
|
||||
@@ -74,7 +74,7 @@ describe('BaseSvgScrapingService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function() {
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
class WithCustomOptions extends DummySvgScrapingService {
|
||||
async handle() {
|
||||
const { message } = await this._requestSvg({
|
||||
@@ -105,8 +105,8 @@ describe('BaseSvgScrapingService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Making badges', function() {
|
||||
it('handles valid svg responses', async function() {
|
||||
describe('Making badges', function () {
|
||||
it('handles valid svg responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: exampleSvg,
|
||||
res: { statusCode: 200 },
|
||||
@@ -121,7 +121,7 @@ describe('BaseSvgScrapingService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('allows overriding the valueMatcher', async function() {
|
||||
it('allows overriding the valueMatcher', async function () {
|
||||
class WithValueMatcher extends BaseSvgScrapingService {
|
||||
static get route() {
|
||||
return {}
|
||||
@@ -149,7 +149,7 @@ describe('BaseSvgScrapingService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles unparseable svg responses', async function() {
|
||||
it('handles unparseable svg responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: 'not svg yo',
|
||||
res: { statusCode: 200 },
|
||||
|
||||
@@ -29,10 +29,10 @@ class DummyXmlService extends BaseXmlService {
|
||||
}
|
||||
}
|
||||
|
||||
describe('BaseXmlService', function() {
|
||||
describe('Making requests', function() {
|
||||
describe('BaseXmlService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: '<requiredString>some-string</requiredString>',
|
||||
@@ -41,7 +41,7 @@ describe('BaseXmlService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function() {
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
await DummyXmlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ handleInternalErrors: false }
|
||||
@@ -55,7 +55,7 @@ describe('BaseXmlService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function() {
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
class WithCustomOptions extends BaseXmlService {
|
||||
static get route() {
|
||||
return {}
|
||||
@@ -87,8 +87,8 @@ describe('BaseXmlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Making badges', function() {
|
||||
it('handles valid xml responses', async function() {
|
||||
describe('Making badges', function () {
|
||||
it('handles valid xml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '<requiredString>some-string</requiredString>',
|
||||
res: { statusCode: 200 },
|
||||
@@ -103,7 +103,7 @@ describe('BaseXmlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('parses XML response with custom parser options', async function() {
|
||||
it('parses XML response with custom parser options', async function () {
|
||||
const customParserOption = { trimValues: false }
|
||||
class DummyXmlServiceWithParserOption extends DummyXmlService {
|
||||
async handle() {
|
||||
@@ -130,7 +130,7 @@ describe('BaseXmlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles xml responses which do not match the schema', async function() {
|
||||
it('handles xml responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '<unexpectedAttribute>some-string</unexpectedAttribute>',
|
||||
res: { statusCode: 200 },
|
||||
@@ -147,7 +147,7 @@ describe('BaseXmlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles unparseable xml responses', async function() {
|
||||
it('handles unparseable xml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: 'not xml',
|
||||
res: { statusCode: 200 },
|
||||
|
||||
@@ -45,10 +45,10 @@ foo: bar
|
||||
foo: baz
|
||||
`
|
||||
|
||||
describe('BaseYamlService', function() {
|
||||
describe('Making requests', function() {
|
||||
describe('BaseYamlService', function () {
|
||||
describe('Making requests', function () {
|
||||
let sendAndCacheRequest
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sendAndCacheRequest = sinon.stub().returns(
|
||||
Promise.resolve({
|
||||
buffer: expectedYaml,
|
||||
@@ -57,7 +57,7 @@ describe('BaseYamlService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('invokes _sendAndCacheRequest', async function() {
|
||||
it('invokes _sendAndCacheRequest', async function () {
|
||||
await DummyYamlService.invoke(
|
||||
{ sendAndCacheRequest },
|
||||
{ handleInternalErrors: false }
|
||||
@@ -74,7 +74,7 @@ describe('BaseYamlService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('forwards options to _sendAndCacheRequest', async function() {
|
||||
it('forwards options to _sendAndCacheRequest', async function () {
|
||||
class WithOptions extends DummyYamlService {
|
||||
async handle() {
|
||||
const { requiredString } = await this._requestYaml({
|
||||
@@ -105,8 +105,8 @@ describe('BaseYamlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Making badges', function() {
|
||||
it('handles valid yaml responses', async function() {
|
||||
describe('Making badges', function () {
|
||||
it('handles valid yaml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: expectedYaml,
|
||||
res: { statusCode: 200 },
|
||||
@@ -121,7 +121,7 @@ describe('BaseYamlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles yaml responses which do not match the schema', async function() {
|
||||
it('handles yaml responses which do not match the schema', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: unexpectedYaml,
|
||||
res: { statusCode: 200 },
|
||||
@@ -138,7 +138,7 @@ describe('BaseYamlService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles unparseable yaml responses', async function() {
|
||||
it('handles unparseable yaml responses', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: invalidYaml,
|
||||
res: { statusCode: 200 },
|
||||
|
||||
@@ -58,10 +58,7 @@ const serviceDataSchema = Joi.object({
|
||||
// `render()` to always return a string.
|
||||
message: Joi.alternatives(Joi.string().allow(''), Joi.number()).required(),
|
||||
color: Joi.string(),
|
||||
link: Joi.array()
|
||||
.items(Joi.string().uri())
|
||||
.single()
|
||||
.max(2),
|
||||
link: Joi.array().items(Joi.string().uri()).single().max(2),
|
||||
// Generally services should not use these options, which are provided to
|
||||
// support the Endpoint badge.
|
||||
labelColor: Joi.string(),
|
||||
@@ -70,9 +67,7 @@ const serviceDataSchema = Joi.object({
|
||||
logoColor: optionalStringWhenNamedLogoPresent,
|
||||
logoWidth: optionalNumberWhenAnyLogoPresent,
|
||||
logoPosition: optionalNumberWhenAnyLogoPresent,
|
||||
cacheSeconds: Joi.number()
|
||||
.integer()
|
||||
.min(0),
|
||||
cacheSeconds: Joi.number().integer().min(0),
|
||||
style: Joi.string(),
|
||||
})
|
||||
.oxor('namedLogo', 'logoSvg')
|
||||
|
||||
@@ -73,7 +73,7 @@ class DummyServiceWithServiceResponseSizeMetricEnabled extends DummyService {
|
||||
}
|
||||
}
|
||||
|
||||
describe('BaseService', function() {
|
||||
describe('BaseService', function () {
|
||||
const defaultConfig = {
|
||||
public: {
|
||||
handleInternalErrors: false,
|
||||
@@ -82,7 +82,7 @@ describe('BaseService', function() {
|
||||
private: {},
|
||||
}
|
||||
|
||||
it('Invokes the handler as expected', async function() {
|
||||
it('Invokes the handler as expected', async function () {
|
||||
expect(
|
||||
await DummyService.invoke(
|
||||
{},
|
||||
@@ -95,7 +95,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('Validates query params', async function() {
|
||||
it('Validates query params', async function () {
|
||||
expect(
|
||||
await DummyService.invoke(
|
||||
{},
|
||||
@@ -110,14 +110,14 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Required overrides', function() {
|
||||
it('Should throw if render() is not overridden', function() {
|
||||
describe('Required overrides', function () {
|
||||
it('Should throw if render() is not overridden', function () {
|
||||
expect(() => BaseService.render()).to.throw(
|
||||
/^render\(\) function not implemented for BaseService$/
|
||||
)
|
||||
})
|
||||
|
||||
it('Should throw if route is not overridden', function() {
|
||||
it('Should throw if route is not overridden', function () {
|
||||
return expect(BaseService.invoke({}, {}, {})).to.be.rejectedWith(
|
||||
/^Route not defined for BaseService$/
|
||||
)
|
||||
@@ -128,31 +128,31 @@ describe('BaseService', function() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
it('Should throw if handle() is not overridden', function() {
|
||||
it('Should throw if handle() is not overridden', function () {
|
||||
return expect(WithRoute.invoke({}, {}, {})).to.be.rejectedWith(
|
||||
/^Handler not implemented for WithRoute$/
|
||||
)
|
||||
})
|
||||
|
||||
it('Should throw if category is not overridden', function() {
|
||||
it('Should throw if category is not overridden', function () {
|
||||
expect(() => BaseService.category).to.throw(
|
||||
/^Category not set for BaseService$/
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Logging', function() {
|
||||
describe('Logging', function () {
|
||||
let sandbox
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
sandbox.restore()
|
||||
})
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox.stub(trace, 'logTrace')
|
||||
})
|
||||
it('Invokes the logger as expected', async function() {
|
||||
it('Invokes the logger as expected', async function () {
|
||||
await DummyService.invoke(
|
||||
{},
|
||||
defaultConfig,
|
||||
@@ -180,8 +180,8 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Service data validation', function() {
|
||||
it('Allows a link array', async function() {
|
||||
describe('Service data validation', function () {
|
||||
it('Allows a link array', async function () {
|
||||
const message = 'hello'
|
||||
const link = ['https://example.com/', 'https://other.example.com/']
|
||||
class LinkService extends DummyService {
|
||||
@@ -202,7 +202,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('On invalid data', function() {
|
||||
context('On invalid data', function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
return {
|
||||
@@ -211,7 +211,7 @@ describe('BaseService', function() {
|
||||
}
|
||||
}
|
||||
|
||||
it('Throws a validation error on invalid data', async function() {
|
||||
it('Throws a validation error on invalid data', async function () {
|
||||
try {
|
||||
await ThrowingService.invoke(
|
||||
{},
|
||||
@@ -229,7 +229,7 @@ describe('BaseService', function() {
|
||||
|
||||
// Ensure debuggabillity.
|
||||
// https://github.com/badges/shields/issues/3784
|
||||
it('Includes the service class in the stack trace', async function() {
|
||||
it('Includes the service class in the stack trace', async function () {
|
||||
try {
|
||||
await ThrowingService.invoke(
|
||||
{},
|
||||
@@ -244,8 +244,8 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Error handling', function() {
|
||||
it('Handles internal errors', async function() {
|
||||
describe('Error handling', function () {
|
||||
it('Handles internal errors', async function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
throw Error("I've made a huge mistake")
|
||||
@@ -265,8 +265,8 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Handles known subtypes of ShieldsInternalError', function() {
|
||||
it('handles NotFound errors', async function() {
|
||||
describe('Handles known subtypes of ShieldsInternalError', function () {
|
||||
it('handles NotFound errors', async function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
throw new NotFound()
|
||||
@@ -281,7 +281,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles Inaccessible errors', async function() {
|
||||
it('handles Inaccessible errors', async function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
throw new Inaccessible()
|
||||
@@ -296,7 +296,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles InvalidResponse errors', async function() {
|
||||
it('handles InvalidResponse errors', async function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
throw new InvalidResponse()
|
||||
@@ -311,7 +311,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles Deprecated', async function() {
|
||||
it('handles Deprecated', async function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
throw new Deprecated()
|
||||
@@ -326,7 +326,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('handles InvalidParameter errors', async function() {
|
||||
it('handles InvalidParameter errors', async function () {
|
||||
class ThrowingService extends DummyService {
|
||||
async handle() {
|
||||
throw new InvalidParameter()
|
||||
@@ -343,7 +343,7 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('ScoutCamp integration', function() {
|
||||
describe('ScoutCamp integration', function () {
|
||||
// TODO Strangly, without the useless escape the regexes do not match in Node 12.
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
const expectedRouteRegex = /^\/foo\/([^\/]+?)(|\.svg|\.json)$/
|
||||
@@ -351,7 +351,7 @@ describe('BaseService', function() {
|
||||
let mockCamp
|
||||
let mockHandleRequest
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
mockCamp = {
|
||||
route: sinon.spy(),
|
||||
}
|
||||
@@ -362,12 +362,12 @@ describe('BaseService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('registers the service', function() {
|
||||
it('registers the service', function () {
|
||||
expect(mockCamp.route).to.have.been.calledOnce
|
||||
expect(mockCamp.route).to.have.been.calledWith(expectedRouteRegex)
|
||||
})
|
||||
|
||||
it('handles the request', async function() {
|
||||
it('handles the request', async function () {
|
||||
expect(mockHandleRequest).to.have.been.calledOnce
|
||||
|
||||
const {
|
||||
@@ -404,8 +404,8 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('getDefinition', function() {
|
||||
it('returns the expected result', function() {
|
||||
describe('getDefinition', function () {
|
||||
it('returns the expected result', function () {
|
||||
const {
|
||||
category,
|
||||
name,
|
||||
@@ -432,12 +432,12 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('validate', function() {
|
||||
describe('validate', function () {
|
||||
const dummySchema = Joi.object({
|
||||
requiredString: Joi.string().required(),
|
||||
}).required()
|
||||
|
||||
it('throws error for invalid responses', function() {
|
||||
it('throws error for invalid responses', function () {
|
||||
expect(() =>
|
||||
DummyService._validate(
|
||||
{ requiredString: ['this', "shouldn't", 'work'] },
|
||||
@@ -449,19 +449,19 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('request', function() {
|
||||
describe('request', function () {
|
||||
let sandbox
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
sandbox.restore()
|
||||
})
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox.stub(trace, 'logTrace')
|
||||
})
|
||||
|
||||
it('logs appropriate information', async function() {
|
||||
it('logs appropriate information', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '',
|
||||
res: { statusCode: 200 },
|
||||
@@ -491,7 +491,7 @@ describe('BaseService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('handles errors', async function() {
|
||||
it('handles errors', async function () {
|
||||
const sendAndCacheRequest = async () => ({
|
||||
buffer: '',
|
||||
res: { statusCode: 404 },
|
||||
@@ -512,14 +512,14 @@ describe('BaseService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Metrics', function() {
|
||||
describe('Metrics', function () {
|
||||
let register
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
register = new prometheus.Registry()
|
||||
})
|
||||
const url = 'some-url'
|
||||
|
||||
it('service response size metric is optional', async function() {
|
||||
it('service response size metric is optional', async function () {
|
||||
const metricHelper = MetricHelper.create({
|
||||
metricInstance: new PrometheusMetrics({ register }),
|
||||
ServiceClass: DummyServiceWithServiceResponseSizeMetricEnabled,
|
||||
@@ -544,7 +544,7 @@ describe('BaseService', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('service response size metric is disabled by default', async function() {
|
||||
it('service response size metric is disabled by default', async function () {
|
||||
const metricHelper = MetricHelper.create({
|
||||
metricInstance: new PrometheusMetrics({ register }),
|
||||
ServiceClass: DummyService,
|
||||
@@ -565,7 +565,7 @@ describe('BaseService', function() {
|
||||
).to.not.contain('service_response_bytes_bucket')
|
||||
})
|
||||
})
|
||||
describe('auth', function() {
|
||||
describe('auth', function () {
|
||||
class AuthService extends DummyService {
|
||||
static get auth() {
|
||||
return {
|
||||
@@ -582,7 +582,7 @@ describe('BaseService', function() {
|
||||
}
|
||||
}
|
||||
|
||||
it('when auth is configured properly, invoke() sets authHelper', async function() {
|
||||
it('when auth is configured properly, invoke() sets authHelper', async function () {
|
||||
expect(
|
||||
await AuthService.invoke(
|
||||
{},
|
||||
@@ -598,7 +598,7 @@ describe('BaseService', function() {
|
||||
).to.deep.equal({ message: 'The CI password is abc123' })
|
||||
})
|
||||
|
||||
it('when auth is not configured properly, invoke() returns inacessible', async function() {
|
||||
it('when auth is not configured properly, invoke() returns inacessible', async function () {
|
||||
expect(
|
||||
await AuthService.invoke(
|
||||
{},
|
||||
|
||||
@@ -7,9 +7,7 @@ const coalesce = require('./coalesce')
|
||||
const serverStartTimeGMTString = new Date().toGMTString()
|
||||
const serverStartTimestamp = Date.now()
|
||||
|
||||
const isOptionalNonNegativeInteger = Joi.number()
|
||||
.integer()
|
||||
.min(0)
|
||||
const isOptionalNonNegativeInteger = Joi.number().integer().min(0)
|
||||
|
||||
const queryParamSchema = Joi.object({
|
||||
cacheSeconds: isOptionalNonNegativeInteger,
|
||||
|
||||
@@ -15,13 +15,13 @@ const {
|
||||
|
||||
chai.use(require('chai-datetime'))
|
||||
|
||||
describe('Cache header functions', function() {
|
||||
describe('Cache header functions', function () {
|
||||
let res
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
res = httpMocks.createResponse()
|
||||
})
|
||||
|
||||
describe('coalesceCacheLength', function() {
|
||||
describe('coalesceCacheLength', function () {
|
||||
const cacheHeaderConfig = { defaultCacheLengthSeconds: 777 }
|
||||
test(coalesceCacheLength, () => {
|
||||
given({ cacheHeaderConfig, queryParams: {} }).expect(777)
|
||||
@@ -101,18 +101,18 @@ describe('Cache header functions', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setHeadersForCacheLength', function() {
|
||||
describe('setHeadersForCacheLength', function () {
|
||||
let sandbox
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox()
|
||||
sandbox.useFakeTimers()
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
sandbox.restore()
|
||||
sandbox = undefined
|
||||
})
|
||||
|
||||
it('should set the correct Date header', function() {
|
||||
it('should set the correct Date header', function () {
|
||||
// Confidence check.
|
||||
expect(res._headers.date).to.equal(undefined)
|
||||
|
||||
@@ -124,42 +124,42 @@ describe('Cache header functions', function() {
|
||||
expect(res._headers.date).to.equal(now)
|
||||
})
|
||||
|
||||
context('cacheLengthSeconds is zero', function() {
|
||||
beforeEach(function() {
|
||||
context('cacheLengthSeconds is zero', function () {
|
||||
beforeEach(function () {
|
||||
setHeadersForCacheLength(res, 0)
|
||||
})
|
||||
|
||||
it('should set the expected Cache-Control header', function() {
|
||||
it('should set the expected Cache-Control header', function () {
|
||||
expect(res._headers['cache-control']).to.equal(
|
||||
'no-cache, no-store, must-revalidate'
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the expected Expires header', function() {
|
||||
it('should set the expected Expires header', function () {
|
||||
expect(res._headers.expires).to.equal(new Date().toGMTString())
|
||||
})
|
||||
})
|
||||
|
||||
context('cacheLengthSeconds is nonzero', function() {
|
||||
beforeEach(function() {
|
||||
context('cacheLengthSeconds is nonzero', function () {
|
||||
beforeEach(function () {
|
||||
setHeadersForCacheLength(res, 123)
|
||||
})
|
||||
|
||||
it('should set the expected Cache-Control header', function() {
|
||||
it('should set the expected Cache-Control header', function () {
|
||||
expect(res._headers['cache-control']).to.equal(
|
||||
'max-age=123 s-maxage=123'
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the expected Expires header', function() {
|
||||
it('should set the expected Expires header', function () {
|
||||
const expires = new Date(Date.now() + 123 * 1000).toGMTString()
|
||||
expect(res._headers.expires).to.equal(expires)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('setCacheHeaders', function() {
|
||||
it('sets the expected fields', function() {
|
||||
describe('setCacheHeaders', function () {
|
||||
it('sets the expected fields', function () {
|
||||
const expectedFields = ['date', 'cache-control', 'expires']
|
||||
expectedFields.forEach(field =>
|
||||
expect(res._headers[field]).to.equal(undefined)
|
||||
@@ -180,18 +180,18 @@ describe('Cache header functions', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('setCacheHeadersForStaticResource', function() {
|
||||
beforeEach(function() {
|
||||
describe('setCacheHeadersForStaticResource', function () {
|
||||
beforeEach(function () {
|
||||
setCacheHeadersForStaticResource(res)
|
||||
})
|
||||
|
||||
it('should set the expected Cache-Control header', function() {
|
||||
it('should set the expected Cache-Control header', function () {
|
||||
expect(res._headers['cache-control']).to.equal(
|
||||
`max-age=${24 * 3600} s-maxage=${24 * 3600}`
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the expected Last-Modified header', function() {
|
||||
it('should set the expected Last-Modified header', function () {
|
||||
const lastModified = res._headers['last-modified']
|
||||
expect(new Date(lastModified)).to.be.withinTime(
|
||||
// Within the last 60 seconds.
|
||||
@@ -201,17 +201,17 @@ describe('Cache header functions', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('serverHasBeenUpSinceResourceCached', function() {
|
||||
describe('serverHasBeenUpSinceResourceCached', function () {
|
||||
// The stringified req's are hard to understand. I thought Sazerac
|
||||
// provided a way to override the describe message, though I can't find it.
|
||||
context('when there is no If-Modified-Since header', function() {
|
||||
it('returns false', function() {
|
||||
context('when there is no If-Modified-Since header', function () {
|
||||
it('returns false', function () {
|
||||
const req = httpMocks.createRequest()
|
||||
expect(serverHasBeenUpSinceResourceCached(req)).to.equal(false)
|
||||
})
|
||||
})
|
||||
context('when the If-Modified-Since header is invalid', function() {
|
||||
it('returns false', function() {
|
||||
context('when the If-Modified-Since header is invalid', function () {
|
||||
it('returns false', function () {
|
||||
const req = httpMocks.createRequest({
|
||||
headers: { 'If-Modified-Since': 'this-is-not-a-date' },
|
||||
})
|
||||
@@ -220,8 +220,8 @@ describe('Cache header functions', function() {
|
||||
})
|
||||
context(
|
||||
'when the If-Modified-Since header is before the process started',
|
||||
function() {
|
||||
it('returns false', function() {
|
||||
function () {
|
||||
it('returns false', function () {
|
||||
const req = httpMocks.createRequest({
|
||||
headers: { 'If-Modified-Since': '2018-02-01T05:00:00.000Z' },
|
||||
})
|
||||
@@ -231,8 +231,8 @@ describe('Cache header functions', function() {
|
||||
)
|
||||
context(
|
||||
'when the If-Modified-Since header is after the process started',
|
||||
function() {
|
||||
it('returns true', function() {
|
||||
function () {
|
||||
it('returns true', function () {
|
||||
const modifiedTimeStamp = new Date(Date.now() + 1800000)
|
||||
const req = httpMocks.createRequest({
|
||||
headers: { 'If-Modified-Since': modifiedTimeStamp.toISOString() },
|
||||
|
||||
@@ -7,7 +7,7 @@ const defaultErrorMessages = {
|
||||
}
|
||||
|
||||
module.exports = function checkErrorResponse(errorMessages = {}) {
|
||||
return async function({ buffer, res }) {
|
||||
return async function ({ buffer, res }) {
|
||||
let error
|
||||
errorMessages = { ...defaultErrorMessages, ...errorMessages }
|
||||
if (res.statusCode === 404) {
|
||||
|
||||
@@ -4,11 +4,11 @@ const { expect } = require('chai')
|
||||
const { NotFound, InvalidResponse, Inaccessible } = require('./errors')
|
||||
const checkErrorResponse = require('./check-error-response')
|
||||
|
||||
describe('async error handler', function() {
|
||||
describe('async error handler', function () {
|
||||
const buffer = Buffer.from('some stuff')
|
||||
|
||||
context('when status is 200', function() {
|
||||
it('passes through the inputs', async function() {
|
||||
context('when status is 200', function () {
|
||||
it('passes through the inputs', async function () {
|
||||
const res = { statusCode: 200 }
|
||||
expect(await checkErrorResponse()({ res, buffer })).to.deep.equal({
|
||||
res,
|
||||
@@ -17,11 +17,11 @@ describe('async error handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when status is 404', function() {
|
||||
context('when status is 404', function () {
|
||||
const buffer = Buffer.from('some stuff')
|
||||
const res = { statusCode: 404 }
|
||||
|
||||
it('throws NotFound', async function() {
|
||||
it('throws NotFound', async function () {
|
||||
try {
|
||||
await checkErrorResponse()({ res, buffer })
|
||||
expect.fail('Expected to throw')
|
||||
@@ -34,7 +34,7 @@ describe('async error handler', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('displays the custom not found message', async function() {
|
||||
it('displays the custom not found message', async function () {
|
||||
const notFoundMessage = 'no goblins found'
|
||||
try {
|
||||
await checkErrorResponse({ 404: notFoundMessage })({ res, buffer })
|
||||
@@ -47,8 +47,8 @@ describe('async error handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when status is 4xx', function() {
|
||||
it('throws InvalidResponse', async function() {
|
||||
context('when status is 4xx', function () {
|
||||
it('throws InvalidResponse', async function () {
|
||||
const res = { statusCode: 499 }
|
||||
try {
|
||||
await checkErrorResponse()({ res, buffer })
|
||||
@@ -64,7 +64,7 @@ describe('async error handler', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('displays the custom error message', async function() {
|
||||
it('displays the custom error message', async function () {
|
||||
const res = { statusCode: 403 }
|
||||
try {
|
||||
await checkErrorResponse({ 403: 'access denied' })({ res })
|
||||
@@ -79,8 +79,8 @@ describe('async error handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when status is 5xx', function() {
|
||||
it('throws Inaccessible', async function() {
|
||||
context('when status is 5xx', function () {
|
||||
it('throws Inaccessible', async function () {
|
||||
const res = { statusCode: 503 }
|
||||
try {
|
||||
await checkErrorResponse()({ res, buffer })
|
||||
@@ -96,7 +96,7 @@ describe('async error handler', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('displays the custom error message', async function() {
|
||||
it('displays the custom error message', async function () {
|
||||
const res = { statusCode: 500 }
|
||||
try {
|
||||
await checkErrorResponse({ 500: 'server overloaded' })({ res, buffer })
|
||||
|
||||
@@ -4,9 +4,9 @@ const { expect } = require('chai')
|
||||
const { getShieldsIcon, getSimpleIcon } = require('../../lib/logos')
|
||||
const coalesceBadge = require('./coalesce-badge')
|
||||
|
||||
describe('coalesceBadge', function() {
|
||||
describe('Label', function() {
|
||||
it('uses the default label', function() {
|
||||
describe('coalesceBadge', function () {
|
||||
describe('Label', function () {
|
||||
it('uses the default label', function () {
|
||||
expect(coalesceBadge({}, {}, { label: 'heyo' }).text).to.deep.equal([
|
||||
'heyo',
|
||||
'n/a',
|
||||
@@ -14,34 +14,34 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
|
||||
// This behavior isn't great and we might want to remove it.
|
||||
it('uses the category as a default label', function() {
|
||||
it('uses the category as a default label', function () {
|
||||
expect(
|
||||
coalesceBadge({}, {}, {}, { category: 'cat' }).text
|
||||
).to.deep.equal(['cat', 'n/a'])
|
||||
})
|
||||
|
||||
it('preserves an empty label', function() {
|
||||
it('preserves an empty label', function () {
|
||||
expect(
|
||||
coalesceBadge({}, { label: '', message: '10k' }, {}).text
|
||||
).to.deep.equal(['', '10k'])
|
||||
})
|
||||
|
||||
it('overrides the label', function() {
|
||||
it('overrides the label', function () {
|
||||
expect(
|
||||
coalesceBadge({ label: 'purr count' }, { label: 'purrs' }, {}).text
|
||||
).to.deep.equal(['purr count', 'n/a'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('Message', function() {
|
||||
it('applies the service message', function() {
|
||||
describe('Message', function () {
|
||||
it('applies the service message', function () {
|
||||
expect(coalesceBadge({}, { message: '10k' }, {}).text).to.deep.equal([
|
||||
undefined,
|
||||
'10k',
|
||||
])
|
||||
})
|
||||
|
||||
it('applies a numeric service message', function() {
|
||||
it('applies a numeric service message', function () {
|
||||
// While a number of badges use this, in the long run we may want
|
||||
// `render()` to always return a string.
|
||||
expect(coalesceBadge({}, { message: 10 }, {}).text).to.deep.equal([
|
||||
@@ -51,12 +51,12 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Right color', function() {
|
||||
it('uses the default color', function() {
|
||||
describe('Right color', function () {
|
||||
it('uses the default color', function () {
|
||||
expect(coalesceBadge({}, {}, {}).color).to.equal('lightgrey')
|
||||
})
|
||||
|
||||
it('overrides the color', function() {
|
||||
it('overrides the color', function () {
|
||||
expect(
|
||||
coalesceBadge({ color: '10ADED' }, { color: 'red' }, {}).color
|
||||
).to.equal('10ADED')
|
||||
@@ -66,8 +66,8 @@ describe('coalesceBadge', function() {
|
||||
).to.equal('B0ADED')
|
||||
})
|
||||
|
||||
context('In case of an error', function() {
|
||||
it('does not override the color', function() {
|
||||
context('In case of an error', function () {
|
||||
it('does not override the color', function () {
|
||||
expect(
|
||||
coalesceBadge(
|
||||
{ color: '10ADED' },
|
||||
@@ -86,23 +86,23 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('applies the service color', function() {
|
||||
it('applies the service color', function () {
|
||||
expect(coalesceBadge({}, { color: 'red' }, {}).color).to.equal('red')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Left color', function() {
|
||||
it('provides no default label color', function() {
|
||||
describe('Left color', function () {
|
||||
it('provides no default label color', function () {
|
||||
expect(coalesceBadge({}, {}, {}).labelColor).to.be.undefined
|
||||
})
|
||||
|
||||
it('applies the service label color', function() {
|
||||
it('applies the service label color', function () {
|
||||
expect(coalesceBadge({}, { labelColor: 'red' }, {}).labelColor).to.equal(
|
||||
'red'
|
||||
)
|
||||
})
|
||||
|
||||
it('overrides the label color', function() {
|
||||
it('overrides the label color', function () {
|
||||
expect(
|
||||
coalesceBadge({ labelColor: '42f483' }, { color: 'green' }, {})
|
||||
.labelColor
|
||||
@@ -113,7 +113,7 @@ describe('coalesceBadge', function() {
|
||||
).to.equal('B2f483')
|
||||
})
|
||||
|
||||
it('converts a query-string numeric color to a string', function() {
|
||||
it('converts a query-string numeric color to a string', function () {
|
||||
expect(
|
||||
coalesceBadge(
|
||||
// Scoutcamp converts numeric query params to numbers.
|
||||
@@ -134,20 +134,20 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Named logos', function() {
|
||||
it('when not a social badge, ignores the default named logo', function() {
|
||||
describe('Named logos', function () {
|
||||
it('when not a social badge, ignores the default named logo', function () {
|
||||
expect(coalesceBadge({}, {}, { namedLogo: 'appveyor' }).logo).to.be
|
||||
.undefined
|
||||
})
|
||||
|
||||
it('when a social badge, uses the default named logo', function() {
|
||||
it('when a social badge, uses the default named logo', function () {
|
||||
// .not.be.empty for confidence that nothing has changed with `getShieldsIcon()`.
|
||||
expect(
|
||||
coalesceBadge({ style: 'social' }, {}, { namedLogo: 'appveyor' }).logo
|
||||
).to.equal(getSimpleIcon({ name: 'appveyor' })).and.not.be.empty
|
||||
})
|
||||
|
||||
it('applies the named logo', function() {
|
||||
it('applies the named logo', function () {
|
||||
expect(coalesceBadge({}, { namedLogo: 'npm' }, {}).namedLogo).to.equal(
|
||||
'npm'
|
||||
)
|
||||
@@ -156,20 +156,20 @@ describe('coalesceBadge', function() {
|
||||
).and.not.to.be.empty
|
||||
})
|
||||
|
||||
it('applies the named logo with color', function() {
|
||||
it('applies the named logo with color', function () {
|
||||
expect(
|
||||
coalesceBadge({}, { namedLogo: 'npm', logoColor: 'blue' }, {}).logo
|
||||
).to.equal(getShieldsIcon({ name: 'npm', color: 'blue' })).and.not.to.be
|
||||
.empty
|
||||
})
|
||||
|
||||
it('overrides the logo', function() {
|
||||
it('overrides the logo', function () {
|
||||
expect(
|
||||
coalesceBadge({ logo: 'npm' }, { namedLogo: 'appveyor' }, {}).logo
|
||||
).to.equal(getShieldsIcon({ name: 'npm' })).and.not.be.empty
|
||||
})
|
||||
|
||||
it('overrides the logo with a color', function() {
|
||||
it('overrides the logo with a color', function () {
|
||||
expect(
|
||||
coalesceBadge(
|
||||
{ logo: 'npm', logoColor: 'blue' },
|
||||
@@ -180,7 +180,7 @@ describe('coalesceBadge', function() {
|
||||
.empty
|
||||
})
|
||||
|
||||
it("when the logo is overridden, it ignores the service's logo color, position, and width", function() {
|
||||
it("when the logo is overridden, it ignores the service's logo color, position, and width", function () {
|
||||
expect(
|
||||
coalesceBadge(
|
||||
{ logo: 'npm' },
|
||||
@@ -195,7 +195,7 @@ describe('coalesceBadge', function() {
|
||||
).to.equal(getShieldsIcon({ name: 'npm' })).and.not.be.empty
|
||||
})
|
||||
|
||||
it("overrides the service logo's color", function() {
|
||||
it("overrides the service logo's color", function () {
|
||||
expect(
|
||||
coalesceBadge(
|
||||
{ logoColor: 'blue' },
|
||||
@@ -207,7 +207,7 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/issues/2998
|
||||
it('overrides logoSvg', function() {
|
||||
it('overrides logoSvg', function () {
|
||||
const logoSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxu'
|
||||
expect(coalesceBadge({ logo: 'npm' }, { logoSvg }, {}).logo).to.equal(
|
||||
getShieldsIcon({ name: 'npm' })
|
||||
@@ -215,15 +215,15 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Custom logos', function() {
|
||||
it('overrides the logo with custom svg', function() {
|
||||
describe('Custom logos', function () {
|
||||
it('overrides the logo with custom svg', function () {
|
||||
const logoSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxu'
|
||||
expect(
|
||||
coalesceBadge({ logo: logoSvg }, { namedLogo: 'appveyor' }, {}).logo
|
||||
).to.equal(logoSvg)
|
||||
})
|
||||
|
||||
it('ignores the color when custom svg is provided', function() {
|
||||
it('ignores the color when custom svg is provided', function () {
|
||||
const logoSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxu'
|
||||
expect(
|
||||
coalesceBadge(
|
||||
@@ -235,26 +235,26 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Logo width', function() {
|
||||
it('overrides the logoWidth', function() {
|
||||
describe('Logo width', function () {
|
||||
it('overrides the logoWidth', function () {
|
||||
expect(coalesceBadge({ logoWidth: 20 }, {}, {}).logoWidth).to.equal(20)
|
||||
})
|
||||
|
||||
it('applies the logo width', function() {
|
||||
it('applies the logo width', function () {
|
||||
expect(
|
||||
coalesceBadge({}, { namedLogo: 'npm', logoWidth: 275 }, {}).logoWidth
|
||||
).to.equal(275)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Logo position', function() {
|
||||
it('overrides the logoPosition', function() {
|
||||
describe('Logo position', function () {
|
||||
it('overrides the logoPosition', function () {
|
||||
expect(
|
||||
coalesceBadge({ logoPosition: -10 }, {}, {}).logoPosition
|
||||
).to.equal(-10)
|
||||
})
|
||||
|
||||
it('applies the logo position', function() {
|
||||
it('applies the logo position', function () {
|
||||
expect(
|
||||
coalesceBadge({}, { namedLogo: 'npm', logoPosition: -10 }, {})
|
||||
.logoPosition
|
||||
@@ -262,8 +262,8 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Links', function() {
|
||||
it('overrides the links', function() {
|
||||
describe('Links', function () {
|
||||
it('overrides the links', function () {
|
||||
expect(
|
||||
coalesceBadge(
|
||||
{ link: 'https://circleci.com/gh/badges/daily-tests' },
|
||||
@@ -277,8 +277,8 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Style', function() {
|
||||
it('falls back to flat with invalid style', function() {
|
||||
describe('Style', function () {
|
||||
it('falls back to flat with invalid style', function () {
|
||||
expect(coalesceBadge({ style: 'pill' }, {}, {}).template).to.equal('flat')
|
||||
expect(coalesceBadge({ style: 7 }, {}, {}).template).to.equal('flat')
|
||||
expect(coalesceBadge({ style: undefined }, {}, {}).template).to.equal(
|
||||
@@ -286,7 +286,7 @@ describe('coalesceBadge', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('replaces legacy popout styles', function() {
|
||||
it('replaces legacy popout styles', function () {
|
||||
expect(coalesceBadge({ style: 'popout' }, {}, {}).template).to.equal(
|
||||
'flat'
|
||||
)
|
||||
@@ -296,8 +296,8 @@ describe('coalesceBadge', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Cache length', function() {
|
||||
it('overrides the cache length', function() {
|
||||
describe('Cache length', function () {
|
||||
it('overrides the cache length', function () {
|
||||
expect(
|
||||
coalesceBadge({ style: 'pill' }, { cacheSeconds: 123 }, {})
|
||||
.cacheLengthSeconds
|
||||
|
||||
@@ -7,8 +7,8 @@ const coalesce = require('./coalesce')
|
||||
// `undefined` instead of `null`, though h/t to
|
||||
// https://github.com/royriojas/coalescy for these tests!
|
||||
|
||||
describe('coalesce', function() {
|
||||
test(coalesce, function() {
|
||||
describe('coalesce', function () {
|
||||
test(coalesce, function () {
|
||||
given().expect(undefined)
|
||||
given(null, []).expect([])
|
||||
given(null, [], {}).expect([])
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const { expect } = require('chai')
|
||||
const deprecatedService = require('./deprecated-service')
|
||||
|
||||
describe('DeprecatedService', function() {
|
||||
describe('DeprecatedService', function () {
|
||||
const route = {
|
||||
base: 'service/that/no/longer/exists',
|
||||
format: '(?:.+)',
|
||||
@@ -12,33 +12,33 @@ describe('DeprecatedService', function() {
|
||||
const dateAdded = new Date()
|
||||
const commonAttrs = { route, category, dateAdded }
|
||||
|
||||
it('returns true on isDeprecated', function() {
|
||||
it('returns true on isDeprecated', function () {
|
||||
const service = deprecatedService({ ...commonAttrs })
|
||||
expect(service.isDeprecated).to.be.true
|
||||
})
|
||||
|
||||
it('has the expected name', function() {
|
||||
it('has the expected name', function () {
|
||||
const service = deprecatedService({ ...commonAttrs })
|
||||
expect(service.name).to.equal('DeprecatedServiceThatNoLongerExists')
|
||||
})
|
||||
|
||||
it('sets specified route', function() {
|
||||
it('sets specified route', function () {
|
||||
const service = deprecatedService({ ...commonAttrs })
|
||||
expect(service.route).to.deep.equal(route)
|
||||
})
|
||||
|
||||
it('sets specified label', function() {
|
||||
it('sets specified label', function () {
|
||||
const label = 'coverity'
|
||||
const service = deprecatedService({ ...commonAttrs, label })
|
||||
expect(service.defaultBadgeData.label).to.equal(label)
|
||||
})
|
||||
|
||||
it('sets specified category', function() {
|
||||
it('sets specified category', function () {
|
||||
const service = deprecatedService({ ...commonAttrs })
|
||||
expect(service.category).to.equal(category)
|
||||
})
|
||||
|
||||
it('sets specified examples', function() {
|
||||
it('sets specified examples', function () {
|
||||
const examples = [
|
||||
{
|
||||
title: 'Not sure we would have examples',
|
||||
@@ -48,7 +48,7 @@ describe('DeprecatedService', function() {
|
||||
expect(service.examples).to.deep.equal(examples)
|
||||
})
|
||||
|
||||
it('uses default deprecation message when no message specified', async function() {
|
||||
it('uses default deprecation message when no message specified', async function () {
|
||||
const service = deprecatedService({ ...commonAttrs })
|
||||
expect(await service.invoke()).to.deep.equal({
|
||||
isError: true,
|
||||
@@ -57,7 +57,7 @@ describe('DeprecatedService', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('uses custom deprecation message when specified', async function() {
|
||||
it('uses custom deprecation message when specified', async function () {
|
||||
const message = 'extended outage'
|
||||
const service = deprecatedService({ ...commonAttrs, message })
|
||||
expect(await service.invoke()).to.deep.equal({
|
||||
|
||||
@@ -21,19 +21,12 @@ const schema = Joi.object({
|
||||
staticPreview: Joi.object({
|
||||
label: Joi.string(),
|
||||
message: Joi.alternatives()
|
||||
.try(
|
||||
Joi.string()
|
||||
.allow('')
|
||||
.required(),
|
||||
Joi.number()
|
||||
)
|
||||
.try(Joi.string().allow('').required(), Joi.number())
|
||||
.required(),
|
||||
color: Joi.string(),
|
||||
style: Joi.string(),
|
||||
}).required(),
|
||||
keywords: Joi.array()
|
||||
.items(Joi.string())
|
||||
.default([]),
|
||||
keywords: Joi.array().items(Joi.string()).default([]),
|
||||
documentation: Joi.string(), // Valid HTML.
|
||||
}).required()
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ const { expect } = require('chai')
|
||||
const { test, given } = require('sazerac')
|
||||
const { validateExample, transformExample } = require('./examples')
|
||||
|
||||
describe('validateExample function', function() {
|
||||
it('passes valid examples', function() {
|
||||
describe('validateExample function', function () {
|
||||
it('passes valid examples', function () {
|
||||
const validExamples = [
|
||||
{
|
||||
title: 'Package manager versioning badge',
|
||||
@@ -23,7 +23,7 @@ describe('validateExample function', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects invalid examples', function() {
|
||||
it('rejects invalid examples', function () {
|
||||
const invalidExamples = [
|
||||
{},
|
||||
{ staticPreview: { message: '123' } },
|
||||
@@ -74,7 +74,7 @@ describe('validateExample function', function() {
|
||||
})
|
||||
})
|
||||
|
||||
test(transformExample, function() {
|
||||
test(transformExample, function () {
|
||||
const ExampleService = {
|
||||
name: 'ExampleService',
|
||||
route: {
|
||||
|
||||
@@ -7,8 +7,8 @@ const { mergeQueries } = require('./graphql')
|
||||
|
||||
require('../register-chai-plugins.spec')
|
||||
|
||||
describe('mergeQueries function', function() {
|
||||
it('merges valid gql queries', function() {
|
||||
describe('mergeQueries function', function () {
|
||||
it('merges valid gql queries', function () {
|
||||
expect(
|
||||
print(
|
||||
mergeQueries(
|
||||
@@ -86,7 +86,7 @@ describe('mergeQueries function', function() {
|
||||
).to.equalIgnoreSpaces('{ foo bar }')
|
||||
})
|
||||
|
||||
it('throws an error when passed invalid params', function() {
|
||||
it('throws an error when passed invalid params', function () {
|
||||
expect(() => mergeQueries('', '')).to.throw(Error)
|
||||
expect(() => mergeQueries(undefined, 17, true)).to.throw(Error)
|
||||
expect(() => mergeQueries(gql``, gql`foo`)).to.throw(Error)
|
||||
|
||||
@@ -70,19 +70,19 @@ function fakeHandlerWithNetworkIo(queryParams, match, sendBadge, request) {
|
||||
})
|
||||
}
|
||||
|
||||
describe('The request handler', function() {
|
||||
describe('The request handler', function () {
|
||||
let port, baseUrl
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
port = await portfinder.getPortPromise()
|
||||
baseUrl = `http://127.0.0.1:${port}`
|
||||
})
|
||||
|
||||
let camp
|
||||
beforeEach(function(done) {
|
||||
beforeEach(function (done) {
|
||||
camp = Camp.start({ port, hostname: '::' })
|
||||
camp.on('listening', () => done())
|
||||
})
|
||||
afterEach(function(done) {
|
||||
afterEach(function (done) {
|
||||
clearRequestCache()
|
||||
if (camp) {
|
||||
camp.close(() => done())
|
||||
@@ -92,15 +92,15 @@ describe('The request handler', function() {
|
||||
|
||||
const standardCacheHeaders = { defaultCacheLengthSeconds: 120 }
|
||||
|
||||
describe('the options object calling style', function() {
|
||||
beforeEach(function() {
|
||||
describe('the options object calling style', function () {
|
||||
beforeEach(function () {
|
||||
camp.route(
|
||||
/^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
handleRequest(standardCacheHeaders, { handler: fakeHandler })
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the expected response', async function() {
|
||||
it('should return the expected response', async function () {
|
||||
const { statusCode, body } = await got(`${baseUrl}/testing/123.json`, {
|
||||
responseType: 'json',
|
||||
})
|
||||
@@ -116,15 +116,15 @@ describe('The request handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the function shorthand calling style', function() {
|
||||
beforeEach(function() {
|
||||
describe('the function shorthand calling style', function () {
|
||||
beforeEach(function () {
|
||||
camp.route(
|
||||
/^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
handleRequest(standardCacheHeaders, fakeHandler)
|
||||
)
|
||||
})
|
||||
|
||||
it('should return the expected response', async function() {
|
||||
it('should return the expected response', async function () {
|
||||
const { statusCode, body } = await got(`${baseUrl}/testing/123.json`, {
|
||||
responseType: 'json',
|
||||
})
|
||||
@@ -140,8 +140,8 @@ describe('The request handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the response size limit', function() {
|
||||
beforeEach(function() {
|
||||
describe('the response size limit', function () {
|
||||
beforeEach(function () {
|
||||
camp.route(
|
||||
/^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
handleRequest(standardCacheHeaders, {
|
||||
@@ -151,7 +151,7 @@ describe('The request handler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should not throw an error if the response <= fetchLimitBytes', async function() {
|
||||
it('should not throw an error if the response <= fetchLimitBytes', async function () {
|
||||
nock('https://www.google.com')
|
||||
.get('/foo/bar')
|
||||
.once()
|
||||
@@ -170,7 +170,7 @@ describe('The request handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw an error if the response is > fetchLimitBytes', async function() {
|
||||
it('should throw an error if the response is > fetchLimitBytes', async function () {
|
||||
nock('https://www.google.com')
|
||||
.get('/foo/bar')
|
||||
.once()
|
||||
@@ -189,15 +189,15 @@ describe('The request handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
nock.cleanAll()
|
||||
})
|
||||
})
|
||||
|
||||
describe('caching', function() {
|
||||
describe('standard query parameters', function() {
|
||||
describe('caching', function () {
|
||||
describe('standard query parameters', function () {
|
||||
let handlerCallCount
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
handlerCallCount = 0
|
||||
})
|
||||
|
||||
@@ -214,12 +214,12 @@ describe('The request handler', function() {
|
||||
)
|
||||
}
|
||||
|
||||
context('With standard cache settings', function() {
|
||||
beforeEach(function() {
|
||||
context('With standard cache settings', function () {
|
||||
beforeEach(function () {
|
||||
register({ cacheHeaderConfig: standardCacheHeaders })
|
||||
})
|
||||
|
||||
it('should cache identical requests', async function() {
|
||||
it('should cache identical requests', async function () {
|
||||
await performTwoRequests(
|
||||
baseUrl,
|
||||
'/testing/123.svg',
|
||||
@@ -228,7 +228,7 @@ describe('The request handler', function() {
|
||||
expect(handlerCallCount).to.equal(1)
|
||||
})
|
||||
|
||||
it('should differentiate known query parameters', async function() {
|
||||
it('should differentiate known query parameters', async function () {
|
||||
await performTwoRequests(
|
||||
baseUrl,
|
||||
'/testing/123.svg?label=foo',
|
||||
@@ -237,7 +237,7 @@ describe('The request handler', function() {
|
||||
expect(handlerCallCount).to.equal(2)
|
||||
})
|
||||
|
||||
it('should ignore unknown query parameters', async function() {
|
||||
it('should ignore unknown query parameters', async function () {
|
||||
await performTwoRequests(
|
||||
baseUrl,
|
||||
'/testing/123.svg?foo=1',
|
||||
@@ -247,7 +247,7 @@ describe('The request handler', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should set the expires header to current time + defaultCacheLengthSeconds', async function() {
|
||||
it('should set the expires header to current time + defaultCacheLengthSeconds', async function () {
|
||||
register({ cacheHeaderConfig: { defaultCacheLengthSeconds: 900 } })
|
||||
const { headers } = await got(`${baseUrl}/testing/123.json`)
|
||||
const expectedExpiry = new Date(
|
||||
@@ -257,7 +257,7 @@ describe('The request handler', function() {
|
||||
expect(headers['cache-control']).to.equal('max-age=900 s-maxage=900')
|
||||
})
|
||||
|
||||
it('should set the expected cache headers on cached responses', async function() {
|
||||
it('should set the expected cache headers on cached responses', async function () {
|
||||
register({ cacheHeaderConfig: { defaultCacheLengthSeconds: 900 } })
|
||||
|
||||
// Make first request.
|
||||
@@ -271,7 +271,7 @@ describe('The request handler', function() {
|
||||
expect(headers['cache-control']).to.equal('max-age=900 s-maxage=900')
|
||||
})
|
||||
|
||||
it('should let live service data override the default cache headers with longer value', async function() {
|
||||
it('should let live service data override the default cache headers with longer value', async function () {
|
||||
camp.route(
|
||||
/^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
handleRequest(
|
||||
@@ -292,7 +292,7 @@ describe('The request handler', function() {
|
||||
expect(headers['cache-control']).to.equal('max-age=400 s-maxage=400')
|
||||
})
|
||||
|
||||
it('should not let live service data override the default cache headers with shorter value', async function() {
|
||||
it('should not let live service data override the default cache headers with shorter value', async function () {
|
||||
camp.route(
|
||||
/^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
handleRequest(
|
||||
@@ -313,7 +313,7 @@ describe('The request handler', function() {
|
||||
expect(headers['cache-control']).to.equal('max-age=300 s-maxage=300')
|
||||
})
|
||||
|
||||
it('should set the expires header to current time + cacheSeconds', async function() {
|
||||
it('should set the expires header to current time + cacheSeconds', async function () {
|
||||
register({ cacheHeaderConfig: { defaultCacheLengthSeconds: 0 } })
|
||||
const { headers } = await got(
|
||||
`${baseUrl}/testing/123.json?cacheSeconds=3600`
|
||||
@@ -325,7 +325,7 @@ describe('The request handler', function() {
|
||||
expect(headers['cache-control']).to.equal('max-age=3600 s-maxage=3600')
|
||||
})
|
||||
|
||||
it('should ignore cacheSeconds when shorter than defaultCacheLengthSeconds', async function() {
|
||||
it('should ignore cacheSeconds when shorter than defaultCacheLengthSeconds', async function () {
|
||||
register({ cacheHeaderConfig: { defaultCacheLengthSeconds: 600 } })
|
||||
const { headers } = await got(
|
||||
`${baseUrl}/testing/123.json?cacheSeconds=300`
|
||||
@@ -337,7 +337,7 @@ describe('The request handler', function() {
|
||||
expect(headers['cache-control']).to.equal('max-age=600 s-maxage=600')
|
||||
})
|
||||
|
||||
it('should set Cache-Control: no-cache, no-store, must-revalidate if cache seconds is 0', async function() {
|
||||
it('should set Cache-Control: no-cache, no-store, must-revalidate if cache seconds is 0', async function () {
|
||||
register({ cacheHeaderConfig: { defaultCacheLengthSeconds: 0 } })
|
||||
const { headers } = await got(`${baseUrl}/testing/123.json`)
|
||||
expect(headers.expires).to.equal(headers.date)
|
||||
@@ -346,25 +346,25 @@ describe('The request handler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('the cache key', function() {
|
||||
beforeEach(function() {
|
||||
describe('the cache key', function () {
|
||||
beforeEach(function () {
|
||||
register({ cacheHeaderConfig: standardCacheHeaders })
|
||||
})
|
||||
const expectedCacheKey = '/testing/123.json?color=123&label=foo'
|
||||
it('should match expected and use canonical order - 1', async function() {
|
||||
it('should match expected and use canonical order - 1', async function () {
|
||||
await got(`${baseUrl}/testing/123.json?color=123&label=foo`)
|
||||
expect(_requestCache.cache).to.have.keys(expectedCacheKey)
|
||||
})
|
||||
it('should match expected and use canonical order - 2', async function() {
|
||||
it('should match expected and use canonical order - 2', async function () {
|
||||
await got(`${baseUrl}/testing/123.json?label=foo&color=123`)
|
||||
expect(_requestCache.cache).to.have.keys(expectedCacheKey)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('custom query parameters', function() {
|
||||
describe('custom query parameters', function () {
|
||||
let handlerCallCount
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
handlerCallCount = 0
|
||||
camp.route(
|
||||
/^\/testing\/([^/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
@@ -378,7 +378,7 @@ describe('The request handler', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should differentiate them', async function() {
|
||||
it('should differentiate them', async function () {
|
||||
await performTwoRequests(
|
||||
baseUrl,
|
||||
'/testing/123.svg?foo=1',
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
const { expect } = require('chai')
|
||||
const { loadServiceClasses, InvalidService } = require('./loader')
|
||||
|
||||
describe('loadServiceClasses function', function() {
|
||||
it('throws if module exports empty', function() {
|
||||
describe('loadServiceClasses function', function () {
|
||||
it('throws if module exports empty', function () {
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/empty-undefined.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
@@ -26,7 +26,7 @@ describe('loadServiceClasses function', function() {
|
||||
).to.throw(InvalidService)
|
||||
})
|
||||
|
||||
it('throws if module exports invalid', function() {
|
||||
it('throws if module exports invalid', function () {
|
||||
expect(() =>
|
||||
loadServiceClasses(['./loader-test-fixtures/invalid-no-base.fixture.js'])
|
||||
).to.throw(InvalidService)
|
||||
@@ -47,7 +47,7 @@ describe('loadServiceClasses function', function() {
|
||||
).to.throw(InvalidService)
|
||||
})
|
||||
|
||||
it('registers services if module exports valid service classes', function() {
|
||||
it('registers services if module exports valid service classes', function () {
|
||||
expect(
|
||||
loadServiceClasses([
|
||||
'./loader-test-fixtures/valid-array.fixture.js',
|
||||
|
||||
@@ -126,7 +126,7 @@ Cache.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
clear: function () {
|
||||
this.cache.clear()
|
||||
this.newest = null
|
||||
this.oldest = null
|
||||
|
||||
@@ -25,14 +25,14 @@ function expectCacheSlots(cache, keys) {
|
||||
}
|
||||
}
|
||||
|
||||
describe('The LRU cache', function() {
|
||||
it('should support a zero capacity', function() {
|
||||
describe('The LRU cache', function () {
|
||||
it('should support a zero capacity', function () {
|
||||
const cache = new LRU(0)
|
||||
cache.set('key', 'value')
|
||||
expect(cache.cache.size).to.equal(0)
|
||||
})
|
||||
|
||||
it('should support a one capacity', function() {
|
||||
it('should support a one capacity', function () {
|
||||
const cache = new LRU(1)
|
||||
cache.set('key1', 'value1')
|
||||
expectCacheSlots(cache, ['key1'])
|
||||
@@ -42,7 +42,7 @@ describe('The LRU cache', function() {
|
||||
expect(cache.get('key2')).to.equal('value2')
|
||||
})
|
||||
|
||||
it('should remove the oldest element when reaching capacity', function() {
|
||||
it('should remove the oldest element when reaching capacity', function () {
|
||||
const cache = new LRU(2)
|
||||
|
||||
cache.set('key1', 'value1')
|
||||
@@ -57,7 +57,7 @@ describe('The LRU cache', function() {
|
||||
expect(cache.get('key3')).to.equal('value3')
|
||||
})
|
||||
|
||||
it('should make sure that resetting a key in cache makes it newest', function() {
|
||||
it('should make sure that resetting a key in cache makes it newest', function () {
|
||||
const cache = new LRU(2)
|
||||
|
||||
cache.set('key', 'value')
|
||||
@@ -70,9 +70,9 @@ describe('The LRU cache', function() {
|
||||
expectCacheSlots(cache, ['key2', 'key'])
|
||||
})
|
||||
|
||||
describe('getting a key in the cache', function() {
|
||||
context('when the requested key is oldest', function() {
|
||||
it('should leave the keys in the expected order', function() {
|
||||
describe('getting a key in the cache', function () {
|
||||
context('when the requested key is oldest', function () {
|
||||
it('should leave the keys in the expected order', function () {
|
||||
const cache = new LRU(2)
|
||||
cache.set('key1', 'value1')
|
||||
cache.set('key2', 'value2')
|
||||
@@ -85,8 +85,8 @@ describe('The LRU cache', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when the requested key is newest', function() {
|
||||
it('should leave the keys in the expected order', function() {
|
||||
context('when the requested key is newest', function () {
|
||||
it('should leave the keys in the expected order', function () {
|
||||
const cache = new LRU(2)
|
||||
cache.set('key1', 'value1')
|
||||
cache.set('key2', 'value2')
|
||||
@@ -97,8 +97,8 @@ describe('The LRU cache', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when the requested key is in the middle', function() {
|
||||
it('should leave the keys in the expected order', function() {
|
||||
context('when the requested key is in the middle', function () {
|
||||
it('should leave the keys in the expected order', function () {
|
||||
const cache = new LRU(3)
|
||||
cache.set('key1', 'value1')
|
||||
cache.set('key2', 'value2')
|
||||
@@ -113,7 +113,7 @@ describe('The LRU cache', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('should clear', function() {
|
||||
it('should clear', function () {
|
||||
// Set up.
|
||||
const cache = new LRU(2)
|
||||
cache.set('key1', 'value1')
|
||||
|
||||
@@ -6,7 +6,7 @@ const { expect } = require('chai')
|
||||
const got = require('../got-test-client')
|
||||
const redirector = require('./redirector')
|
||||
|
||||
describe('Redirector', function() {
|
||||
describe('Redirector', function () {
|
||||
const route = {
|
||||
base: 'very/old/service',
|
||||
pattern: ':namedParamA',
|
||||
@@ -16,15 +16,15 @@ describe('Redirector', function() {
|
||||
const dateAdded = new Date()
|
||||
const attrs = { category, route, transformPath, dateAdded }
|
||||
|
||||
it('returns true on isDeprecated', function() {
|
||||
it('returns true on isDeprecated', function () {
|
||||
expect(redirector(attrs).isDeprecated).to.be.true
|
||||
})
|
||||
|
||||
it('has the expected name', function() {
|
||||
it('has the expected name', function () {
|
||||
expect(redirector(attrs).name).to.equal('VeryOldServiceRedirect')
|
||||
})
|
||||
|
||||
it('overrides the name', function() {
|
||||
it('overrides the name', function () {
|
||||
expect(
|
||||
redirector({
|
||||
...attrs,
|
||||
@@ -33,33 +33,33 @@ describe('Redirector', function() {
|
||||
).to.equal('ShinyRedirect')
|
||||
})
|
||||
|
||||
it('sets specified route', function() {
|
||||
it('sets specified route', function () {
|
||||
expect(redirector(attrs).route).to.deep.equal(route)
|
||||
})
|
||||
|
||||
it('sets specified category', function() {
|
||||
it('sets specified category', function () {
|
||||
expect(redirector(attrs).category).to.equal(category)
|
||||
})
|
||||
|
||||
it('throws the expected error when dateAdded is missing', function() {
|
||||
it('throws the expected error when dateAdded is missing', function () {
|
||||
expect(() =>
|
||||
redirector({ route, category, transformPath }).validateDefinition()
|
||||
).to.throw('"dateAdded" is required')
|
||||
})
|
||||
|
||||
describe('ScoutCamp integration', function() {
|
||||
describe('ScoutCamp integration', function () {
|
||||
let port, baseUrl
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
port = await portfinder.getPortPromise()
|
||||
baseUrl = `http://127.0.0.1:${port}`
|
||||
})
|
||||
|
||||
let camp
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
camp = Camp.start({ port, hostname: '::' })
|
||||
await new Promise(resolve => camp.on('listening', () => resolve()))
|
||||
})
|
||||
afterEach(async function() {
|
||||
afterEach(async function () {
|
||||
if (camp) {
|
||||
await new Promise(resolve => camp.close(resolve))
|
||||
camp = undefined
|
||||
@@ -68,7 +68,7 @@ describe('Redirector', function() {
|
||||
|
||||
const transformPath = ({ namedParamA }) => `/new/service/${namedParamA}`
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
const ServiceClass = redirector({
|
||||
category,
|
||||
route,
|
||||
@@ -81,7 +81,7 @@ describe('Redirector', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect as configured', async function() {
|
||||
it('should redirect as configured', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}/very/old/service/hello-world.svg`,
|
||||
{
|
||||
@@ -93,7 +93,7 @@ describe('Redirector', function() {
|
||||
expect(headers.location).to.equal('/new/service/hello-world.svg')
|
||||
})
|
||||
|
||||
it('should redirect raster extensions to the canonical path as configured', async function() {
|
||||
it('should redirect raster extensions to the canonical path as configured', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}/very/old/service/hello-world.png`,
|
||||
{
|
||||
@@ -107,7 +107,7 @@ describe('Redirector', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should forward the query params', async function() {
|
||||
it('should forward the query params', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}/very/old/service/hello-world.svg?color=123&style=flat-square`,
|
||||
{
|
||||
@@ -121,14 +121,14 @@ describe('Redirector', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('transformQueryParams', function() {
|
||||
describe('transformQueryParams', function () {
|
||||
const route = {
|
||||
base: 'another/old/service',
|
||||
pattern: 'token/:token/:namedParamA',
|
||||
}
|
||||
const transformQueryParams = ({ token }) => ({ token })
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
const ServiceClass = redirector({
|
||||
category,
|
||||
route,
|
||||
@@ -139,7 +139,7 @@ describe('Redirector', function() {
|
||||
ServiceClass.register({ camp }, {})
|
||||
})
|
||||
|
||||
it('should forward the transformed query params', async function() {
|
||||
it('should forward the transformed query params', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}/another/old/service/token/abc123/hello-world.svg`,
|
||||
{
|
||||
@@ -153,7 +153,7 @@ describe('Redirector', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should forward the specified and transformed query params', async function() {
|
||||
it('should forward the specified and transformed query params', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}/another/old/service/token/abc123/hello-world.svg?color=123&style=flat-square`,
|
||||
{
|
||||
@@ -167,7 +167,7 @@ describe('Redirector', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should use transformed query params on param conflicts by default', async function() {
|
||||
it('should use transformed query params on param conflicts by default', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}/another/old/service/token/abc123/hello-world.svg?color=123&style=flat-square&token=def456`,
|
||||
{
|
||||
@@ -181,7 +181,7 @@ describe('Redirector', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should use specified query params on param conflicts when configured', async function() {
|
||||
it('should use specified query params on param conflicts when configured', async function () {
|
||||
const route = {
|
||||
base: 'override/service',
|
||||
pattern: 'token/:token/:namedParamA',
|
||||
|
||||
@@ -9,9 +9,7 @@ function makeFullUrl(base, partialUrl) {
|
||||
}
|
||||
|
||||
const isValidRoute = Joi.object({
|
||||
base: Joi.string()
|
||||
.allow('')
|
||||
.required(),
|
||||
base: Joi.string().allow('').required(),
|
||||
pattern: Joi.string().allow(''),
|
||||
format: Joi.string(),
|
||||
capture: Joi.alternatives().conditional('format', {
|
||||
|
||||
@@ -9,8 +9,8 @@ const {
|
||||
getQueryParamNames,
|
||||
} = require('./route')
|
||||
|
||||
describe('Route helpers', function() {
|
||||
context('A `pattern` with a named param is declared', function() {
|
||||
describe('Route helpers', function () {
|
||||
context('A `pattern` with a named param is declared', function () {
|
||||
const { regex, captureNames } = prepareRoute({
|
||||
base: 'foo',
|
||||
pattern: ':namedParamA',
|
||||
@@ -36,7 +36,7 @@ describe('Route helpers', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('A `format` with a named param is declared', function() {
|
||||
context('A `format` with a named param is declared', function () {
|
||||
const { regex, captureNames } = prepareRoute({
|
||||
base: 'foo',
|
||||
format: '([^/]+?)',
|
||||
@@ -62,7 +62,7 @@ describe('Route helpers', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('No named params are declared', function() {
|
||||
context('No named params are declared', function () {
|
||||
const { regex, captureNames } = prepareRoute({
|
||||
base: 'foo',
|
||||
format: '(?:[^/]+)',
|
||||
@@ -78,7 +78,7 @@ describe('Route helpers', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('The wrong number of params are declared', function() {
|
||||
context('The wrong number of params are declared', function () {
|
||||
const { regex, captureNames } = prepareRoute({
|
||||
base: 'foo',
|
||||
format: '([^/]+)/([^/]+)',
|
||||
@@ -94,7 +94,7 @@ describe('Route helpers', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('getQueryParamNames', function() {
|
||||
it('getQueryParamNames', function () {
|
||||
expect(
|
||||
getQueryParamNames({
|
||||
queryParamSchema: Joi.object({ foo: Joi.string() }).required(),
|
||||
|
||||
@@ -5,10 +5,7 @@ const Joi = require('@hapi/joi')
|
||||
// This should be kept in sync with the schema in
|
||||
// `frontend/lib/service-definitions/index.ts`.
|
||||
|
||||
const arrayOfStrings = Joi.array()
|
||||
.items(Joi.string())
|
||||
.min(0)
|
||||
.required()
|
||||
const arrayOfStrings = Joi.array().items(Joi.string()).min(0).required()
|
||||
|
||||
const objectOfKeyValues = Joi.object()
|
||||
.pattern(/./, Joi.string().allow(null))
|
||||
@@ -39,9 +36,7 @@ const serviceDefinition = Joi.object({
|
||||
}).required(),
|
||||
preview: Joi.object({
|
||||
label: Joi.string(),
|
||||
message: Joi.string()
|
||||
.allow('')
|
||||
.required(),
|
||||
message: Joi.string().allow('').required(),
|
||||
color: Joi.string().required(),
|
||||
style: Joi.string(),
|
||||
namedLogo: Joi.string(),
|
||||
@@ -70,9 +65,7 @@ const serviceDefinitionExport = Joi.object({
|
||||
})
|
||||
)
|
||||
.required(),
|
||||
services: Joi.array()
|
||||
.items(serviceDefinition)
|
||||
.required(),
|
||||
services: Joi.array().items(serviceDefinition).required(),
|
||||
}).required()
|
||||
|
||||
function assertValidServiceDefinitionExport(examples, message = undefined) {
|
||||
|
||||
@@ -7,19 +7,19 @@ const trace = require('./trace')
|
||||
const { InvalidParameter } = require('./errors')
|
||||
const validate = require('./validate')
|
||||
|
||||
describe('validate', function() {
|
||||
describe('validate', function () {
|
||||
const schema = Joi.object({
|
||||
requiredString: Joi.string().required(),
|
||||
}).required()
|
||||
|
||||
let sandbox
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
sandbox.restore()
|
||||
})
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
sandbox.stub(trace, 'logTrace')
|
||||
})
|
||||
|
||||
@@ -35,8 +35,8 @@ describe('validate', function() {
|
||||
traceSuccessMessage,
|
||||
}
|
||||
|
||||
context('schema is not provided', function() {
|
||||
it('throws the expected programmer error', function() {
|
||||
context('schema is not provided', function () {
|
||||
it('throws the expected programmer error', function () {
|
||||
try {
|
||||
validate(options, { requiredString: 'bar' }, undefined)
|
||||
expect.fail('Expected to throw')
|
||||
@@ -47,8 +47,8 @@ describe('validate', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('data matches schema', function() {
|
||||
it('logs the data', function() {
|
||||
context('data matches schema', function () {
|
||||
it('logs the data', function () {
|
||||
validate(options, { requiredString: 'bar' }, schema)
|
||||
expect(trace.logTrace).to.be.calledWithMatch(
|
||||
'validate',
|
||||
@@ -60,8 +60,8 @@ describe('validate', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('data does not match schema', function() {
|
||||
it('logs the data and throws the expected error', function() {
|
||||
context('data does not match schema', function () {
|
||||
it('logs the data and throws the expected error', function () {
|
||||
try {
|
||||
validate(
|
||||
options,
|
||||
@@ -84,8 +84,8 @@ describe('validate', function() {
|
||||
)
|
||||
})
|
||||
|
||||
context('with includeKeys: true', function() {
|
||||
it('includes keys in the error text', function() {
|
||||
context('with includeKeys: true', function () {
|
||||
it('includes keys in the error text', function () {
|
||||
try {
|
||||
validate(
|
||||
{ ...options, includeKeys: true },
|
||||
@@ -108,7 +108,7 @@ describe('validate', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('allowAndStripUnknownKeys', function() {
|
||||
it('allowAndStripUnknownKeys', function () {
|
||||
try {
|
||||
validate(
|
||||
{ ...options, allowAndStripUnknownKeys: false, includeKeys: true },
|
||||
|
||||
@@ -6,7 +6,7 @@ const { expect } = require('chai')
|
||||
const log = require('./log')
|
||||
const InfluxMetrics = require('./influx-metrics')
|
||||
require('../register-chai-plugins.spec')
|
||||
describe('Influx metrics', function() {
|
||||
describe('Influx metrics', function () {
|
||||
const metricInstance = {
|
||||
metrics() {
|
||||
return [
|
||||
@@ -20,16 +20,16 @@ describe('Influx metrics', function() {
|
||||
]
|
||||
},
|
||||
}
|
||||
describe('"metrics" function', function() {
|
||||
describe('"metrics" function', function () {
|
||||
let osHostnameStub
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
nock.enableNetConnect()
|
||||
delete process.env.INSTANCE_ID
|
||||
if (osHostnameStub) {
|
||||
osHostnameStub.restore()
|
||||
}
|
||||
})
|
||||
it('should use an environment variable value as an instance label', async function() {
|
||||
it('should use an environment variable value as an instance label', async function () {
|
||||
process.env.INSTANCE_ID = 'instance3'
|
||||
const influxMetrics = new InfluxMetrics(metricInstance, {
|
||||
instanceIdFrom: 'env-var',
|
||||
@@ -39,7 +39,7 @@ describe('Influx metrics', function() {
|
||||
expect(influxMetrics.metrics()).to.contain('instance=instance3')
|
||||
})
|
||||
|
||||
it('should use a hostname as an instance label', async function() {
|
||||
it('should use a hostname as an instance label', async function () {
|
||||
osHostnameStub = sinon.stub(os, 'hostname').returns('test-hostname')
|
||||
const customConfig = {
|
||||
instanceIdFrom: 'hostname',
|
||||
@@ -49,7 +49,7 @@ describe('Influx metrics', function() {
|
||||
expect(influxMetrics.metrics()).to.be.contain('instance=test-hostname')
|
||||
})
|
||||
|
||||
it('should use a random string as an instance label', async function() {
|
||||
it('should use a random string as an instance label', async function () {
|
||||
const customConfig = {
|
||||
instanceIdFrom: 'random',
|
||||
}
|
||||
@@ -58,7 +58,7 @@ describe('Influx metrics', function() {
|
||||
expect(influxMetrics.metrics()).to.be.match(/instance=\w+ /)
|
||||
})
|
||||
|
||||
it('should use a hostname alias as an instance label', async function() {
|
||||
it('should use a hostname alias as an instance label', async function () {
|
||||
osHostnameStub = sinon.stub(os, 'hostname').returns('test-hostname')
|
||||
const customConfig = {
|
||||
instanceIdFrom: 'hostname',
|
||||
@@ -72,12 +72,12 @@ describe('Influx metrics', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('startPushingMetrics', function() {
|
||||
describe('startPushingMetrics', function () {
|
||||
let influxMetrics, clock
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
clock = sinon.useFakeTimers()
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
influxMetrics.stopPushingMetrics()
|
||||
nock.cleanAll()
|
||||
nock.enableNetConnect()
|
||||
@@ -85,7 +85,7 @@ describe('Influx metrics', function() {
|
||||
clock.restore()
|
||||
})
|
||||
|
||||
it('should send metrics', async function() {
|
||||
it('should send metrics', async function () {
|
||||
const scope = nock('http://shields-metrics.io/', {
|
||||
reqheaders: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
@@ -120,11 +120,11 @@ describe('Influx metrics', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('sendMetrics', function() {
|
||||
beforeEach(function() {
|
||||
describe('sendMetrics', function () {
|
||||
beforeEach(function () {
|
||||
sinon.stub(log, 'error')
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
log.error.restore()
|
||||
nock.cleanAll()
|
||||
nock.enableNetConnect()
|
||||
@@ -137,7 +137,7 @@ describe('Influx metrics', function() {
|
||||
username: 'metrics-username',
|
||||
password: 'metrics-password',
|
||||
})
|
||||
it('should log errors', async function() {
|
||||
it('should log errors', async function () {
|
||||
nock.disableNetConnect()
|
||||
|
||||
await influxMetrics.sendMetrics()
|
||||
@@ -154,11 +154,8 @@ describe('Influx metrics', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should log error responses', async function() {
|
||||
nock('http://shields-metrics.io/')
|
||||
.persist()
|
||||
.post('/metrics')
|
||||
.reply(400)
|
||||
it('should log error responses', async function () {
|
||||
nock('http://shields-metrics.io/').persist().post('/metrics').reply(400)
|
||||
|
||||
await influxMetrics.sendMetrics()
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
function generateInstanceId() {
|
||||
// from https://gist.github.com/gordonbrander/2230317
|
||||
return Math.random()
|
||||
.toString(36)
|
||||
.substr(2, 9)
|
||||
return Math.random().toString(36).substr(2, 9)
|
||||
}
|
||||
|
||||
module.exports = generateInstanceId
|
||||
|
||||
@@ -4,9 +4,9 @@ const { expect } = require('chai')
|
||||
const prometheus = require('prom-client')
|
||||
const { promClientJsonToInfluxV2 } = require('./format-converters')
|
||||
|
||||
describe('Metric format converters', function() {
|
||||
describe('prom-client JSON to InfluxDB line protocol (version 2)', function() {
|
||||
it('converts a counter', function() {
|
||||
describe('Metric format converters', function () {
|
||||
describe('prom-client JSON to InfluxDB line protocol (version 2)', function () {
|
||||
it('converts a counter', function () {
|
||||
const json = [
|
||||
{
|
||||
help: 'counter 1 help',
|
||||
@@ -22,7 +22,7 @@ describe('Metric format converters', function() {
|
||||
expect(influx).to.be.equal('prometheus counter1=11')
|
||||
})
|
||||
|
||||
it('converts a counter (from prometheus registry)', function() {
|
||||
it('converts a counter (from prometheus registry)', function () {
|
||||
const register = new prometheus.Registry()
|
||||
const counter = new prometheus.Counter({
|
||||
name: 'counter1',
|
||||
@@ -36,7 +36,7 @@ describe('Metric format converters', function() {
|
||||
expect(influx).to.be.equal('prometheus counter1=11')
|
||||
})
|
||||
|
||||
it('converts a gauge', function() {
|
||||
it('converts a gauge', function () {
|
||||
const json = [
|
||||
{
|
||||
help: 'gause 1 help',
|
||||
@@ -52,7 +52,7 @@ describe('Metric format converters', function() {
|
||||
expect(influx).to.be.equal('prometheus gauge1=20')
|
||||
})
|
||||
|
||||
it('converts a gauge (from prometheus registry)', function() {
|
||||
it('converts a gauge (from prometheus registry)', function () {
|
||||
const register = new prometheus.Registry()
|
||||
const gauge = new prometheus.Gauge({
|
||||
name: 'gauge1',
|
||||
@@ -66,13 +66,9 @@ describe('Metric format converters', function() {
|
||||
expect(influx).to.be.equal('prometheus gauge1=20')
|
||||
})
|
||||
|
||||
const sortLines = text =>
|
||||
text
|
||||
.split('\n')
|
||||
.sort()
|
||||
.join('\n')
|
||||
const sortLines = text => text.split('\n').sort().join('\n')
|
||||
|
||||
it('converts a histogram', function() {
|
||||
it('converts a histogram', function () {
|
||||
const json = [
|
||||
{
|
||||
name: 'histogram1',
|
||||
@@ -105,7 +101,7 @@ prometheus histogram1_count=3,histogram1_sum=111`)
|
||||
)
|
||||
})
|
||||
|
||||
it('converts a histogram (from prometheus registry)', function() {
|
||||
it('converts a histogram (from prometheus registry)', function () {
|
||||
const register = new prometheus.Registry()
|
||||
const histogram = new prometheus.Histogram({
|
||||
name: 'histogram1',
|
||||
@@ -128,7 +124,7 @@ prometheus histogram1_count=3,histogram1_sum=111`)
|
||||
)
|
||||
})
|
||||
|
||||
it('converts a summary', function() {
|
||||
it('converts a summary', function () {
|
||||
const json = [
|
||||
{
|
||||
name: 'summary1',
|
||||
@@ -155,7 +151,7 @@ prometheus summary1_count=3,summary1_sum=111`)
|
||||
)
|
||||
})
|
||||
|
||||
it('converts a summary (from prometheus registry)', function() {
|
||||
it('converts a summary (from prometheus registry)', function () {
|
||||
const register = new prometheus.Registry()
|
||||
const summary = new prometheus.Summary({
|
||||
name: 'summary1',
|
||||
@@ -177,7 +173,7 @@ prometheus summary1_count=3,summary1_sum=111`)
|
||||
)
|
||||
})
|
||||
|
||||
it('converts a counter and skip a timestamp', function() {
|
||||
it('converts a counter and skip a timestamp', function () {
|
||||
const json = [
|
||||
{
|
||||
help: 'counter 4 help',
|
||||
@@ -193,7 +189,7 @@ prometheus summary1_count=3,summary1_sum=111`)
|
||||
expect(influx).to.be.equal('prometheus counter4=11')
|
||||
})
|
||||
|
||||
it('converts a counter and adds extra labels', function() {
|
||||
it('converts a counter and adds extra labels', function () {
|
||||
const json = [
|
||||
{
|
||||
help: 'counter 1 help',
|
||||
|
||||
@@ -39,10 +39,7 @@ function setRoutes({ rateLimit }, { server, metricInstance }) {
|
||||
const ip =
|
||||
(req.headers['x-forwarded-for'] || '').split(', ')[0] ||
|
||||
req.socket.remoteAddress
|
||||
const badgeType = req.url
|
||||
.split(/[/-]/)
|
||||
.slice(0, 3)
|
||||
.join('')
|
||||
const badgeType = req.url.split(/[/-]/).slice(0, 3).join('')
|
||||
const referer = req.headers.referer
|
||||
|
||||
if (ipRateLimit.isBanned(ip, req, res)) {
|
||||
@@ -91,7 +88,7 @@ function setRoutes({ rateLimit }, { server, metricInstance }) {
|
||||
})
|
||||
})
|
||||
|
||||
return function() {
|
||||
return function () {
|
||||
ipRateLimit.stop()
|
||||
badgeTypeRateLimit.stop()
|
||||
refererRateLimit.stop()
|
||||
|
||||
@@ -6,15 +6,15 @@ const portfinder = require('portfinder')
|
||||
const got = require('../got-test-client')
|
||||
const Metrics = require('./prometheus-metrics')
|
||||
|
||||
describe('Prometheus metrics route', function() {
|
||||
describe('Prometheus metrics route', function () {
|
||||
let port, baseUrl, camp, metrics
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
port = await portfinder.getPortPromise()
|
||||
baseUrl = `http://127.0.0.1:${port}`
|
||||
camp = Camp.start({ port, hostname: '::' })
|
||||
await new Promise(resolve => camp.on('listening', () => resolve()))
|
||||
})
|
||||
afterEach(async function() {
|
||||
afterEach(async function () {
|
||||
if (metrics) {
|
||||
metrics.stop()
|
||||
}
|
||||
@@ -24,7 +24,7 @@ describe('Prometheus metrics route', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('returns default metrics', async function() {
|
||||
it('returns default metrics', async function () {
|
||||
metrics = new Metrics()
|
||||
metrics.registerMetricsEndpoint(camp)
|
||||
|
||||
|
||||
@@ -71,12 +71,8 @@ const publicConfigSchema = Joi.object({
|
||||
Joi.string().pattern(/^\\\\\.\\pipe\\.+$/)
|
||||
),
|
||||
address: Joi.alternatives().try(
|
||||
Joi.string()
|
||||
.ip()
|
||||
.required(),
|
||||
Joi.string()
|
||||
.hostname()
|
||||
.required()
|
||||
Joi.string().ip().required(),
|
||||
Joi.string().hostname().required()
|
||||
),
|
||||
},
|
||||
metrics: {
|
||||
@@ -119,9 +115,7 @@ const publicConfigSchema = Joi.object({
|
||||
redirectUrl: optionalUrl,
|
||||
rasterUrl: optionalUrl,
|
||||
cors: {
|
||||
allowedOrigin: Joi.array()
|
||||
.items(optionalUrl)
|
||||
.required(),
|
||||
allowedOrigin: Joi.array().items(optionalUrl).required(),
|
||||
},
|
||||
persistence: {
|
||||
dir: Joi.string().required(),
|
||||
@@ -133,10 +127,7 @@ const publicConfigSchema = Joi.object({
|
||||
baseUri: requiredUrl,
|
||||
debug: {
|
||||
enabled: Joi.boolean().required(),
|
||||
intervalSeconds: Joi.number()
|
||||
.integer()
|
||||
.min(1)
|
||||
.required(),
|
||||
intervalSeconds: Joi.number().integer().min(1).required(),
|
||||
},
|
||||
},
|
||||
jira: defaultService,
|
||||
@@ -152,9 +143,7 @@ const publicConfigSchema = Joi.object({
|
||||
trace: Joi.boolean().required(),
|
||||
}).required(),
|
||||
cacheHeaders: {
|
||||
defaultCacheLengthSeconds: Joi.number()
|
||||
.integer()
|
||||
.required(),
|
||||
defaultCacheLengthSeconds: Joi.number().integer().required(),
|
||||
},
|
||||
rateLimit: Joi.boolean().required(),
|
||||
handleInternalErrors: Joi.boolean().required(),
|
||||
|
||||
@@ -7,24 +7,24 @@ const got = require('../got-test-client')
|
||||
const Server = require('./server')
|
||||
const { createTestServer } = require('./in-process-server-test-helpers')
|
||||
|
||||
describe('The server', function() {
|
||||
describe('running', function() {
|
||||
describe('The server', function () {
|
||||
describe('running', function () {
|
||||
let server, baseUrl
|
||||
before('Start the server', async function() {
|
||||
before('Start the server', async function () {
|
||||
// Fixes https://github.com/badges/shields/issues/2611
|
||||
this.timeout(10000)
|
||||
server = await createTestServer()
|
||||
baseUrl = server.baseUrl
|
||||
await server.start()
|
||||
})
|
||||
after('Shut down the server', async function() {
|
||||
after('Shut down the server', async function () {
|
||||
if (server) {
|
||||
await server.stop()
|
||||
}
|
||||
server = undefined
|
||||
})
|
||||
|
||||
it('should allow strings for port', async function() {
|
||||
it('should allow strings for port', async function () {
|
||||
// fixes #4391 - This allows the app to be run using iisnode, which uses a named pipe for the port.
|
||||
const pipeServer = await createTestServer({
|
||||
public: {
|
||||
@@ -36,7 +36,7 @@ describe('The server', function() {
|
||||
expect(pipeServer).to.not.be.undefined
|
||||
})
|
||||
|
||||
it('should produce colorscheme badges', async function() {
|
||||
it('should produce colorscheme badges', async function () {
|
||||
const { statusCode, body } = await got(`${baseUrl}:fruit-apple-green.svg`)
|
||||
expect(statusCode).to.equal(200)
|
||||
expect(body)
|
||||
@@ -45,7 +45,7 @@ describe('The server', function() {
|
||||
.and.to.include('apple')
|
||||
})
|
||||
|
||||
it('should redirect colorscheme PNG badges as configured', async function() {
|
||||
it('should redirect colorscheme PNG badges as configured', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}:fruit-apple-green.png`,
|
||||
{
|
||||
@@ -58,7 +58,7 @@ describe('The server', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should redirect modern PNG badges as configured', async function() {
|
||||
it('should redirect modern PNG badges as configured', async function () {
|
||||
const { statusCode, headers } = await got(`${baseUrl}npm/v/express.png`, {
|
||||
followRedirect: false,
|
||||
})
|
||||
@@ -68,7 +68,7 @@ describe('The server', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should produce json badges', async function() {
|
||||
it('should produce json badges', async function () {
|
||||
const { statusCode, body, headers } = await got(
|
||||
`${baseUrl}twitter/follow/_Pyves.json`
|
||||
)
|
||||
@@ -77,16 +77,14 @@ describe('The server', function() {
|
||||
expect(() => JSON.parse(body)).not.to.throw()
|
||||
})
|
||||
|
||||
it('should preserve label case', async function() {
|
||||
it('should preserve label case', async function () {
|
||||
const { statusCode, body } = await got(`${baseUrl}:fRuiT-apple-green.svg`)
|
||||
expect(statusCode).to.equal(200)
|
||||
expect(body)
|
||||
.to.satisfy(isSvg)
|
||||
.and.to.include('fRuiT')
|
||||
expect(body).to.satisfy(isSvg).and.to.include('fRuiT')
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/pull/1319
|
||||
it('should not crash with a numeric logo', async function() {
|
||||
it('should not crash with a numeric logo', async function () {
|
||||
const { statusCode, body } = await got(
|
||||
`${baseUrl}:fruit-apple-green.svg?logo=1`
|
||||
)
|
||||
@@ -97,7 +95,7 @@ describe('The server', function() {
|
||||
.and.to.include('apple')
|
||||
})
|
||||
|
||||
it('should not crash with a numeric link', async function() {
|
||||
it('should not crash with a numeric link', async function () {
|
||||
const { statusCode, body } = await got(
|
||||
`${baseUrl}:fruit-apple-green.svg?link=1`
|
||||
)
|
||||
@@ -108,7 +106,7 @@ describe('The server', function() {
|
||||
.and.to.include('apple')
|
||||
})
|
||||
|
||||
it('should not crash with a boolean link', async function() {
|
||||
it('should not crash with a boolean link', async function () {
|
||||
const { statusCode, body } = await got(
|
||||
`${baseUrl}:fruit-apple-green.svg?link=true`
|
||||
)
|
||||
@@ -119,7 +117,7 @@ describe('The server', function() {
|
||||
.and.to.include('apple')
|
||||
})
|
||||
|
||||
it('should return the 404 badge for unknown badges', async function() {
|
||||
it('should return the 404 badge for unknown badges', async function () {
|
||||
const { statusCode, body } = await got(
|
||||
`${baseUrl}this/is/not/a/badge.svg`,
|
||||
{
|
||||
@@ -133,7 +131,7 @@ describe('The server', function() {
|
||||
.and.to.include('badge not found')
|
||||
})
|
||||
|
||||
it('should return the 404 badge page for rando links', async function() {
|
||||
it('should return the 404 badge page for rando links', async function () {
|
||||
const { statusCode, body } = await got(
|
||||
`${baseUrl}this/is/most/definitely/not/a/badge.js`,
|
||||
{
|
||||
@@ -147,7 +145,7 @@ describe('The server', function() {
|
||||
.and.to.include('badge not found')
|
||||
})
|
||||
|
||||
it('should redirect the root as configured', async function() {
|
||||
it('should redirect the root as configured', async function () {
|
||||
const { statusCode, headers } = await got(baseUrl, {
|
||||
followRedirect: false,
|
||||
})
|
||||
@@ -157,7 +155,7 @@ describe('The server', function() {
|
||||
expect(headers.location).to.equal('http://frontend.example.test')
|
||||
})
|
||||
|
||||
it('should return the 410 badge for obsolete formats', async function() {
|
||||
it('should return the 410 badge for obsolete formats', async function () {
|
||||
const { statusCode, body } = await got(`${baseUrl}npm/v/express.jpg`, {
|
||||
throwHttpErrors: false,
|
||||
})
|
||||
@@ -170,15 +168,15 @@ describe('The server', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('configuration', function() {
|
||||
describe('configuration', function () {
|
||||
let server
|
||||
afterEach(async function() {
|
||||
afterEach(async function () {
|
||||
if (server) {
|
||||
server.stop()
|
||||
}
|
||||
})
|
||||
|
||||
it('should allow to enable prometheus metrics', async function() {
|
||||
it('should allow to enable prometheus metrics', async function () {
|
||||
// Fixes https://github.com/badges/shields/issues/2611
|
||||
this.timeout(10000)
|
||||
server = await createTestServer({
|
||||
@@ -193,7 +191,7 @@ describe('The server', function() {
|
||||
expect(statusCode).to.be.equal(200)
|
||||
})
|
||||
|
||||
it('should allow to disable prometheus metrics', async function() {
|
||||
it('should allow to disable prometheus metrics', async function () {
|
||||
// Fixes https://github.com/badges/shields/issues/2611
|
||||
this.timeout(10000)
|
||||
server = await createTestServer({
|
||||
@@ -211,10 +209,10 @@ describe('The server', function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe('configuration validation', function() {
|
||||
describe('influx', function() {
|
||||
describe('configuration validation', function () {
|
||||
describe('influx', function () {
|
||||
let customConfig
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
customConfig = config.util.toObject()
|
||||
customConfig.public.metrics.influx = {
|
||||
enabled: true,
|
||||
@@ -232,46 +230,46 @@ describe('The server', function() {
|
||||
}
|
||||
})
|
||||
|
||||
it('should not require influx configuration', function() {
|
||||
it('should not require influx configuration', function () {
|
||||
delete customConfig.public.metrics.influx
|
||||
expect(() => new Server(config.util.toObject())).to.not.throw()
|
||||
})
|
||||
|
||||
it('should require url when influx configuration is enabled', function() {
|
||||
it('should require url when influx configuration is enabled', function () {
|
||||
delete customConfig.public.metrics.influx.url
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'"metrics.influx.url" is required'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not require url when influx configuration is disabled', function() {
|
||||
it('should not require url when influx configuration is disabled', function () {
|
||||
customConfig.public.metrics.influx.enabled = false
|
||||
delete customConfig.public.metrics.influx.url
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
it('should require timeoutMilliseconds when influx configuration is enabled', function() {
|
||||
it('should require timeoutMilliseconds when influx configuration is enabled', function () {
|
||||
delete customConfig.public.metrics.influx.timeoutMilliseconds
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'"metrics.influx.timeoutMilliseconds" is required'
|
||||
)
|
||||
})
|
||||
|
||||
it('should require intervalSeconds when influx configuration is enabled', function() {
|
||||
it('should require intervalSeconds when influx configuration is enabled', function () {
|
||||
delete customConfig.public.metrics.influx.intervalSeconds
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'"metrics.influx.intervalSeconds" is required'
|
||||
)
|
||||
})
|
||||
|
||||
it('should require instanceIdFrom when influx configuration is enabled', function() {
|
||||
it('should require instanceIdFrom when influx configuration is enabled', function () {
|
||||
delete customConfig.public.metrics.influx.instanceIdFrom
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'"metrics.influx.instanceIdFrom" is required'
|
||||
)
|
||||
})
|
||||
|
||||
it('should require instanceIdEnvVarName when instanceIdFrom is env-var', function() {
|
||||
it('should require instanceIdEnvVarName when instanceIdFrom is env-var', function () {
|
||||
customConfig.public.metrics.influx.instanceIdFrom = 'env-var'
|
||||
delete customConfig.public.metrics.influx.instanceIdEnvVarName
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
@@ -279,53 +277,53 @@ describe('The server', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('should allow instanceIdFrom = hostname', function() {
|
||||
it('should allow instanceIdFrom = hostname', function () {
|
||||
customConfig.public.metrics.influx.instanceIdFrom = 'hostname'
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
it('should allow instanceIdFrom = env-var', function() {
|
||||
it('should allow instanceIdFrom = env-var', function () {
|
||||
customConfig.public.metrics.influx.instanceIdFrom = 'env-var'
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
it('should allow instanceIdFrom = random', function() {
|
||||
it('should allow instanceIdFrom = random', function () {
|
||||
customConfig.public.metrics.influx.instanceIdFrom = 'random'
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
it('should require envLabel when influx configuration is enabled', function() {
|
||||
it('should require envLabel when influx configuration is enabled', function () {
|
||||
delete customConfig.public.metrics.influx.envLabel
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'"metrics.influx.envLabel" is required'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not require hostnameAliases', function() {
|
||||
it('should not require hostnameAliases', function () {
|
||||
delete customConfig.public.metrics.influx.hostnameAliases
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
it('should allow empty hostnameAliases', function() {
|
||||
it('should allow empty hostnameAliases', function () {
|
||||
customConfig.public.metrics.influx.hostnameAliases = {}
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
it('should require username when influx configuration is enabled', function() {
|
||||
it('should require username when influx configuration is enabled', function () {
|
||||
delete customConfig.private.influx_username
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'Private configuration is invalid. Check these paths: influx_username'
|
||||
)
|
||||
})
|
||||
|
||||
it('should require password when influx configuration is enabled', function() {
|
||||
it('should require password when influx configuration is enabled', function () {
|
||||
delete customConfig.private.influx_password
|
||||
expect(() => new Server(customConfig)).to.throw(
|
||||
'Private configuration is invalid. Check these paths: influx_password'
|
||||
)
|
||||
})
|
||||
|
||||
it('should allow other private keys', function() {
|
||||
it('should allow other private keys', function () {
|
||||
customConfig.private.gh_token = 'my-token'
|
||||
expect(() => new Server(customConfig)).to.not.throw()
|
||||
})
|
||||
|
||||
@@ -73,7 +73,7 @@ if (process.env.TESTED_SERVER_URL) {
|
||||
} else {
|
||||
const port = 1111
|
||||
baseUrl = 'http://localhost:1111'
|
||||
before('Start running the server', async function() {
|
||||
before('Start running the server', async function () {
|
||||
server = await createTestServer({
|
||||
public: {
|
||||
bind: {
|
||||
@@ -83,7 +83,7 @@ if (process.env.TESTED_SERVER_URL) {
|
||||
})
|
||||
server.start()
|
||||
})
|
||||
after('Shut down the server', async function() {
|
||||
after('Shut down the server', async function () {
|
||||
if (server) {
|
||||
await server.stop()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ const {
|
||||
inferPullRequest,
|
||||
} = require('./infer-pull-request')
|
||||
|
||||
describe('Pull request inference', function() {
|
||||
describe('Pull request inference', function () {
|
||||
test(parseGithubPullRequestUrl, () => {
|
||||
forCases([
|
||||
given('https://github.com/badges/shields/pull/1234'),
|
||||
|
||||
@@ -85,7 +85,7 @@ class ServiceTester {
|
||||
this.beforeEach()
|
||||
})
|
||||
// eslint-disable-next-line mocha/prefer-arrow-callback
|
||||
.finally(function() {
|
||||
.finally(function () {
|
||||
// `this` is the IcedFrisby instance.
|
||||
let responseBody
|
||||
try {
|
||||
@@ -125,7 +125,7 @@ class ServiceTester {
|
||||
|
||||
const fn = this._only ? describe.only : describe
|
||||
// eslint-disable-next-line mocha/prefer-arrow-callback
|
||||
fn(this.title, function() {
|
||||
fn(this.title, function () {
|
||||
specs.forEach(spec => {
|
||||
spec._message = `[${spec.hasIntercept ? 'mocked' : 'live'}] ${
|
||||
spec._message
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const { test, given } = require('sazerac')
|
||||
const servicesForTitle = require('./services-for-title')
|
||||
|
||||
describe('Services from PR title', function() {
|
||||
describe('Services from PR title', function () {
|
||||
test(servicesForTitle, () => {
|
||||
given('[Travis] Fix timeout issues').expect(['travis'])
|
||||
given('[Travis Sonar] Support user token authentication').expect([
|
||||
|
||||
@@ -6,20 +6,20 @@ const readFile = require('fs-readfile-promise')
|
||||
const { expect } = require('chai')
|
||||
const FsTokenPersistence = require('./fs-token-persistence')
|
||||
|
||||
describe('File system token persistence', function() {
|
||||
describe('File system token persistence', function () {
|
||||
let path, persistence
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
path = tmp.tmpNameSync()
|
||||
persistence = new FsTokenPersistence({ path })
|
||||
})
|
||||
|
||||
context('when the file does not exist', function() {
|
||||
it('does nothing', async function() {
|
||||
context('when the file does not exist', function () {
|
||||
it('does nothing', async function () {
|
||||
const tokens = await persistence.initialize()
|
||||
expect(tokens).to.deep.equal([])
|
||||
})
|
||||
|
||||
it('saving creates an empty file', async function() {
|
||||
it('saving creates an empty file', async function () {
|
||||
await persistence.initialize()
|
||||
|
||||
await persistence.save()
|
||||
@@ -29,20 +29,20 @@ describe('File system token persistence', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when the file exists', function() {
|
||||
context('when the file exists', function () {
|
||||
const initialTokens = ['a', 'b', 'c'].map(char => char.repeat(40))
|
||||
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
fs.writeFileSync(path, JSON.stringify(initialTokens))
|
||||
})
|
||||
|
||||
it('loads the contents', async function() {
|
||||
it('loads the contents', async function () {
|
||||
const tokens = await persistence.initialize()
|
||||
expect(tokens).to.deep.equal(initialTokens)
|
||||
})
|
||||
|
||||
context('when tokens are added', function() {
|
||||
it('saves the change', async function() {
|
||||
context('when tokens are added', function () {
|
||||
it('saves the change', async function () {
|
||||
const newToken = 'e'.repeat(40)
|
||||
const expected = Array.from(initialTokens)
|
||||
expected.push(newToken)
|
||||
@@ -55,8 +55,8 @@ describe('File system token persistence', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when tokens are removed', function() {
|
||||
it('saves the change', async function() {
|
||||
context('when tokens are removed', function () {
|
||||
it('saves the change', async function () {
|
||||
const expected = Array.from(initialTokens)
|
||||
const toRemove = expected.pop()
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ const Redis = require('ioredis')
|
||||
const { expect } = require('chai')
|
||||
const RedisTokenPersistence = require('./redis-token-persistence')
|
||||
|
||||
describe('Redis token persistence', function() {
|
||||
describe('Redis token persistence', function () {
|
||||
let server
|
||||
// In CI, expect redis already to be running.
|
||||
if (!process.env.CI) {
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
server = new RedisServer({ config: { host: 'localhost' } })
|
||||
await server.open()
|
||||
})
|
||||
@@ -18,11 +18,11 @@ describe('Redis token persistence', function() {
|
||||
const key = 'tokenPersistenceIntegrationTest'
|
||||
|
||||
let redis
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
redis = new Redis()
|
||||
await redis.del(key)
|
||||
})
|
||||
afterEach(async function() {
|
||||
afterEach(async function () {
|
||||
if (redis) {
|
||||
await redis.quit()
|
||||
redis = undefined
|
||||
@@ -30,44 +30,44 @@ describe('Redis token persistence', function() {
|
||||
})
|
||||
|
||||
if (!process.env.CI) {
|
||||
afterEach(async function() {
|
||||
afterEach(async function () {
|
||||
await server.close()
|
||||
server = undefined
|
||||
})
|
||||
}
|
||||
|
||||
let persistence
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
persistence = new RedisTokenPersistence({ key })
|
||||
})
|
||||
afterEach(async function() {
|
||||
afterEach(async function () {
|
||||
if (persistence) {
|
||||
await persistence.stop()
|
||||
persistence = undefined
|
||||
}
|
||||
})
|
||||
|
||||
context('when the key does not exist', function() {
|
||||
it('does nothing', async function() {
|
||||
context('when the key does not exist', function () {
|
||||
it('does nothing', async function () {
|
||||
const tokens = await persistence.initialize()
|
||||
expect(tokens).to.deep.equal([])
|
||||
})
|
||||
})
|
||||
|
||||
context('when the key exists', function() {
|
||||
context('when the key exists', function () {
|
||||
const initialTokens = ['a', 'b', 'c'].map(char => char.repeat(40))
|
||||
|
||||
beforeEach(async function() {
|
||||
beforeEach(async function () {
|
||||
await redis.sadd(key, initialTokens)
|
||||
})
|
||||
|
||||
it('loads the contents', async function() {
|
||||
it('loads the contents', async function () {
|
||||
const tokens = await persistence.initialize()
|
||||
expect(tokens.sort()).to.deep.equal(initialTokens)
|
||||
})
|
||||
|
||||
context('when tokens are added', function() {
|
||||
it('saves the change', async function() {
|
||||
context('when tokens are added', function () {
|
||||
it('saves the change', async function () {
|
||||
const newToken = 'e'.repeat(40)
|
||||
const expected = initialTokens.slice()
|
||||
expected.push(newToken)
|
||||
@@ -80,8 +80,8 @@ describe('Redis token persistence', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when tokens are removed', function() {
|
||||
it('saves the change', async function() {
|
||||
context('when tokens are removed', function () {
|
||||
it('saves the change', async function () {
|
||||
const expected = Array.from(initialTokens)
|
||||
const toRemove = expected.pop()
|
||||
|
||||
|
||||
@@ -13,10 +13,7 @@ const PriorityQueue = require('priorityqueuejs')
|
||||
* @returns {string} hash
|
||||
*/
|
||||
function sanitizeToken(id) {
|
||||
return crypto
|
||||
.createHash('sha256')
|
||||
.update(id, 'utf-8')
|
||||
.digest('hex')
|
||||
return crypto.createHash('sha256').update(id, 'utf-8').digest('hex')
|
||||
}
|
||||
|
||||
function getUtcEpochSeconds() {
|
||||
|
||||
@@ -11,27 +11,27 @@ function expectPoolToBeExhausted(pool) {
|
||||
}).to.throw(Error, /^Token pool is exhausted$/)
|
||||
}
|
||||
|
||||
describe('The token pool', function() {
|
||||
describe('The token pool', function () {
|
||||
const ids = ['1', '2', '3', '4', '5']
|
||||
const batchSize = 3
|
||||
|
||||
let tokenPool
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
tokenPool = new TokenPool({ batchSize })
|
||||
ids.forEach(id => tokenPool.add(id))
|
||||
})
|
||||
|
||||
it('allValidTokenIds() should return the full list', function() {
|
||||
it('allValidTokenIds() should return the full list', function () {
|
||||
expect(tokenPool.allValidTokenIds()).to.deep.equal(ids)
|
||||
})
|
||||
|
||||
it('should yield the expected tokens', function() {
|
||||
it('should yield the expected tokens', function () {
|
||||
ids.forEach(id =>
|
||||
times(batchSize, () => expect(tokenPool.next().id).to.equal(id))
|
||||
)
|
||||
})
|
||||
|
||||
it('should repeat when reaching the end', function() {
|
||||
it('should repeat when reaching the end', function () {
|
||||
ids.forEach(id =>
|
||||
times(batchSize, () => expect(tokenPool.next().id).to.equal(id))
|
||||
)
|
||||
@@ -40,17 +40,17 @@ describe('The token pool', function() {
|
||||
)
|
||||
})
|
||||
|
||||
describe('serializeDebugInfo should initially return the expected', function() {
|
||||
beforeEach(function() {
|
||||
describe('serializeDebugInfo should initially return the expected', function () {
|
||||
beforeEach(function () {
|
||||
sinon.useFakeTimers({ now: 1544307744484 })
|
||||
})
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
sinon.restore()
|
||||
})
|
||||
|
||||
context('sanitize is not specified', function() {
|
||||
it('returns fully sanitized results', function() {
|
||||
context('sanitize is not specified', function () {
|
||||
it('returns fully sanitized results', function () {
|
||||
// This is `sha()` of '1', '2', '3', '4', '5'. These are written
|
||||
// literally for avoidance of doubt as to whether sanitization is
|
||||
// happening.
|
||||
@@ -79,8 +79,8 @@ describe('The token pool', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('with sanitize: false', function() {
|
||||
it('returns unsanitized results', function() {
|
||||
context('with sanitize: false', function () {
|
||||
it('returns unsanitized results', function () {
|
||||
expect(tokenPool.serializeDebugInfo({ sanitize: false })).to.deep.equal(
|
||||
{
|
||||
allValidTokenIds: ids,
|
||||
@@ -101,8 +101,8 @@ describe('The token pool', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('tokens are marked exhausted immediately', function() {
|
||||
it('should be exhausted', function() {
|
||||
context('tokens are marked exhausted immediately', function () {
|
||||
it('should be exhausted', function () {
|
||||
ids.forEach(() => {
|
||||
const token = tokenPool.next()
|
||||
token.update(0, Token.nextResetNever)
|
||||
@@ -112,8 +112,8 @@ describe('The token pool', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('tokens are marked after the last request', function() {
|
||||
it('should be exhausted', function() {
|
||||
context('tokens are marked after the last request', function () {
|
||||
it('should be exhausted', function () {
|
||||
ids.forEach(() => {
|
||||
const token = times(batchSize, () => tokenPool.next()).pop()
|
||||
token.update(0, Token.nextResetNever)
|
||||
@@ -123,8 +123,8 @@ describe('The token pool', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('tokens are renewed', function() {
|
||||
it('should keep using them', function() {
|
||||
context('tokens are renewed', function () {
|
||||
it('should keep using them', function () {
|
||||
const tokensToRenew = ['2', '4']
|
||||
const renewalCount = 3
|
||||
|
||||
@@ -149,16 +149,16 @@ describe('The token pool', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('tokens reset', function() {
|
||||
context('tokens reset', function () {
|
||||
let clock
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
clock = sinon.useFakeTimers()
|
||||
})
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
clock.restore()
|
||||
})
|
||||
|
||||
it('should start using them', function() {
|
||||
it('should start using them', function () {
|
||||
const tokensToReset = ['2', '4']
|
||||
const futureTime = 1440
|
||||
|
||||
@@ -183,8 +183,8 @@ describe('The token pool', function() {
|
||||
})
|
||||
})
|
||||
|
||||
context('when empty', function() {
|
||||
it('next() should return the expected error', function() {
|
||||
context('when empty', function () {
|
||||
it('next() should return the expected error', function () {
|
||||
const tokenPool = new TokenPool()
|
||||
expect(() => tokenPool.next()).to.throw('Token pool is exhausted')
|
||||
})
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
'use strict'
|
||||
|
||||
describe('Main page', function() {
|
||||
describe('Main page', function () {
|
||||
const backendUrl = Cypress.env('backend_url')
|
||||
const SEARCH_INPUT = 'input[placeholder="search / project URL"]'
|
||||
|
||||
function expectBadgeExample(title, previewUrl, pattern) {
|
||||
cy.contains('tr', `${title}:`)
|
||||
.find('code')
|
||||
.should('have.text', pattern)
|
||||
cy.contains('tr', `${title}:`).find('code').should('have.text', pattern)
|
||||
cy.contains('tr', `${title}:`)
|
||||
.find('img')
|
||||
.should('have.attr', 'src', previewUrl)
|
||||
}
|
||||
|
||||
it('Search for badges', function() {
|
||||
it('Search for badges', function () {
|
||||
cy.visit('/')
|
||||
|
||||
cy.get(SEARCH_INPUT).type('pypi')
|
||||
@@ -21,7 +19,7 @@ describe('Main page', function() {
|
||||
cy.contains('PyPI - License')
|
||||
})
|
||||
|
||||
it('Shows badge from category', function() {
|
||||
it('Shows badge from category', function () {
|
||||
cy.visit('/category/chat')
|
||||
|
||||
expectBadgeExample(
|
||||
@@ -31,7 +29,7 @@ describe('Main page', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('Suggest badges', function() {
|
||||
it('Suggest badges', function () {
|
||||
const badgeUrl = `${backendUrl}/github/issues/badges/shields`
|
||||
cy.visit('/')
|
||||
|
||||
@@ -41,7 +39,7 @@ describe('Main page', function() {
|
||||
expectBadgeExample('GitHub issues', badgeUrl, badgeUrl)
|
||||
})
|
||||
|
||||
it('Customization form is filled with suggested badge details', function() {
|
||||
it('Customization form is filled with suggested badge details', function () {
|
||||
const badgeUrl = `${backendUrl}/github/issues/badges/shields`
|
||||
cy.visit('/')
|
||||
cy.get(SEARCH_INPUT).type('https://github.com/badges/shields')
|
||||
@@ -53,7 +51,7 @@ describe('Main page', function() {
|
||||
cy.get('input[name="repo"]').should('have.value', 'shields')
|
||||
})
|
||||
|
||||
it('Customizate suggested badge', function() {
|
||||
it('Customizate suggested badge', function () {
|
||||
const badgeUrl = `${backendUrl}/github/issues/badges/shields`
|
||||
cy.visit('/')
|
||||
cy.get(SEARCH_INPUT).type('https://github.com/badges/shields')
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = class ExampleService extends LegacyService {
|
||||
static registerLegacyRouteHandler({ camp, cache }) {
|
||||
camp.route(
|
||||
/^\/example\/([^\/]+)\/([^\/]+)\.(svg|png|gif|jpg|json)$/,
|
||||
cache(function(data, match, sendBadge, request) {
|
||||
cache(function (data, match, sendBadge, request) {
|
||||
var first = match[1]
|
||||
var second = match[2]
|
||||
var format = match[3]
|
||||
|
||||
@@ -5,7 +5,7 @@ const isSvg = require('is-svg')
|
||||
const got = require('./core/got-test-client')
|
||||
|
||||
let server
|
||||
before(function() {
|
||||
before(function () {
|
||||
this.timeout('5s')
|
||||
// remove args comming from mocha
|
||||
// https://github.com/badges/shields/issues/3365
|
||||
@@ -13,17 +13,14 @@ before(function() {
|
||||
server = require('./server')
|
||||
})
|
||||
|
||||
after('shut down the server', async function() {
|
||||
after('shut down the server', async function () {
|
||||
await server.stop()
|
||||
})
|
||||
|
||||
it('should render a badge', async function() {
|
||||
it('should render a badge', async function () {
|
||||
const { statusCode, body } = await got(
|
||||
'http://localhost:1111/badge/fruit-apple-green.svg'
|
||||
)
|
||||
expect(statusCode).to.equal(200)
|
||||
expect(body)
|
||||
.to.satisfy(isSvg)
|
||||
.and.to.include('fruit')
|
||||
.and.to.include('apple')
|
||||
expect(body).to.satisfy(isSvg).and.to.include('fruit').and.to.include('apple')
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { test, given } from 'sazerac'
|
||||
import { patternToOptions, removeRegexpFromPattern } from './pattern-helpers'
|
||||
|
||||
describe('Badge URL functions', function() {
|
||||
describe('Badge URL functions', function () {
|
||||
test(patternToOptions, () => {
|
||||
given('[^\\/]+?').expect(undefined)
|
||||
given('abc|[^\\/]+').expect(undefined)
|
||||
|
||||
@@ -2,13 +2,13 @@ import { expect } from 'chai'
|
||||
import { test, given } from 'sazerac'
|
||||
import { findCategory, getDefinitionsForCategory } from '.'
|
||||
|
||||
describe('Service definition helpers', function() {
|
||||
describe('Service definition helpers', function () {
|
||||
test(findCategory, () => {
|
||||
given('build').expect({ id: 'build', name: 'Build', keywords: ['build'] })
|
||||
given('foo').expect(undefined)
|
||||
})
|
||||
|
||||
it('getDefinitionsForCategory', function() {
|
||||
it('getDefinitionsForCategory', function () {
|
||||
expect(getDefinitionsForCategory('build'))
|
||||
.to.have.length.greaterThan(10)
|
||||
.and.lessThan(75)
|
||||
|
||||
@@ -2,7 +2,7 @@ import { test, given, forCases } from 'sazerac'
|
||||
import { predicateFromQuery } from './service-definition-set-helper'
|
||||
import { Example } from '.'
|
||||
|
||||
describe('Badge example functions', function() {
|
||||
describe('Badge example functions', function () {
|
||||
function exampleMatchesQuery(
|
||||
{ examples }: { examples: Example[] },
|
||||
query: string
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
const { expect } = require('chai')
|
||||
const loadSimpleIcons = require('./load-simple-icons')
|
||||
|
||||
describe('loadSimpleIcons', function() {
|
||||
describe('loadSimpleIcons', function () {
|
||||
let simpleIcons
|
||||
before(function() {
|
||||
before(function () {
|
||||
simpleIcons = loadSimpleIcons()
|
||||
})
|
||||
|
||||
it('prepares three color themes', function() {
|
||||
it('prepares three color themes', function () {
|
||||
expect(simpleIcons.sentry.base64).to.have.all.keys(
|
||||
'default',
|
||||
'light',
|
||||
@@ -17,13 +17,13 @@ describe('loadSimpleIcons', function() {
|
||||
)
|
||||
})
|
||||
|
||||
it('normalizes icon keys', function() {
|
||||
it('normalizes icon keys', function () {
|
||||
// original key in the simple-icons is 'Linux Foundation'
|
||||
expect(simpleIcons).to.include.key('linux-foundation')
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/issues/4016
|
||||
it('excludes "get" function provided by the simple-icons', function() {
|
||||
it('excludes "get" function provided by the simple-icons', function () {
|
||||
expect(simpleIcons).to.not.have.property('get')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ const {
|
||||
makeLogo,
|
||||
} = require('./logos')
|
||||
|
||||
describe('Logo helpers', function() {
|
||||
describe('Logo helpers', function () {
|
||||
test(prependPrefix, () => {
|
||||
given('data:image/svg+xml;base64,PHN2ZyB4bWxu', 'data:').expect(
|
||||
'data:image/svg+xml;base64,PHN2ZyB4bWxu'
|
||||
@@ -46,7 +46,7 @@ describe('Logo helpers', function() {
|
||||
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1NCA1NCIgZmlsbD0iIzAwN2VjNiI+PHBhdGggZD0iTTI1IDNhMSAxIDAgMCAwLTEgMXY3YTEgMSAwIDAgMCAxIDFoNXYzSDZhMyAzIDAgMCAwLTMgM3YxMkgxYTEgMSAwIDAgMC0xIDF2MTBhMSAxIDAgMCAwIDEgMWgydjZhMyAzIDAgMCAwIDMgM2g0MmEzIDMgMCAwIDAgMy0zdi02aDJhMSAxIDAgMCAwIDEtMVYzMWExIDEgMCAwIDAtMS0xaC0yVjE4YTMgMyAwIDAgMC0zLTNIMzNWNGExIDEgMCAwIDAtMS0xaC03em0tMy45ODIgMjZhMS4yMSAxLjIxIDAgMCAxIC44MzcuMzU1bDEuMjkgMS4yOWExLjIxIDEuMjEgMCAwIDEgMCAxLjcwOSAxLjIxIDEuMjEgMCAwIDEgMCAuMDAxbC02LjI5MSA2LjI5YTEuMjEgMS4yMSAwIDAgMS0xLjcxIDBsLTMuNzktMy43OTFhMS4yMSAxLjIxIDAgMCAxIDAtMS43MWwxLjI5LTEuMjlhMS4yMSAxLjIxIDAgMCAxIDEuNzEgMEwxNiAzMy41bDQuMTQ1LTQuMTQ1YTEuMjEgMS4yMSAwIDAgMSAuODczLS4zNTV6bTE5Ljk2MiAwYTEuMjEgMS4yMSAwIDAgMSAuODc0LjM1NGwxLjI5IDEuMjlhMS4yMSAxLjIxIDAgMCAxIDAgMS43MWwtNi4yOSA2LjI4OXYuMDAyYTEuMjEgMS4yMSAwIDAgMS0xLjcxMSAwbC0zLjc5LTMuNzlhMS4yMSAxLjIxIDAgMCAxIDAtMS43MWwxLjI5LTEuMjlhMS4yMSAxLjIxIDAgMCAxIDEuNzEgMGwxLjY0NSAxLjY0NSA0LjE0Ny00LjE0NkExLjIxIDEuMjEgMCAwIDEgNDAuOTggMjl6Ii8+PC9zdmc+'
|
||||
)
|
||||
|
||||
it('preserves color if light logo on dark background', function() {
|
||||
it('preserves color if light logo on dark background', function () {
|
||||
const logo = prepareNamedLogo({ name: 'javascript' })
|
||||
const decodedLogo = Buffer.from(
|
||||
logo.replace('data:image/svg+xml;base64,', ''),
|
||||
@@ -54,7 +54,7 @@ describe('Logo helpers', function() {
|
||||
).toString('ascii')
|
||||
expect(decodedLogo).to.contain('fill="#F7DF1E"')
|
||||
})
|
||||
it('recolors logo if light logo on light background', function() {
|
||||
it('recolors logo if light logo on light background', function () {
|
||||
const logo = prepareNamedLogo({ name: 'javascript', style: 'social' })
|
||||
const decodedLogo = Buffer.from(
|
||||
logo.replace('data:image/svg+xml;base64,', ''),
|
||||
@@ -63,7 +63,7 @@ describe('Logo helpers', function() {
|
||||
expect(decodedLogo).to.contain('fill="#333"')
|
||||
})
|
||||
|
||||
it('preserves color if dark logo on light background', function() {
|
||||
it('preserves color if dark logo on light background', function () {
|
||||
const logo = prepareNamedLogo({ name: 'nuget', style: 'social' })
|
||||
const decodedLogo = Buffer.from(
|
||||
logo.replace('data:image/svg+xml;base64,', ''),
|
||||
@@ -71,7 +71,7 @@ describe('Logo helpers', function() {
|
||||
).toString('ascii')
|
||||
expect(decodedLogo).to.contain('fill="#004880"')
|
||||
})
|
||||
it('recolors logo if dark logo on dark background', function() {
|
||||
it('recolors logo if dark logo on dark background', function () {
|
||||
const logo = prepareNamedLogo({ name: 'nuget' })
|
||||
const decodedLogo = Buffer.from(
|
||||
logo.replace('data:image/svg+xml;base64,', ''),
|
||||
@@ -80,7 +80,7 @@ describe('Logo helpers', function() {
|
||||
expect(decodedLogo).to.contain('fill="whitesmoke"')
|
||||
})
|
||||
|
||||
it('preserves color if medium logo on dark background', function() {
|
||||
it('preserves color if medium logo on dark background', function () {
|
||||
const logo = prepareNamedLogo({ name: 'skype' })
|
||||
const decodedLogo = Buffer.from(
|
||||
logo.replace('data:image/svg+xml;base64,', ''),
|
||||
@@ -88,7 +88,7 @@ describe('Logo helpers', function() {
|
||||
).toString('ascii')
|
||||
expect(decodedLogo).to.contain('fill="#00AFF0"')
|
||||
})
|
||||
it('preserves color if medium logo on light background', function() {
|
||||
it('preserves color if medium logo on light background', function () {
|
||||
const logo = prepareNamedLogo({ name: 'skype', style: 'social' })
|
||||
const decodedLogo = Buffer.from(
|
||||
logo.replace('data:image/svg+xml;base64,', ''),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const { test, given } = require('sazerac')
|
||||
const { svg2base64 } = require('./svg-helpers')
|
||||
|
||||
describe('SVG helpers', function() {
|
||||
describe('SVG helpers', function () {
|
||||
test(svg2base64, () => {
|
||||
given('<svg xmlns="http://www.w3.org/2000/svg"/>').expect(
|
||||
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -25218,9 +25218,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"prettier": {
|
||||
"version": "1.19.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
|
||||
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
|
||||
"integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==",
|
||||
"dev": true
|
||||
},
|
||||
"pretty-bytes": {
|
||||
|
||||
@@ -226,7 +226,7 @@
|
||||
"nyc": "^15.0.1",
|
||||
"opn-cli": "^5.0.0",
|
||||
"portfinder": "^1.0.26",
|
||||
"prettier": "1.19.1",
|
||||
"prettier": "2.0.5",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-error-overlay": "^3.0.0",
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isVPlusDottedVersionAtLeastOne } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('Version')
|
||||
.get('/IndieGala-Helper.json')
|
||||
.expectBadge({
|
||||
label: 'mozilla add-on',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
t.create('Version').get('/IndieGala-Helper.json').expectBadge({
|
||||
label: 'mozilla add-on',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
|
||||
t.create('Version (not found)')
|
||||
.get('/not-a-real-plugin.json')
|
||||
|
||||
@@ -5,9 +5,7 @@ const { floorCount } = require('../color-formatters')
|
||||
const { BaseJsonService, InvalidResponse } = require('..')
|
||||
|
||||
const ansibleContentSchema = Joi.object({
|
||||
quality_score: Joi.number()
|
||||
.allow(null)
|
||||
.required(),
|
||||
quality_score: Joi.number().allow(null).required(),
|
||||
}).required()
|
||||
|
||||
class AnsibleGalaxyContent extends BaseJsonService {
|
||||
|
||||
@@ -54,8 +54,6 @@ t.create('Invalid License')
|
||||
t.create('Unexpected response')
|
||||
.get('/dm/vim-mode.json')
|
||||
.intercept(nock =>
|
||||
nock('https://atom.io')
|
||||
.get('/api/packages/vim-mode')
|
||||
.reply(invalidJSON)
|
||||
nock('https://atom.io').get('/api/packages/vim-mode').reply(invalidJSON)
|
||||
)
|
||||
.expectBadge({ label: 'downloads', message: 'unparseable json response' })
|
||||
|
||||
@@ -10,9 +10,7 @@ const schema = Joi.object({
|
||||
status: isBuildStatus,
|
||||
jobs: Joi.array()
|
||||
.items({
|
||||
name: Joi.string()
|
||||
.allow('')
|
||||
.required(),
|
||||
name: Joi.string().allow('').required(),
|
||||
status: isBuildStatus,
|
||||
testsCount: nonNegativeInteger,
|
||||
passedTestsCount: nonNegativeInteger,
|
||||
|
||||
@@ -5,7 +5,7 @@ const { test, given } = require('sazerac')
|
||||
const { NotFound } = require('..')
|
||||
const AppveyorJobBuild = require('./appveyor-job-build.service')
|
||||
|
||||
describe('AppveyorJobBuild', function() {
|
||||
describe('AppveyorJobBuild', function () {
|
||||
test(AppveyorJobBuild.prototype.transform, () => {
|
||||
given({ data: {} }).expect({
|
||||
status: 'no builds found',
|
||||
@@ -31,13 +31,13 @@ describe('AppveyorJobBuild', function() {
|
||||
})
|
||||
})
|
||||
|
||||
it('throws NotFound when response is missing jobs', function() {
|
||||
it('throws NotFound when response is missing jobs', function () {
|
||||
expect(() => AppveyorJobBuild.prototype.transform({ data: { build: {} } }))
|
||||
.to.throw(NotFound)
|
||||
.with.property('prettyMessage', 'no jobs found')
|
||||
})
|
||||
|
||||
it('throws NotFound when specified job missing jobs', function() {
|
||||
it('throws NotFound when specified job missing jobs', function () {
|
||||
expect(() =>
|
||||
AppveyorJobBuild.prototype.transform({
|
||||
jobName: 'mac',
|
||||
|
||||
@@ -12,19 +12,13 @@ const { InvalidResponse } = require('..')
|
||||
const aurSchema = Joi.object({
|
||||
resultcount: nonNegativeInteger,
|
||||
results: Joi.alternatives(
|
||||
Joi.array()
|
||||
.length(0)
|
||||
.required(),
|
||||
Joi.array().length(0).required(),
|
||||
Joi.object({
|
||||
License: Joi.string()
|
||||
.required()
|
||||
.allow(null),
|
||||
License: Joi.string().required().allow(null),
|
||||
NumVotes: nonNegativeInteger,
|
||||
Version: Joi.string().required(),
|
||||
OutOfDate: nonNegativeInteger.allow(null),
|
||||
Maintainer: Joi.string()
|
||||
.required()
|
||||
.allow(null),
|
||||
Maintainer: Joi.string().required().allow(null),
|
||||
LastModified: nonNegativeInteger,
|
||||
}).required()
|
||||
),
|
||||
|
||||
@@ -36,12 +36,10 @@ t.create('version (not found)')
|
||||
|
||||
// votes tests
|
||||
|
||||
t.create('votes (valid)')
|
||||
.get('/votes/google-chrome.json')
|
||||
.expectBadge({
|
||||
label: 'votes',
|
||||
message: isMetric,
|
||||
})
|
||||
t.create('votes (valid)').get('/votes/google-chrome.json').expectBadge({
|
||||
label: 'votes',
|
||||
message: isMetric,
|
||||
})
|
||||
|
||||
t.create('votes (not found)')
|
||||
.get('/votes/not-a-package.json')
|
||||
|
||||
@@ -6,19 +6,15 @@ const t = (module.exports = require('../tester').createServiceTester())
|
||||
// https://dev.azure.com/totodem/Shields.io is a public Azure DevOps project
|
||||
// solely created for Shields.io testing.
|
||||
|
||||
t.create('default branch')
|
||||
.get('/totodem/shields.io/2.json')
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
t.create('default branch').get('/totodem/shields.io/2.json').expectBadge({
|
||||
label: 'build',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
|
||||
t.create('named branch')
|
||||
.get('/totodem/shields.io/2/master.json')
|
||||
.expectBadge({
|
||||
label: 'build',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
t.create('named branch').get('/totodem/shields.io/2/master.json').expectBadge({
|
||||
label: 'build',
|
||||
message: isBuildStatus,
|
||||
})
|
||||
|
||||
t.create('stage badge')
|
||||
.get('/totodem/Shields.io/5.json?stage=Successful%20Stage')
|
||||
|
||||
@@ -74,9 +74,7 @@ t.create('unknown build definition')
|
||||
t.create('404 latest build error response')
|
||||
.get(mockBadgeUriPath)
|
||||
.intercept(nock =>
|
||||
nock(azureDevOpsApiBaseUri)
|
||||
.get(mockLatestBuildApiUriPath)
|
||||
.reply(404)
|
||||
nock(azureDevOpsApiBaseUri).get(mockLatestBuildApiUriPath).reply(404)
|
||||
)
|
||||
.expectBadge({
|
||||
label: 'coverage',
|
||||
|
||||
@@ -38,9 +38,7 @@ t.create('unknown project')
|
||||
.get('/totodem/515/515/515.json')
|
||||
.expectBadge({ label: 'deployment', message: 'project not found' })
|
||||
|
||||
t.create('unknown user')
|
||||
.get('/this-repo/does-not-exist/1/2.json')
|
||||
.expectBadge({
|
||||
label: 'deployment',
|
||||
message: 'user or environment not found',
|
||||
})
|
||||
t.create('unknown user').get('/this-repo/does-not-exist/1/2.json').expectBadge({
|
||||
label: 'deployment',
|
||||
message: 'user or environment not found',
|
||||
})
|
||||
|
||||
@@ -121,9 +121,7 @@ t.create('unknown build definition')
|
||||
t.create('404 latest build error response')
|
||||
.get(mockBadgeUri)
|
||||
.intercept(nock =>
|
||||
nock(azureDevOpsApiBaseUri)
|
||||
.get(mockLatestBuildApiUriPath)
|
||||
.reply(404)
|
||||
nock(azureDevOpsApiBaseUri).get(mockLatestBuildApiUriPath).reply(404)
|
||||
)
|
||||
.expectBadge({
|
||||
label: 'tests',
|
||||
@@ -133,12 +131,10 @@ t.create('404 latest build error response')
|
||||
t.create('no build response')
|
||||
.get(`${uriPrefix}/${nonExistentDefinitionId}.json`)
|
||||
.intercept(nock =>
|
||||
nock(azureDevOpsApiBaseUri)
|
||||
.get(mockNonExistentBuildApiUriPath)
|
||||
.reply(200, {
|
||||
count: 0,
|
||||
value: [],
|
||||
})
|
||||
nock(azureDevOpsApiBaseUri).get(mockNonExistentBuildApiUriPath).reply(200, {
|
||||
count: 0,
|
||||
value: [],
|
||||
})
|
||||
)
|
||||
.expectBadge({ label: 'tests', message: 'build pipeline not found' })
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ const Joi = require('@hapi/joi')
|
||||
const { BaseJsonService } = require('..')
|
||||
|
||||
const schema = Joi.object({
|
||||
total_amount: Joi.number()
|
||||
.min(0)
|
||||
.required(),
|
||||
total_amount: Joi.number().min(0).required(),
|
||||
}).required()
|
||||
|
||||
module.exports = class Beerpay extends BaseJsonService {
|
||||
|
||||
@@ -5,12 +5,10 @@ const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
const amountOfMoney = withRegex(/^\$[0-9]+(\.[0-9]+)?/)
|
||||
|
||||
t.create('funding')
|
||||
.get('/hashdog/scrapfy-chrome-extension.json')
|
||||
.expectBadge({
|
||||
label: 'beerpay',
|
||||
message: amountOfMoney,
|
||||
})
|
||||
t.create('funding').get('/hashdog/scrapfy-chrome-extension.json').expectBadge({
|
||||
label: 'beerpay',
|
||||
message: amountOfMoney,
|
||||
})
|
||||
|
||||
t.create('funding (unknown project)')
|
||||
.get('/hashdog/not-a-real-project.json')
|
||||
|
||||
@@ -5,8 +5,8 @@ const nock = require('nock')
|
||||
const { cleanUpNockAfterEach, defaultContext } = require('../test-helpers')
|
||||
const Bintray = require('./bintray.service')
|
||||
|
||||
describe('Bintray', function() {
|
||||
describe('auth', function() {
|
||||
describe('Bintray', function () {
|
||||
describe('auth', function () {
|
||||
cleanUpNockAfterEach()
|
||||
|
||||
const user = 'admin'
|
||||
@@ -18,7 +18,7 @@ describe('Bintray', function() {
|
||||
},
|
||||
}
|
||||
|
||||
it('sends the auth information as configured', async function() {
|
||||
it('sends the auth information as configured', async function () {
|
||||
const scope = nock('https://bintray.com')
|
||||
.get('/api/v1/packages/asciidoctor/maven/asciidoctorj/versions/_latest')
|
||||
// This ensures that the expected credentials are actually being sent with the HTTP request.
|
||||
|
||||
@@ -5,12 +5,10 @@ const {
|
||||
} = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('version')
|
||||
.get('/asciidoctor/maven/asciidoctorj.json')
|
||||
.expectBadge({
|
||||
label: 'bintray',
|
||||
message: isVPlusDottedVersionNClausesWithOptionalSuffix,
|
||||
})
|
||||
t.create('version').get('/asciidoctor/maven/asciidoctorj.json').expectBadge({
|
||||
label: 'bintray',
|
||||
message: isVPlusDottedVersionNClausesWithOptionalSuffix,
|
||||
})
|
||||
|
||||
t.create('version (not found)')
|
||||
.get('/asciidoctor/maven/not-a-real-package.json')
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
const { isMetric } = require('../test-validators')
|
||||
|
||||
t.create('collection (valid)')
|
||||
.get('/ramda/ramda.json')
|
||||
.expectBadge({
|
||||
label: 'components',
|
||||
message: isMetric,
|
||||
})
|
||||
t.create('collection (valid)').get('/ramda/ramda.json').expectBadge({
|
||||
label: 'components',
|
||||
message: isMetric,
|
||||
})
|
||||
|
||||
t.create('collection (valid)')
|
||||
.get('/bit/no-collection-test.json')
|
||||
|
||||
@@ -5,13 +5,13 @@ const nock = require('nock')
|
||||
const { cleanUpNockAfterEach, defaultContext } = require('../test-helpers')
|
||||
const [BitbucketPullRequest] = require('./bitbucket-pull-request.service')
|
||||
|
||||
describe('BitbucketPullRequest', function() {
|
||||
describe('BitbucketPullRequest', function () {
|
||||
cleanUpNockAfterEach()
|
||||
|
||||
const user = 'admin'
|
||||
const pass = 'password'
|
||||
|
||||
it('Sends auth headers to Bitbucket as configured', async function() {
|
||||
it('Sends auth headers to Bitbucket as configured', async function () {
|
||||
const scope = nock('https://bitbucket.org/api/2.0/repositories/')
|
||||
.get(/.*/)
|
||||
.basicAuth({ user, pass })
|
||||
@@ -40,7 +40,7 @@ describe('BitbucketPullRequest', function() {
|
||||
scope.done()
|
||||
})
|
||||
|
||||
it('Sends auth headers to Bitbucket Server as configured', async function() {
|
||||
it('Sends auth headers to Bitbucket Server as configured', async function () {
|
||||
const scope = nock('https://bitbucket.example.test/rest/api/1.0/projects')
|
||||
.get(/.*/)
|
||||
.basicAuth({ user, pass })
|
||||
|
||||
@@ -24,12 +24,10 @@ t.create('pr-raw (private repo)')
|
||||
.get('/pr-raw/chris48s/example-private-repo.json')
|
||||
.expectBadge({ label: 'pull requests', message: 'private repo' })
|
||||
|
||||
t.create('pr (valid)')
|
||||
.get('/pr/atlassian/python-bitbucket.json')
|
||||
.expectBadge({
|
||||
label: 'pull requests',
|
||||
message: isMetricOpenIssues,
|
||||
})
|
||||
t.create('pr (valid)').get('/pr/atlassian/python-bitbucket.json').expectBadge({
|
||||
label: 'pull requests',
|
||||
message: isMetricOpenIssues,
|
||||
})
|
||||
|
||||
t.create('pr (not found)')
|
||||
.get('/pr/atlassian/not-a-repo.json')
|
||||
|
||||
@@ -13,13 +13,10 @@ const isBowerPrereleaseVersion = Joi.string().regex(
|
||||
/^v\d+(\.\d+)?(\.\d+)?(-?[.\w\d])+?$/
|
||||
)
|
||||
|
||||
t.create('version')
|
||||
.timeout(10000)
|
||||
.get('/v/bootstrap.json')
|
||||
.expectBadge({
|
||||
label: 'bower',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
t.create('version').timeout(10000).get('/v/bootstrap.json').expectBadge({
|
||||
label: 'bower',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
|
||||
t.create('pre version') // e.g. bower|v0.2.5-alpha-rc-pre
|
||||
.timeout(10000)
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
const { isMetric } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('Players')
|
||||
.get('/1.json')
|
||||
.expectBadge({
|
||||
label: 'players',
|
||||
message: isMetric,
|
||||
})
|
||||
t.create('Players').get('/1.json').expectBadge({
|
||||
label: 'players',
|
||||
message: isMetric,
|
||||
})
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
const { isMetric } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('Servers')
|
||||
.get('/1.json')
|
||||
.expectBadge({
|
||||
label: 'servers',
|
||||
message: isMetric,
|
||||
})
|
||||
t.create('Servers').get('/1.json').expectBadge({
|
||||
label: 'servers',
|
||||
message: isMetric,
|
||||
})
|
||||
|
||||
@@ -13,9 +13,7 @@ const schema = Joi.object({
|
||||
.items(
|
||||
Joi.object({
|
||||
status: Joi.string().required(),
|
||||
resolution: Joi.string()
|
||||
.allow('')
|
||||
.required(),
|
||||
resolution: Joi.string().allow('').required(),
|
||||
}).required()
|
||||
)
|
||||
.min(1)
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
const { test, given } = require('sazerac')
|
||||
const Bugzilla = require('./bugzilla.service')
|
||||
|
||||
describe('getDisplayStatus function', function() {
|
||||
it('formats status correctly', async function() {
|
||||
describe('getDisplayStatus function', function () {
|
||||
it('formats status correctly', async function () {
|
||||
test(Bugzilla.getDisplayStatus, () => {
|
||||
given({ status: 'RESOLVED', resolution: 'WORKSFORME' }).expect(
|
||||
'works for me'
|
||||
|
||||
@@ -15,12 +15,10 @@ const bzBugStatus = Joi.equal(
|
||||
'incomplete'
|
||||
)
|
||||
|
||||
t.create('Bugzilla valid bug status')
|
||||
.get('/996038.json')
|
||||
.expectBadge({
|
||||
label: 'bug 996038',
|
||||
message: bzBugStatus,
|
||||
})
|
||||
t.create('Bugzilla valid bug status').get('/996038.json').expectBadge({
|
||||
label: 'bug 996038',
|
||||
message: bzBugStatus,
|
||||
})
|
||||
|
||||
t.create('Bugzilla valid bug status with custom baseUrl')
|
||||
.get('/545424.json?baseUrl=https://bugs.eclipse.org/bugs')
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isVPlusTripleDottedVersion } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('cdnjs (valid)')
|
||||
.get('/jquery.json')
|
||||
.expectBadge({
|
||||
label: 'cdnjs',
|
||||
message: isVPlusTripleDottedVersion,
|
||||
})
|
||||
t.create('cdnjs (valid)').get('/jquery.json').expectBadge({
|
||||
label: 'cdnjs',
|
||||
message: isVPlusTripleDottedVersion,
|
||||
})
|
||||
|
||||
t.create('cdnjs (not found)')
|
||||
.get('/not-a-library.json')
|
||||
|
||||
@@ -8,11 +8,11 @@ const {
|
||||
// When these tests fail, they will throw AssertionErrors. Wrapping them in an
|
||||
// `expect().not.to.throw()` makes the error output unreadable.
|
||||
|
||||
it('Services have unique names', function() {
|
||||
it('Services have unique names', function () {
|
||||
this.timeout(30000)
|
||||
checkNames()
|
||||
})
|
||||
|
||||
it('Can collect the service definitions', function() {
|
||||
it('Can collect the service definitions', function () {
|
||||
collectDefinitions()
|
||||
})
|
||||
|
||||
@@ -14,12 +14,10 @@ const t = (module.exports = new ServiceTester({
|
||||
|
||||
// downloads
|
||||
|
||||
t.create('total downloads (valid)')
|
||||
.get('/dt/scriptcs.json')
|
||||
.expectBadge({
|
||||
label: 'downloads',
|
||||
message: isMetric,
|
||||
})
|
||||
t.create('total downloads (valid)').get('/dt/scriptcs.json').expectBadge({
|
||||
label: 'downloads',
|
||||
message: isMetric,
|
||||
})
|
||||
|
||||
t.create('total downloads (not found)')
|
||||
.get('/dt/not-a-real-package.json')
|
||||
@@ -27,12 +25,10 @@ t.create('total downloads (not found)')
|
||||
|
||||
// version
|
||||
|
||||
t.create('version (valid)')
|
||||
.get('/v/scriptcs.json')
|
||||
.expectBadge({
|
||||
label: 'chocolatey',
|
||||
message: isVPlusDottedVersionNClauses,
|
||||
})
|
||||
t.create('version (valid)').get('/v/scriptcs.json').expectBadge({
|
||||
label: 'chocolatey',
|
||||
message: isVPlusDottedVersionNClauses,
|
||||
})
|
||||
|
||||
t.create('version (not found)')
|
||||
.get('/v/not-a-real-package.json')
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isVPlusDottedVersionAtLeastOne } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('Version')
|
||||
.get('/alhjnofcnnpeaphgeakdhkebafjcpeae.json')
|
||||
.expectBadge({
|
||||
label: 'chrome web store',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
t.create('Version').get('/alhjnofcnnpeaphgeakdhkebafjcpeae.json').expectBadge({
|
||||
label: 'chrome web store',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
|
||||
t.create('Version (not found)')
|
||||
.get('/invalid-name-of-addon.json')
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isMetric } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('clojars downloads (valid)')
|
||||
.get('/prismic.json')
|
||||
.expectBadge({
|
||||
label: 'downloads',
|
||||
message: isMetric,
|
||||
})
|
||||
t.create('clojars downloads (valid)').get('/prismic.json').expectBadge({
|
||||
label: 'downloads',
|
||||
message: isMetric,
|
||||
})
|
||||
|
||||
t.create('clojars downloads (not found)')
|
||||
.get('/not-a-package.json')
|
||||
|
||||
@@ -8,9 +8,7 @@ const { BaseJsonService } = require('..')
|
||||
|
||||
const schema = Joi.object({
|
||||
cocoadocs: Joi.object({
|
||||
doc_percent: Joi.number()
|
||||
.allow(null)
|
||||
.required(),
|
||||
doc_percent: Joi.number().allow(null).required(),
|
||||
}).required(),
|
||||
}).required()
|
||||
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isIntegerPercentage } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('doc percent (valid)')
|
||||
.get('/AFNetworking.json')
|
||||
.expectBadge({
|
||||
label: 'docs',
|
||||
message: isIntegerPercentage,
|
||||
})
|
||||
t.create('doc percent (valid)').get('/AFNetworking.json').expectBadge({
|
||||
label: 'docs',
|
||||
message: isIntegerPercentage,
|
||||
})
|
||||
|
||||
t.create('doc percent (null)')
|
||||
.get('/AFNetworking.json')
|
||||
|
||||
@@ -7,12 +7,10 @@ const isPlatform = Joi.string().regex(
|
||||
/^(osx|ios|tvos|watchos)( \| (osx|ios|tvos|watchos))*$/
|
||||
)
|
||||
|
||||
t.create('platform (valid)')
|
||||
.get('/AFNetworking.json')
|
||||
.expectBadge({
|
||||
label: 'platform',
|
||||
message: isPlatform,
|
||||
})
|
||||
t.create('platform (valid)').get('/AFNetworking.json').expectBadge({
|
||||
label: 'platform',
|
||||
message: isPlatform,
|
||||
})
|
||||
|
||||
t.create('platform (not found)')
|
||||
.get('/not-a-package.json')
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isVPlusDottedVersionAtLeastOne } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('version (valid)')
|
||||
.get('/AFNetworking.json')
|
||||
.expectBadge({
|
||||
label: 'pod',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
t.create('version (valid)').get('/AFNetworking.json').expectBadge({
|
||||
label: 'pod',
|
||||
message: isVPlusDottedVersionAtLeastOne,
|
||||
})
|
||||
|
||||
t.create('version (not found)')
|
||||
.get('/not-a-package.json')
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const { isIntegerPercentage } = require('../test-validators')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
t.create('Coverage')
|
||||
.get('/59d607d0e311408885e418004068ea58.json')
|
||||
.expectBadge({
|
||||
label: 'coverage',
|
||||
message: isIntegerPercentage,
|
||||
})
|
||||
t.create('Coverage').get('/59d607d0e311408885e418004068ea58.json').expectBadge({
|
||||
label: 'coverage',
|
||||
message: isIntegerPercentage,
|
||||
})
|
||||
|
||||
t.create('Coverage on branch')
|
||||
.get('/59d607d0e311408885e418004068ea58/master.json')
|
||||
|
||||
@@ -7,14 +7,10 @@ const t = (module.exports = require('../tester').createServiceTester())
|
||||
// Examples for this service can be found through the explore page:
|
||||
// https://codeclimate.com/explore
|
||||
|
||||
t.create('issues count')
|
||||
.get('/issues/angular/angular.json')
|
||||
.expectBadge({
|
||||
label: 'issues',
|
||||
message: Joi.number()
|
||||
.integer()
|
||||
.positive(),
|
||||
})
|
||||
t.create('issues count').get('/issues/angular/angular.json').expectBadge({
|
||||
label: 'issues',
|
||||
message: Joi.number().integer().positive(),
|
||||
})
|
||||
|
||||
t.create('technical debt percentage')
|
||||
.get('/tech-debt/angular/angular.json')
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const { test, forCases, given } = require('sazerac')
|
||||
const Codecov = require('./codecov.service')
|
||||
|
||||
describe('Codecov', function() {
|
||||
describe('Codecov', function () {
|
||||
test(Codecov.prototype.legacyTransform, () => {
|
||||
forCases([given({ json: {} }), given({ json: { commit: {} } })]).expect({
|
||||
coverage: 'unknown',
|
||||
|
||||
@@ -51,8 +51,9 @@ module.exports = class CodeFactorGrade extends BaseSvgScrapingService {
|
||||
async handle({ vcsType, user, repo, branch }) {
|
||||
const { message } = await this._requestSvg({
|
||||
schema,
|
||||
url: `https://codefactor.io/repository/${vcsType}/${user}/${repo}/badge/${branch ||
|
||||
''}`,
|
||||
url: `https://codefactor.io/repository/${vcsType}/${user}/${repo}/badge/${
|
||||
branch || ''
|
||||
}`,
|
||||
errorMessages: { 404: 'repo or branch not found' },
|
||||
})
|
||||
return this.constructor.render({ grade: message })
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
const { test, given } = require('sazerac')
|
||||
const CodeFactorGrade = require('./codefactor-grade.service')
|
||||
|
||||
describe('CodeFactorGrade', function() {
|
||||
describe('CodeFactorGrade', function () {
|
||||
test(CodeFactorGrade.render, () => {
|
||||
given({ grade: 'A' }).expect({
|
||||
message: 'A',
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
const { isValidGrade } = require('./codefactor-helpers')
|
||||
|
||||
t.create('Grade')
|
||||
.get('/github/google/guava.json')
|
||||
.expectBadge({
|
||||
label: 'code quality',
|
||||
message: isValidGrade,
|
||||
})
|
||||
t.create('Grade').get('/github/google/guava.json').expectBadge({
|
||||
label: 'code quality',
|
||||
message: isValidGrade,
|
||||
})
|
||||
|
||||
t.create('Grade (branch)')
|
||||
.get('/github/pallets/flask/master.json')
|
||||
|
||||
@@ -6,7 +6,7 @@ const Codeship = require('./codeship.service')
|
||||
const pending = { message: 'pending', label: undefined, color: undefined }
|
||||
const notBuilt = { message: 'not built', label: undefined, color: undefined }
|
||||
|
||||
describe('Codeship', function() {
|
||||
describe('Codeship', function () {
|
||||
test(Codeship.render, () => {
|
||||
given({ status: 'testing' }).expect(pending)
|
||||
given({ status: 'waiting' }).expect(pending)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user