Test a local server
User guide
- Getting Started
Api
Concepts
Configurations
Configuring webhint
Connectors
Development flow integration
Extensions
Formatters
Hints
- Avoid CSS limits
- Avoid HTTP redirects
- axe accessibility check
- Babel configuration hint set
- Compatibility of CSS, HTML and JavaScript features
- Correct `Content-Type` header
- Correct manifest extension
- Correct viewport
- Detect CSS Reflows
- Disallowed HTTP headers
- External links disown opener
- Has web app manifest
- Highest document mode
- HTTP cache
- Leading '.' in `classList.add` or `classList.remove`
- Manifest has name
- Minify JavaScript
- Modern DOCTYPE
- No `createElement` with SVG
- No `P3P` headers
- No broken links
- No byte-order mark
- No Inline CSS Styles
- No protocol-relative URLs
- No small error pages
- No vulnerable libraries
- Nu HTML test
- Optimal compression
- Optimize images
- Performance budget
- Prefixed CSS first
- scoped-svg-styles
- Specify button type
- SSL server test
- TypeScript configuration hints set
- Unneeded HTTP headers
- Use `Strict-Transport-Security` header
- Use `X-Content-Type-Options` header
- Use Apple touch icon
- Use charset `utf-8`
- Use HTTPS
- Use subresource integrity
- Valid `Set-Cookie` header
- Valid `theme-color`
- Valid manifest
- webpack configuration hints set
Parsers
Server configurations
Troubleshoot
- Api
- Concepts
- Configurations
- Configuring webhint
- Connectors
- Development flow integration
- Extensions
- Formatters
- Hints
- Parsers
- Server configurations
- Troubleshoot
Test a local server
In this scenario you want to run webhint
against a local server that
is running the code you want to test. Usually the tasks to perform can be
reduced to:
- Start server
- Run webhint
A solution to automate this is via npm scripts
and the test
task.
The biggest concern is how to start both tasks and kill the other when
one ends in a multiplatform environment. For example, the following will
not work because npm start
will start the server, it will not stop
(it’ll be waiting for incoming requests), and thus never executing
hint http://localhost:8080
:
{
...
"scripts": {
...
"start": "start your web server somehow",
"test": "npm start && hint http://localhost:8080",
...
}
...
} |
While there are some solutions like using just &
or |
, these don’t
work in all platforms (nor is recommended to pipe the output). To solve
this issue, you will need to use a package that can start multiple npm
tasks simultaneously and coordinate them. npm-run-all
is
one of those.
As an example, the following npm script
will build the
project, start http-server
(assuming the output of the
build process is on the dist
folder), run webhint
on localhost
and once it ends, kill the server started by http-server
:
{
...
"scripts": {
...
"start": "http-server dist -s -g",
"hint": "hint http://localhost:8080",
"test": "npm build && npm-run-all -r -p http-server hint",
...
}
...
} |