|
| 1 | +# @passmarked/js |
| 2 | + |
| 3 | +[Passmarked](http://passmarked.com) is a suite of tests that can be run against any page/website to identify issues with parity to most online tools in one package. |
| 4 | + |
| 5 | +The [Terminal Client](http://npmjs.org/package/passmarked) is intended for use by developers to integrate into their workflow/CI servers but also integrate into their own application that might need to test websites and provide realtime feedback. |
| 6 | + |
| 7 | +All of the checks on [Passmarked](http://passmarked.com) can be voted on importance and are [open-sourced](http://github.com/passmarked/suite), to encourage community involvement in fixing and adding new rules. We are building the living Web Standard and love any [contributions](#contributing). |
| 8 | + |
| 9 | +## Installing |
| 10 | + |
| 11 | +To install just add the library as part of your HTML: |
| 12 | + |
| 13 | +``` |
| 14 | +<script src="//cdn.passmarked.com/jsapi/v1.js"></script> |
| 15 | +``` |
| 16 | + |
| 17 | +The page will now have a global `passmarked` object that can be used |
| 18 | + |
| 19 | +## Widget |
| 20 | + |
| 21 | +The JS API provides a simple to use widget that can be added to any page using a few lines of Javascript code. This widget will allow users to test numerous parts of their site depending on the `mode`, which can be: |
| 22 | + |
| 23 | +* `categories` (default) - Displays the list of categories [Performance](https://passmarked.com/library/performance) / [Compatibility](https://passmarked.com/library/compatibility) / [Content](https://passmarked.com/library/content) / [Security](https://passmarked.com/library/security). |
| 24 | +* `rules` - Displays a list of selected rules in a list with a check next to each if found on the target page |
| 25 | +* `screenshots` - Displays a list of screenshots of numerous screensize's, to show how a site appears on each of these devices. |
| 26 | +* |
| 27 | + |
| 28 | +To use the widget, first make sure the library is loaded in the head or just before the body of the page: |
| 29 | + |
| 30 | +``` |
| 31 | +<script src="//cdn.passmarked.com/jsapi/v1.js"></script> |
| 32 | +``` |
| 33 | + |
| 34 | +Then create a div that the widget can use (everything inside this div will be removed when the widget's HTML is inserted: |
| 35 | + |
| 36 | +``` |
| 37 | +<div id="passmarked-widget"></div> |
| 38 | +``` |
| 39 | + |
| 40 | +then simply start the actual widget pointing to the defined wrapper block: |
| 41 | + |
| 42 | +``` |
| 43 | +var widget = passmarked.createWidget({ |
| 44 | +
|
| 45 | + el: document.querySelector('#passmarked-widget'), |
| 46 | + token: '<token-for-passmarked-api>' |
| 47 | +
|
| 48 | +}); |
| 49 | +``` |
| 50 | + |
| 51 | +After reloading the page, the widget will now appear be usable. |
| 52 | + |
| 53 | +## Running a report with the API |
| 54 | + |
| 55 | +``` |
| 56 | +/** |
| 57 | +* Create a report |
| 58 | +**/ |
| 59 | +var report = passmarked.create({ |
| 60 | +
|
| 61 | + url: 'http://example.com', |
| 62 | + token: '<token-here>' |
| 63 | +
|
| 64 | +}); |
| 65 | +
|
| 66 | +/** |
| 67 | +* Start the report |
| 68 | +**/ |
| 69 | +report.start(function(err, code) { |
| 70 | +
|
| 71 | + if(err) { |
| 72 | + |
| 73 | + /** Something with the network went terribly wrong **/ |
| 74 | + |
| 75 | + } else if(code) { |
| 76 | + |
| 77 | + /** Validation code returned **/ |
| 78 | + |
| 79 | + } |
| 80 | +
|
| 81 | +}); |
| 82 | +
|
| 83 | +/** |
| 84 | +* Listen when the report is done |
| 85 | +**/ |
| 86 | +report.on('done', function() { |
| 87 | +
|
| 88 | + // get the data |
| 89 | + var page = report.getResult(); |
| 90 | + |
| 91 | + // output done ! |
| 92 | + console.log('Page scored ' + page.getScore() + '!'); |
| 93 | + |
| 94 | + // get the screenshot |
| 95 | + console.log('preview of desktop: ' + page.getPreview('desktop')); |
| 96 | + |
| 97 | + // check if a certain rule is broken |
| 98 | + if(page.hasRule('heartbleed')) { |
| 99 | + |
| 100 | + // output that the server is in trouble ... |
| 101 | + console.log('Server is vunerable to HeartBleed !'); |
| 102 | + |
| 103 | + } |
| 104 | +
|
| 105 | +}); |
| 106 | +``` |
| 107 | + |
| 108 | +## Rules |
| 109 | + |
| 110 | +Rules represent checks that occur in this module, all of these rules have a **UID** which can be used to check for specific rules. For the structure and more details see the [Wiki](https://github.com/passmarked/passmarked/wiki) page on [Rules](https://github.com/passmarked/passmarked/wiki/Create). |
| 111 | + |
| 112 | +> Rules also include a `type` which could be `critical`, `error`, `warning` or `notice` giving a better view on the importance of the rule. |
| 113 | +
|
| 114 | +See [passmarked.com/library](https://passmarked.com/library) for all the rules. |
| 115 | + |
| 116 | +## Contributing |
| 117 | + |
| 118 | +```bash |
| 119 | +git clone git@github.com:passmarked/seo.git |
| 120 | +npm install |
| 121 | +npm test |
| 122 | +``` |
| 123 | + |
| 124 | +Pull requests have a prerequisite of passing tests. If your contribution is accepted, it will be merged into `develop` (and then `master` after staging tests by the team) which will then be deployed live to [passmarked.com](http://passmarked.com) and on NPM for everyone to download and test. |
| 125 | + |
| 126 | +## About |
| 127 | + |
| 128 | +To learn more visit: |
| 129 | + |
| 130 | +* [Passmarked](http://passmarked.com) |
| 131 | +* [Terminal Client](https://www.npmjs.com/package/passmarked) |
| 132 | +* [Slack](http://passmarked.com/chat) - We have a Slack team with all our team and open to anyone using the site to chat and figure out problems. To join head over to [passmarked.com/chat](http://passmarked.com/chat) and request a invite. |
| 133 | + |
| 134 | +## License |
| 135 | + |
| 136 | +Copyright 2016 Passmarked Inc |
| 137 | + |
| 138 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 139 | +you may not use this file except in compliance with the License. |
| 140 | +You may obtain a copy of the License at |
| 141 | + |
| 142 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 143 | + |
| 144 | +Unless required by applicable law or agreed to in writing, software |
| 145 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 146 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 147 | +See the License for the specific language governing permissions and |
| 148 | +limitations under the License. |
0 commit comments