Skip to content

Commit 3455800

Browse files
committed
Merge pull request #7 from solidusjs/add-unit-testing
Add Jasmine unit testing framework
2 parents d74ae72 + 41a0fcd commit 3455800

18 files changed

Lines changed: 157 additions & 50 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
bower_components
3+
.grunt

Gruntfile.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,36 @@ module.exports = function(grunt) {
33
// Project configuration.
44
grunt.initConfig({
55
pkg: grunt.file.readJSON('package.json'),
6+
manifest: grunt.file.readJSON('extension/manifest.json'),
67
jshint: {
7-
files: ['*.js', 'views/*.js'],
8+
files: ['extension/*.js'],
89
options: {
910
jshintrc: true
1011
}
12+
},
13+
jasmine: {
14+
src: ['extension/*.js'],
15+
options: {
16+
specs: 'tests/spec/*.spec.js',
17+
helpers: 'tests/spec/*.helper.js'
18+
}
19+
},
20+
run: {
21+
crxmake: {
22+
exec: [
23+
'./crxmake.sh extension/ cert/key.pem',
24+
'mv extension.crx dist/<%= pkg.name %>-<%= manifest.version %>.crx'
25+
].join(' && ')
26+
}
1127
}
1228
});
1329

14-
grunt.loadNpmTasks('grunt-contrib-uglify');
1530
grunt.loadNpmTasks('grunt-contrib-jshint');
16-
grunt.loadNpmTasks('grunt-contrib-nodeunit');
31+
grunt.loadNpmTasks('grunt-contrib-jasmine');
32+
grunt.loadNpmTasks('grunt-run');
1733

18-
grunt.registerTask('default', ['uglify']);
19-
grunt.registerTask('test', ['jshint']);
34+
grunt.registerTask('default', ['jshint', 'jasmine']);
35+
grunt.registerTask('test', ['jshint', 'jasmine']);
36+
grunt.registerTask('build', ['jshint', 'jasmine', 'run:crxmake']);
2037

2138
};

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
A Google Chrome developer tools extension for use by [Solidus](https://github.com/solidusjs/solidus) developers. Provides real-time introspection of API data and access to Solidus server error logs for use in debugging preprocessors executed in the Node.js runtime environment.
22

3-
**Note:** This is still a work in progress, use at your own risk.
4-
5-
#Build
3+
#Clone
64
* Clone the repo with `git clone https://github.com/solidusjs/devtools-solidus.git devtools-solidus`
7-
* Run `npm install` to install dependencies (npm will automatically run a script to install front-end dependencies using bower).
8-
* (Optional) Chrome will complain about `.pem` files in some of the dependencies, so you can manually delete `node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws/test/` to prevent Chrome from warning you when you install the extension.
95

106
#Installation
11-
* Open chrome://extensions
12-
* Enable 'Developer Mode' checkbox
13-
* Click 'Load unpacked extensions...'
14-
* Select the `devtools-solidus` folder
7+
* Find the `.crx` file you want in the `dist/` directory. We recommend using the latest version, or you can manually build your own (see below).
8+
* Open <chrome://extensions> in Chrome
9+
* Drag and drop the `.crx` file onto the page and click "Add" to install.
10+
11+
#Manually Build
12+
* Run `npm install` to install dependencies (npm will automatically run a script to install front-end dependencies using bower).
13+
* Run `grunt build` to generate an installable `.crx` file in the `dist/` directory.
14+
15+
#Usage
16+
* Once the extension is installed, you can open Chrome's Developer Tools and you should see a "Solidus" tab.

crxmake.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash -e
2+
#
3+
# Purpose: Pack a Chromium extension directory into crx format
4+
5+
if test $# -ne 2; then
6+
echo "Usage: crxmake.sh <extension dir> <pem path>"
7+
exit 1
8+
fi
9+
10+
dir=$1
11+
key=$2
12+
name=$(basename "$dir")
13+
crx="$name.crx"
14+
pub="$name.pub"
15+
sig="$name.sig"
16+
zip="$name.zip"
17+
trap 'rm -f "$pub" "$sig" "$zip"' EXIT
18+
19+
# zip up the crx dir
20+
cwd=$(pwd -P)
21+
(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
22+
23+
# signature
24+
openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
25+
26+
# public key
27+
openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null
28+
29+
byte_swap () {
30+
# Take "abcdefgh" and return it as "ghefcdab"
31+
echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
32+
}
33+
34+
crmagic_hex="4372 3234" # Cr24
35+
version_hex="0200 0000" # 2
36+
pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}')))
37+
sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}')))
38+
(
39+
echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p
40+
cat "$pub" "$sig" "$zip"
41+
) > "$crx"
42+
echo "Wrote $crx"

dist/devtools-solidus-0.1.0.crx

2.79 MB
Binary file not shown.

background.js renamed to extension/background.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ function notifyDevtools(msgType, payload) {
4040
});
4141
}
4242

43+
function isSolidus(xpbHeader) {
44+
if (xpbHeader.match(/Solidus/i)) {
45+
return true;
46+
} else {
47+
return false;
48+
}
49+
}
50+
4351
function getJsonResource(tabID) {
4452
chrome.tabs.get(tabID, function(tab) {
4553
var jsonResourceURL = tab.url+'.json';
@@ -48,7 +56,7 @@ function getJsonResource(tabID) {
4856
xhr.onreadystatechange = function() {
4957
if (xhr.readyState !== 4) return; //quickly return if not complete request
5058
var xpbHeader = xhr.getResponseHeader('X-Powered-By') || 'unknown';
51-
if (!xpbHeader.match(/Solidus/i)) { //quickly return if not solidus
59+
if (!isSolidus(xpbHeader)) { //quickly return if not solidus
5260
notifyDevtools('error', 'No Solidus header detected.');
5361
notifyDevtools('status', '<b>not</b> running Solidus 0.1.7 or greater');
5462
notifyDevtools('action', 'shutdown');

bower.json renamed to extension/bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"Eric Lanehart <eric@sparkart.com>"
88
],
99
"description": "Adds Solidus debugging tools to the Chrome Developer Tools.",
10-
"main": "views/devpanel.html",
10+
"main": "app/devpanel.html",
1111
"moduleType": [
1212
"node"
1313
],
@@ -29,7 +29,8 @@
2929
"bootstrap": "~3.2.0",
3030
"Inspector-JSON": "SparkartGroupInc/Inspector-JSON#e6bec9fe4cc7551cd46f44bafed6891620a5e47d",
3131
"bootstrap-vertical-tabs": "~1.1.0",
32-
"jquery-ui": "~1.11.0"
32+
"jquery-ui": "~1.11.0",
33+
"socket.io-client": "^1.0.6"
3334
},
3435
"resolutions": {
3536
"bootstrap": "~3.2.0"
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
<html>
33
<head>
44

5-
<link rel="stylesheet" href="../bower_components/jquery-ui/themes/smoothness/jquery-ui.css">
5+
<link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.css">
66

7-
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
8-
<script src="../bower_components/jquery-ui/jquery-ui.js"></script>
9-
<script src="../node_modules/socket.io-client/socket.io.js"></script>
7+
<script src="bower_components/jquery/dist/jquery.min.js"></script>
8+
<script src="bower_components/jquery-ui/jquery-ui.js"></script>
9+
<script src="bower_components/socket.io-client/socket.io.js"></script>
1010
<script src="devpanel.js"></script>
11-
<script src="../bower_components/Inspector-JSON/inspector-json.js"></script>
12-
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
11+
<script src="bower_components/Inspector-JSON/inspector-json.js"></script>
12+
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
1313

14-
<link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" media="all" rel="stylesheet" type="text/css">
15-
<link href="../bower_components/bootstrap-vertical-tabs/bootstrap.vertical-tabs.min.css" media="all" rel="stylesheet" type="text/css">
14+
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" media="all" rel="stylesheet" type="text/css">
15+
<link href="bower_components/bootstrap-vertical-tabs/bootstrap.vertical-tabs.min.css" media="all" rel="stylesheet" type="text/css">
1616
<link href="devpanel.css" media="all" rel="stylesheet" type="text/css">
1717
</head>
1818
<body>
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
var inspector;
1212

13-
var socket = io('http://localhost:8081');
14-
socket.on('connect', function(){
15-
socket.on('log', function(data){
16-
addToLog(data.message);
17-
});
18-
socket.on('disconnect', function(){
19-
document.querySelector('#serverlogs').innerHTML = 'Socket Disconnected';
20-
});
21-
});
13+
if (typeof io !== 'undefined') {
14+
var socket = io('http://localhost:8081');
15+
socket.on('connect', function(){
16+
socket.on('log', function(data){
17+
addToLog(data.message);
18+
});
19+
socket.on('disconnect', function(){
20+
document.querySelector('#serverlogs').innerHTML = 'Socket Disconnected';
21+
});
22+
});
23+
}
2224

2325
function processMainIncomingMessage(msg) {
2426
switch(msg.msgType) {
@@ -100,17 +102,23 @@ function updateStatus(status) { //Update status panel in footer
100102
}
101103

102104
function addToLog(msg) {
103-
var logContainer = document.querySelector('#serverlogs');
104-
logContainer.innerHTML += msg + '\n';
105-
logContainer.scrollTop = logContainer.scrollHeight;
105+
if (document.querySelector('#serverlogs')) {
106+
var logContainer = document.querySelector('#serverlogs');
107+
logContainer.innerHTML += msg + '\n';
108+
logContainer.scrollTop = logContainer.scrollHeight;
109+
}
106110
}
107111

108112
function clearLog() {
109113
document.querySelector('#serverlogs').innerHTML = '';
110114
}
111115

112-
window.onload = function() {
113-
var clearButton = document.querySelector('#logclear');
114-
clearButton.addEventListener('click', clearLog, false);
115-
$('#sidePanel').resizable({ minWidth: 120, handles: 'e'});
116-
};
116+
window.addEventListener('load', function() {
117+
if (document.querySelector('#logclear')) {
118+
var clearButton = document.querySelector('#logclear');
119+
clearButton.addEventListener('click', clearLog, false);
120+
}
121+
if (document.querySelector('#sidePanel')) {
122+
$('#sidePanel').resizable({ minWidth: 120, handles: 'e'});
123+
}
124+
}, false);

0 commit comments

Comments
 (0)