Skip to content

Commit d1d62f8

Browse files
committed
initial version
1 parent d50b1fa commit d1d62f8

6 files changed

+197
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Martin Kutschker
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1-
# inspectreJs
1+
# inspectreJS
22

3-
A web layout regression testing tool.
3+
A web layout regression testing tool for [PhantomJS](http://phantomjs.org/) and [SlimerJS](http://slimerjs.org/).
4+
5+
The code runs directly in PhantomJS or SlimerJS, it is not meant for [Node.js](https://nodejs.org/).
6+
7+
## Work In Progress
8+
9+
Eventually inspectreJS is to be used with a continuous integration server to compare screenshots, CSS styles and DOM elements.
10+
Currently it will only make screenshots of given URLs (full page or parts).
11+
12+
## Usage
13+
14+
`phantomjs inspectre.js <config.json>`
15+
16+
## Configuration File Format
17+
18+
``` json
19+
{
20+
"baseUrl": "<url>",
21+
"paths": [
22+
"<url-path>",
23+
{
24+
"path": "<url-path>",
25+
"selectors": "<css-selector>"
26+
},
27+
{
28+
"path": "<url-path>",
29+
"selectors": [
30+
"<css-selector>",
31+
...
32+
]
33+
},
34+
"<url>",
35+
...
36+
]
37+
}
38+
```
39+
40+
## License
41+
42+
MIT

inspectre.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
*
3+
*/
4+
5+
'use strict';
6+
7+
var system = require('system');
8+
var config = require('./lib/configuration.js');
9+
var ImageScraper = require('./../inspectre/node_modules/eerie-toolbox/lib/imagescraper.js');
10+
var configuration, queue;
11+
12+
if (system.args.length !== 2) {
13+
console.error("Usage: <phantomjs|slimerjs> inspectre.js config-file");
14+
phantom.exit(1);
15+
} else {
16+
try {
17+
configuration = config.read(system.args[1]);
18+
queue = config.buildImageScraperQueue(configuration);
19+
20+
ImageScraper.build().processQueue(
21+
queue,
22+
function (context) {
23+
phantom.exit();
24+
},
25+
function (item, error, context) {
26+
console.error('LOAD ERROR: ' + item.url);
27+
},
28+
function (item, error, context) {
29+
console.error('ERROR: ' + error.message);
30+
phantom.exit(1);
31+
}
32+
);
33+
} catch (error) {
34+
console.error('ERROR: ' + error.message);
35+
phantom.exit(1);
36+
}
37+
}

lib/configuration.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
*
3+
*/
4+
5+
'use strict';
6+
7+
var fs = require('fs');
8+
var URI = require('../node_modules/URIjs/src/URI.js');
9+
10+
/**
11+
*
12+
* @param {string} filename
13+
* @returns {object}
14+
*/
15+
function read(filename) {
16+
var configString, configObject;
17+
try {
18+
configString = fs.read(filename);
19+
} catch (error) {
20+
throw new Error('Unable to open configuration file "' + filename + '".');
21+
}
22+
try {
23+
configObject = JSON.parse(configString);
24+
} catch (error) {
25+
throw new Error('Unable to parse configuration file "' + filename + '".');
26+
}
27+
configObject.baseUrl = configObject.baseUrl || '';
28+
configObject.paths = configObject.paths || [];
29+
return configObject;
30+
}
31+
32+
/**
33+
*
34+
* @param {object} configuration
35+
* @returns {Array}
36+
*/
37+
function buildImageScraperQueue(configuration) {
38+
var baseUrl = new URI(configuration.baseUrl).normalize(),
39+
queue = [],
40+
i, path, selectors;
41+
for (i = 0; i < configuration.paths.length; i++) {
42+
if (typeof configuration.paths[i] === 'string') {
43+
path = configuration.paths[i];
44+
selectors = [];
45+
} else {
46+
path = configuration.paths[i].path;
47+
if (typeof configuration.paths[i].selectors === 'string') {
48+
selectors = [configuration.paths[i].selectors];
49+
} else {
50+
selectors = configuration.paths[i].selectors;
51+
}
52+
}
53+
queue.push({
54+
url: new URI(path).absoluteTo(baseUrl).normalize().toString(),
55+
selectors: selectors
56+
});
57+
}
58+
return queue;
59+
}
60+
61+
module.exports = {
62+
read: read,
63+
buildImageScraperQueue: buildImageScraperQueue
64+
};

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "inspectrejs",
3+
"version": "0.0.1",
4+
"description": "A web layout regression testing tool for PhantomJS and SlimerJS.",
5+
"keywords": [
6+
"phantomjs",
7+
"slimerjs",
8+
"screenshot",
9+
"cli"
10+
],
11+
"author": {
12+
"name": "Martin Kutschker",
13+
"email": "[email protected]"
14+
},
15+
"homepage": "https://github.com/masi/inspectrejs",
16+
"license": "MIT",
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/masi/inspectrejs.git"
20+
},
21+
"bugs": {
22+
"url": "https://github.com/masi/inspectrejs/issues"
23+
},
24+
"dependencies": {
25+
"eerie-toolbox": "*",
26+
"URIjs": ">=1.12"
27+
},
28+
"engines": {
29+
"phantomjs": "*",
30+
"slimerjs": "*"
31+
}
32+
}

0 commit comments

Comments
 (0)