Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manifest-exists rule and make other improvements #54

Merged
merged 5 commits into from Mar 21, 2017
Merged

Add manifest-exists rule and make other improvements #54

merged 5 commits into from Mar 21, 2017

Conversation

alrra
Copy link
Contributor

@alrra alrra commented Mar 21, 2017

alrra and others added 3 commits March 21, 2017 16:49
Add rule to check if a single web app manifest file is specified,
* and if that specified file is accessible.
The `::index` part wasn't being removed when calling the
event and caused an exception.
@alrra alrra requested a review from molant March 21, 2017 14:52
@@ -98,7 +100,8 @@ const builder: CollectorBuilder = (server: Sonar, config): Collector => {

return {
body,
headers: response.headers
headers: response.headers,
statusCode: response.statusCode
Copy link
Contributor Author

@alrra alrra Mar 21, 2017

Choose a reason for hiding this comment

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

@molant At some point rules will also need to know the request headers, so maybe we should rename headers to responseHeaders, or better yet just split this into 2 objects ({ request: {}, response: {} }). What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Can you give me an example of why a rule should know the request headers? If they need an specific header they can pass it via customHeaders.
If we need something else other than the headers from the response then I'd go for the 2 objects. If it is only the headers then responseHeaders and requestHeaders are ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give me an example of why a rule should know the request headers?

While users can make extra requests where they can set if needed custom request headers so that they control exactly how the requests are made, I think that providing the request headers will simplify some things, and in certain cases could potentially avoid some extra requests (e.g.: users can check what headers where sent by default and based on that conditionally do extra things, they can quickly use request headers while debugging).

That being said, I don't expect them to be used much, probably mostly with rules related to: content negotiation.

If we need something else other than the headers from the response

Another question is: in the future, are we considering providing any other information about the requests (e.g.: information about timing, security)?


My opinion right now is that, even if we don't expose the request headers for now, I think the response related data should be under response: {...} so that we can add other things in the future without any problems.

Copy link
Member

Choose a reason for hiding this comment

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

OK, let's go with request: {}, response: {} then :)


t.context.rule[event.name](eventData);
event.responses.forEach((respons, i) => { // eslint-disable-line no-loop-func
ruleContext.fetchContent.onCall(i).returns(Promise.resolve(respons));
Copy link
Contributor Author

@alrra alrra Mar 21, 2017

Choose a reason for hiding this comment

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

Note: When we change this to use fixtures, another thing to consider is that it should also allow to test the value that is passed to fetchContent.

@@ -98,7 +100,8 @@ const builder: CollectorBuilder = (server: Sonar, config): Collector => {

return {
body,
headers: response.headers
headers: response.headers,
statusCode: response.statusCode
Copy link
Member

Choose a reason for hiding this comment

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

Can you give me an example of why a rule should know the request headers? If they need an specific header they can pass it via customHeaders.
If we need something else other than the headers from the response then I'd go for the 2 objects. If it is only the headers then responseHeaders and requestHeaders are ok.


In the context of [progressive web
apps](https://en.wikipedia.org/wiki/Progressive_web_app),
providing a web app manifest files is essential.
Copy link
Member

Choose a reason for hiding this comment

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

I think we need more details here of what things are going to be checked. Cases where the rule will fail and when it will pass. You are checking if the file exists, that should be mentioned here:

  • Missing manifest
  • Duplicate manifest
  • File doesn't exist
  • Something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we need more details here of what things are going to be checked.

Note: We should discuss at one point what exactly should the docs contain.

Copy link
Member

Choose a reason for hiding this comment

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

This is the information that will show up in the website so it needs to be as complete as possible. Things it should have:

  • Why this rule is important and when to care about it
  • How to configure it if applicable
  • How it behaves and what does it test exactly:
    • Examples that pass the rule
    • Examples that trigger the rule
  • Special requirements if applicable (there might be rules that require an specific feature not supported in all collectors)
  • Related links (spec, articles, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made an update before you made the above comment.

Will update / open anther PR with more information tomorrow.


import { test, ContextualTestContext } from 'ava'; // eslint-disable-line no-unused-vars
import { Rule, RuleBuilder, ElementFoundEvent } from '../../lib/types'; // eslint-disable-line no-unused-vars
import { Rule, RuleBuilder, ElementFoundEvent, FetchResponse} from '../../lib/types'; // eslint-disable-line no-unused-vars
Copy link
Member

Choose a reason for hiding this comment

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

If you have a better name for FetchResponse please let me know. I'm having a hard time finding good and meaningful names :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since in developer tools, that kinda of information is displayed in the network panel, maybeNetworkData?

Copy link
Member

Choose a reason for hiding this comment

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

Good to me, can you update the references?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


t.context.rule[event.name](eventData);
event.responses.forEach((respons, i) => { // eslint-disable-line no-loop-func
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename this to response or res if it is already used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, sorry about the typo.

* Change `rule-runner` to allow to specify the results for requests
  made by `fetchContent`.
* Add `statusCode` member to the `FetchResponse` interface.
* Update, improve, and fix the code for the `manifest-exists` rule.
@molant molant merged commit 162cc6b into webhintio:master Mar 21, 2017
@alrra alrra deleted the add-manifest-exists-rule-and-make-improvements branch March 21, 2017 20:05
alrra added a commit that referenced this pull request Mar 22, 2017
Move members of `NetworkData` interface into more specialized
interfaces (i.e. `Request` and `Response`), and add those more
specialised interfaces as members of `NetworkData`.

This change is done in order to remove the need to work around
potential naming conflicts (i.e. both the `request` and `response`
have `headers`), and thus, easily allow future additions (e.g.:
adding information about network timing, network security, etc.),
without requiring any changes.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Ref: #54 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants