Commit 8af0aefc authored by Stanley Shyiko's avatar Stanley Shyiko

Added test/ (+ enabled semistandard)

parent f82d10f8
...@@ -15,7 +15,13 @@ ...@@ -15,7 +15,13 @@
"electron-prebuilt": "^0.35.4" "electron-prebuilt": "^0.35.4"
}, },
"devDependencies": { "devDependencies": {
"electron-packager": "^5.1.1" "electron-packager": "^5.1.1",
"chai": "^3.4.1",
"mocha": "^2.3.4",
"semistandard": "^7.0.4"
},
"semistandard": {
"globals": ["chrome", "describe", "it", "before"]
}, },
"scripts": { "scripts": {
"clean": "rm -rf build", "clean": "rm -rf build",
...@@ -26,7 +32,8 @@ ...@@ -26,7 +32,8 @@
"tar:macosx": "cd build/electron-har-darwin-x64 && tar -cvzf ../electron-har-$npm_package_version-darwin-x64.tar.gz *", "tar:macosx": "cd build/electron-har-darwin-x64 && tar -cvzf ../electron-har-$npm_package_version-darwin-x64.tar.gz *",
"tar:linux": "echo x64 ia32 | xargs -n1 -I{} sh -c \"cd build/electron-har-linux-{} && tar -cvzf ../electron-har-$npm_package_version-linux-{}.tar.gz *\"", "tar:linux": "echo x64 ia32 | xargs -n1 -I{} sh -c \"cd build/electron-har-linux-{} && tar -cvzf ../electron-har-$npm_package_version-linux-{}.tar.gz *\"",
"tar": "npm run tar:macosx && npm run tar:linux", "tar": "npm run tar:macosx && npm run tar:linux",
"release": "npm run build && npm run tar" "release": "npm run build && npm run tar",
"test": "semistandard src/**/*.js test/**/*.js && ./node_modules/mocha/bin/mocha -R spec"
}, },
"keywords": [ "keywords": [
"electron", "electron",
......
var expect = require('chai').expect;
var http = require('http');
var url = require('url');
var exec = require('child_process').exec;
describe('electron-har', function () {
this.timeout(10000);
var baseURL;
before(function (done) {
var server = http.createServer(function (req, res) {
var path = url.parse(req.url).pathname;
switch (path) {
case '/':
res.setHeader('Content-Type', 'text/html');
res.write(
'<!DOCTYPE html>' +
'<script src="index.js"></script>'
);
break;
case '/index.js':
res.setHeader('Content-Type', 'application/javascript');
res.write(
'console.log("I wish I was a pony!")'
);
break;
case '/self-destruct':
if (req.headers.authorization === 'Basic ' +
new Buffer('jean_luc_picard:picard_4_7_alpha_tango')
.toString('base64')) {
res.setHeader('Content-Type', 'text/plain');
res.write('BOOM!');
} else {
res.setHeader('WWW-Authenticate', 'Basic realm=Hogwarts');
res.statusCode = 401;
}
break;
default:
res.statusCode = 404;
}
res.end();
});
server.on('listening', function () {
var addr = server.address();
baseURL = 'http://localhost:' + addr.port;
done();
});
server.listen(0);
});
it('should include all resources before onload', function (done) {
exec(__dirname + '/../bin/electron-har "' + baseURL + '/"',
function (err, stdout, stderr) {
if (err) {
throw err;
}
var har = JSON.parse(stdout);
expect(har.log.entries.length).to.be.equal(2); // html + script
done();
});
});
it('should generate valid HAR even if url leads to something other than html',
function (done) {
exec(__dirname + '/../bin/electron-har "' + baseURL + '/index.js"',
function (err, stdout, stderr) {
if (err) {
throw err;
}
var har = JSON.parse(stdout);
expect(har.log.entries.length).to.be.equal(1);
done();
});
});
it('should return an error in case of malformed url', function (done) {
exec(__dirname + '/../bin/electron-har "http://_"',
function (err, stdout, stderr) {
expect(err).to.exist;
expect(stderr).to.contain('attempt to generate HAR resulted in error code -');
done();
});
});
it('should attempt to authenticate in case url is protected', function (done) {
exec(__dirname + '/../bin/electron-har -u jean_luc_picard:picard_4_7_alpha_tango "' + baseURL + '/self-destruct"',
function (err, stdout, stderr) {
if (err) {
throw err;
}
var har = JSON.parse(stdout);
expect(har.log.entries.length).to.be.equal(1);
expect(har.log.entries[0].response.status).to.be.equal(200); // not 401
done();
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment