-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query param validation to remaining new-style services [azuredevo…
…ps appveyor npm] Remove now-obsolete code. Close #2675
- Loading branch information
1 parent
b7d632c
commit a070da3
Showing
11 changed files
with
160 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
|
||
const testResultQueryParamSchema = Joi.object({ | ||
compact_message: Joi.equal(''), | ||
passed_label: Joi.string(), | ||
failed_label: Joi.string(), | ||
skipped_label: Joi.string(), | ||
}).required() | ||
|
||
function renderTestResultMessage({ | ||
passed, | ||
failed, | ||
skipped, | ||
total, | ||
passedLabel, | ||
failedLabel, | ||
skippedLabel, | ||
isCompact, | ||
}) { | ||
const labels = { passedLabel, failedLabel, skippedLabel } | ||
if (total === 0) { | ||
return 'no tests' | ||
} else if (isCompact) { | ||
;({ passedLabel = '✔', failedLabel = '✘', skippedLabel = '➟' } = labels) | ||
return [ | ||
`${passedLabel} ${passed}`, | ||
failed > 0 && `${failedLabel} ${failed}`, | ||
skipped > 0 && `${skippedLabel} ${skipped}`, | ||
] | ||
.filter(Boolean) | ||
.join(' | ') | ||
} else { | ||
;({ | ||
passedLabel = 'passed', | ||
failedLabel = 'failed', | ||
skippedLabel = 'skipped', | ||
} = labels) | ||
return [ | ||
`${passed} ${passedLabel}`, | ||
failed > 0 && `${failed} ${failedLabel}`, | ||
skipped > 0 && `${skipped} ${skippedLabel}`, | ||
] | ||
.filter(Boolean) | ||
.join(', ') | ||
} | ||
} | ||
|
||
function renderTestResultBadge({ | ||
passed, | ||
failed, | ||
skipped, | ||
total, | ||
passedLabel, | ||
failedLabel, | ||
skippedLabel, | ||
isCompact, | ||
}) { | ||
const message = renderTestResultMessage({ | ||
passed, | ||
failed, | ||
skipped, | ||
total, | ||
passedLabel, | ||
failedLabel, | ||
skippedLabel, | ||
isCompact, | ||
}) | ||
|
||
let color | ||
if (total === 0) { | ||
color = 'yellow' | ||
} else if (failed > 0) { | ||
color = 'red' | ||
} else if (skipped > 0 && passed > 0) { | ||
color = 'green' | ||
} else if (skipped > 0) { | ||
color = 'yellow' | ||
} else { | ||
color = 'brightgreen' | ||
} | ||
|
||
return { message, color } | ||
} | ||
|
||
module.exports = { | ||
testResultQueryParamSchema, | ||
renderTestResultMessage, | ||
renderTestResultBadge, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict' | ||
|
||
const { test, given } = require('sazerac') | ||
const { | ||
renderTestResultMessage, | ||
renderTestResultBadge, | ||
} = require('./test-results') | ||
|
||
describe('Test result helpers', function() { | ||
function renderBothStyles(props) { | ||
const { message: standardMessage, color } = renderTestResultBadge(props) | ||
const compactMessage = renderTestResultMessage({ | ||
...props, | ||
isCompact: true, | ||
}) | ||
return { standardMessage, compactMessage, color } | ||
} | ||
|
||
test(renderBothStyles, () => { | ||
given({ passed: 12, failed: 3, skipped: 3, total: 18 }).expect({ | ||
standardMessage: '12 passed, 3 failed, 3 skipped', | ||
compactMessage: '✔ 12 | ✘ 3 | ➟ 3', | ||
color: 'red', | ||
}) | ||
given({ passed: 12, failed: 3, skipped: 0, total: 15 }).expect({ | ||
standardMessage: '12 passed, 3 failed', | ||
compactMessage: '✔ 12 | ✘ 3', | ||
color: 'red', | ||
}) | ||
given({ passed: 12, failed: 0, skipped: 3, total: 15 }).expect({ | ||
standardMessage: '12 passed, 3 skipped', | ||
compactMessage: '✔ 12 | ➟ 3', | ||
color: 'green', | ||
}) | ||
given({ passed: 0, failed: 0, skipped: 3, total: 3 }).expect({ | ||
standardMessage: '0 passed, 3 skipped', | ||
compactMessage: '✔ 0 | ➟ 3', | ||
color: 'yellow', | ||
}) | ||
given({ passed: 12, failed: 0, skipped: 0, total: 12 }).expect({ | ||
standardMessage: '12 passed', | ||
compactMessage: '✔ 12', | ||
color: 'brightgreen', | ||
}) | ||
given({ passed: 0, failed: 0, skipped: 0, total: 0 }).expect({ | ||
standardMessage: 'no tests', | ||
compactMessage: 'no tests', | ||
color: 'yellow', | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.