pageup
v0.2.0
Published
Do Check If My Page Is UP
Downloads
9
Maintainers
Readme
pageup
Do Check If My Page Is UP
An easy way to test if your page is available in Node.js, without tying you to any testing framework out there.
toc:
installation:
⇒ npm install pageup
API:
var PageupTest = require("pageup");
new PageupTest(config)
Creates a new test harness.
config
(Object): passed as it toPageupTest#configure
Example:
var pageupTest = new PageupTest({
file: "test-description.json"
});
pageupTest.configure(config)
Configures the test harness.
config
(Object): test configurations. Properties include:files
(String[]): array of absolute filepathsfile
(String): an absolute filepathdescription
(Object): a single test descriptiondescriptions
(Object[]): array of test descriptionstimeout
(Integer): number of milliseconds before a request times out. Default isnull
i.e. a timeout is not applied to the requests.
If both config.files
and config.file
are provided, config.file
will be appended to config.files
(if not found in config.files
). Similarly for config.description
and config.descriptions
.
See test description
for how the file should be formatted.
You can also use globs. These will be used to find target files. Therefore you don't need to write down all file paths explicitly.
Example:
pageupTest.configure({
files: ["server.*.js"],
timeout: 5000,
descriptions: [
{
baseurl: "http://forfuture.co.ke/",
endpoints: {
"/": 200
}
}
]
});
pageupTest.run(tester, done)
Runs your tests.
tester
(Function): Test the status code- signature:
tester(err, actual, expected, url)
err
(Error): truthy, if an error occurring making request such as network failures and request timeouts. Note:404
s and other status codes usually regarded as errors are not passed aserr
. Status codes do not signify anything specific to pageup.actual
(Integer): response status code e.g.200
expected
(Integer): expected status code e.g.404
url
(String): url the current request was sent to. e.g."http://localhost:8080/endpoint"
- signature:
done
(Function): called when all requests are done- signature:
done(err)
err
(Error): truthy, if an error occurs in one of the processing stages prior to testing. An error may occur when reading the target files or converting the file contents to JSON.
- signature:
Example:
var assert = require("assert");
pageupTest.run(function(err, actual, expected, url) {
assert.ok(!!err, "error making request to " + url);
assert.equal(actual, expected, "status code mismatch: " + url);
}, function(err) {
assert.ok(!!err, "error occurred prior sending requests");
console.log("we are done");
});
test description:
Tests are described using valid .json
files. The following are the required properties:
baseurl
(String): base url to use to resolve endpoints
These properties are optional:
endpoints
(Object): mapping of endpoints to expected response status codesok
(Array): an array of endpoints, that we expect status code200
Sample description file:
{
"baseurl": "http://localhost:8080",
"endpoints": {
"/200": 200,
"/404": 404,
"/500": 500
},
"ok": [
"/"
]
}
CLI:
The module also provides a command-line interface. Passed arguments are in the format <status-code>=<url>
. Ensure url
is a valid url.
For example,
⇒ pageup 200=https://duckduckgo.com
✔ (200) https://duckduckgo.com/
You can also ignore the status-code
; 200
will be implied.
⇒ pageup https://duckduckgo.com
✔ (200) https://duckduckgo.com/
You can omit the protocol from the url; http
will be implied.
⇒ pageup duckduckgo.com
✔ (200) http://duckduckgo.com/
You can specify more than one url.
⇒ pageup duckduckgo.com forfuture.co.ke
✔ (200) http://forfuture.co.ke/
✔ (200) http://duckduckgo.com/
debugging:
To run your tests with debugging output of pageup enabled, set the DEBUG
environment variable to pageup
.
For example, in *nix:
⇒ DEBUG="pageup"
license:
The MIT License (MIT)
Copyright (c) 2015 GochoMugo [email protected]