-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[hhvm] #1499 - update hhvm service #1508
Conversation
Thanks for submitting a PR for this. I'll submit comments for review shortly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few minor inline comments.
Additionally, could you possibly add a small test suite for your code. This will help to verify that the code works correctly and will hopefully allow an error like the one you've reported in #1499 to be flagged up earlier in future.
A minimal test suite for this badge should cover the following cases:
- expected behaviour
- package not found
- connection error
- unexpected response
There is documentation on writing tests in https://github.com/badges/shields/blob/master/service-tests/README.md but something like https://github.com/badges/shields/blob/master/service-tests/requires.js or https://github.com/badges/shields/blob/master/service-tests/shippable.js would be a good example to crib from for this badge.
If you create your tests in a file called hhvm.js
, edit your PR title to something like "[hhvm] my pull request title" and Circle CI will run the tests for that service when you push additional commits.
Thanks again.
server.js
Outdated
var verInfo = {}; | ||
for (var i = 0, count = data.versions.length; i < count; i++) { | ||
verInfo = data.versions[i]; | ||
if (verInfo.name == branch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use a strict comparison here please (triple equals)
server.js
Outdated
verInfo = data.versions[i]; | ||
if (verInfo.name == branch) { | ||
switch (verInfo.travis.hhvm) { | ||
case 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This switch statement would be easier to read if the cases were indented by a block (sorry to leave feedback on indenting :( this should really be picked up by a linting rule!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do (I copy/pasted a switch statement from elsewhere in the code)
server.js
Outdated
// Remove the leading slash. | ||
apiUrl += '?branch=' + branch.slice(1); | ||
} | ||
var apiUrl = 'https://php-eye.com/api/v1/package/'+user+'.json'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update the variable declarations to use the ES6 style let
and const
as applicable while you're working on this code.
I'll create some tests asap when I actually have time to get the environment up and running... so far the edits were simply done on github.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Thanks for adding tests. This is shaping up nicely. I've left a few more comments about the tests but I think we're fairly close to a final check and getting this merged :)
service-tests/hhvm.js
Outdated
|
||
t.create('invalid package name') | ||
.get('/frodo/is-not-a-package.json') | ||
.expectJSON({ name: 'hhvm', value: 'invalid' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'invalid' label should be used when there is a problem generating the response (e.g: the json response could not be parsed). There is a handy fixture you can import using const { invalidJSON } = require('./helpers/response-fixtures');
which allows you to mock an invalid response like this
shields/service-tests/cdnjs.js
Lines 28 to 34 in 75503ec
t.create('cdnjs (unexpected response)') | |
.get('/v/jquery.json') | |
.intercept(nock => nock('https://api.cdnjs.com') | |
.get('/libraries/jquery?fields=version') | |
.reply(invalidJSON) | |
) | |
.expectJSON({name: 'cdnjs', value: 'invalid'}); |
In the case where the package or branch is not found, we should return a 'not found' rather than 'invalid'. It looks like where the repo is not found, php-eye returns a 404: https://php-eye.com/api/v1/package/frodo/not-a-package.json This is the most common case so we have a handler for it checkErrorResponse
which can be used like this
Lines 6157 to 6160 in 75503ec
if (checkErrorResponse(badgeData, err, res, 'repo not found')) { | |
sendBadge(format, badgeData); | |
return; | |
} |
checkErrorResponse
will also handle the 'inaccessible' case, so you can remove the if (err != null) ...
block and replace with a block like the one above.
service-tests/hhvm.js
Outdated
|
||
t.create('get symfony status (default branch - not tested)') | ||
.get('/symfony/symfony.json') | ||
.expectJSONTypes(Joi.object().keys({ name: 'hhvm', value: 'not tested' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit of project convention: We use .expectJSON()
if we're comparing the response to an object literal and .expectJSONTypes()
if we're checking the type of the response keys or validating against a regex.
service-tests/hhvm.js
Outdated
|
||
t.create('gets yii 1.1.19 status') | ||
.get('/yiisoft/yii/1.1.19.json') | ||
.expectJSON({ name: 'hhvm', value: 'partially tested' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit concerned that these tests may be a bit brittle or tied to particular projects. I also initially found the way the service tests are done on this project a bit confusing (there's some good discussion on it in this issue. It can be a bit tricky when your tests depend on external services but the sweet spot we're aiming for is that we want the tests to fail if php-eye change their JSON format or move their endpoint, but the tests shouldn't tell us the service integration is broken if Yii framework decide to change their approach to testing on HHVM, for example.
I'd suggest that the valid test cases (with/without branch) should just check against a regex like /^(tested|partially tested|not tested|maybe untested)$/
. If you also want to test the logic that leads to particular responses, you could use a test with a mocked response like this one:
shields/service-tests/homebrew.js
Lines 19 to 25 in 17b4a70
t.create('homebrew (valid, mocked response)') | |
.get('/v/cake.json') | |
.intercept(nock => nock('http://formulae.brew.sh') | |
.get('/formula/cake/version') | |
.reply(200, {stable: '0.23.0', devel: null, head: null}) | |
) | |
.expectJSON({name: 'homebrew', value: 'v0.23.0'}); |
How does that sound?
better tests: including invalidJSON fixture
@chris48s thanks for the feedback, I believe I've incorporated all of your suggestions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks very much. I think this is good to merge but one of the maintainers will need to take it over the line.
Thanks for contributing, changes look good to me. Thanks for reviewing @chris48s 😄 |
http://hhvm.h4cc.de... -> https://php-eye.com/api/v1/package...