2017-07-07 18:41:22 +08:00
|
|
|
exports.defineAutoTests = function() {
|
|
|
|
|
|
|
|
describe('Webserver (window.webserver)', function () {
|
|
|
|
var fns = [
|
|
|
|
'start'
|
|
|
|
];
|
|
|
|
|
|
|
|
it('should exist', function() {
|
|
|
|
expect(webserver).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
fns.forEach(function(fn) {
|
|
|
|
it('should contain a ' + fn + ' function', function () {
|
|
|
|
expect(typeof webserver[fn]).toBeDefined();
|
|
|
|
expect(typeof webserver[fn] === 'function').toBe(true);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
2017-07-10 15:58:47 +08:00
|
|
|
|
|
|
|
describe('Do a request', function() {
|
|
|
|
|
|
|
|
it('should do a request', function() {
|
|
|
|
webserver.onRequest(
|
|
|
|
function(request) {
|
|
|
|
// Check for a request is made
|
|
|
|
}
|
|
|
|
);
|
|
|
|
websever.start();
|
|
|
|
webserver.stop();
|
|
|
|
});
|
|
|
|
});
|
2017-07-07 18:41:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.defineManualTests = function(contentEl, createActionButton) {
|
2017-07-08 18:15:41 +08:00
|
|
|
createActionButton('Start bljad Webserver', function() {
|
|
|
|
console.log("Starting webserver...");
|
|
|
|
|
2017-07-10 15:58:47 +08:00
|
|
|
webserver.onRequest(
|
|
|
|
function(request) {
|
2017-07-10 20:38:46 +08:00
|
|
|
console.log('Received request');
|
2017-07-12 01:40:37 +08:00
|
|
|
console.log('requestId: ', request.requestId);
|
|
|
|
console.log('body: ', request.body);
|
|
|
|
console.log('headers: ', request.headers);
|
|
|
|
console.log('path: ', request.path);
|
|
|
|
console.log('query: ', request.query);
|
|
|
|
|
2017-07-10 20:38:46 +08:00
|
|
|
webserver.sendResponse(
|
2017-07-12 01:40:37 +08:00
|
|
|
request.requestId,
|
2017-07-10 20:38:46 +08:00
|
|
|
{
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
2017-07-12 01:40:37 +08:00
|
|
|
'Content-Type': 'text/html',
|
2017-07-10 20:38:46 +08:00
|
|
|
'TestHeader': 'Just a testheader'
|
|
|
|
},
|
2017-07-12 01:40:37 +08:00
|
|
|
body: '<html><form method="POST"><input type="text" name="bla" /><input type="submit" /></form></html>'
|
2017-07-10 20:38:46 +08:00
|
|
|
}
|
|
|
|
);
|
2017-07-10 15:58:47 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-07-08 18:15:41 +08:00
|
|
|
webserver.start(
|
|
|
|
function() {
|
|
|
|
console.log('Success!');
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
console.log('Error!');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
createActionButton('Start Webserver with Port 1337', function() {
|
|
|
|
console.log("Starting webserver...");
|
2017-07-07 21:23:55 +08:00
|
|
|
|
2017-07-07 18:41:22 +08:00
|
|
|
webserver.start(
|
|
|
|
function() {
|
|
|
|
console.log('Success!');
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
console.log('Error!');
|
|
|
|
},
|
2017-07-08 18:15:41 +08:00
|
|
|
1337
|
|
|
|
);
|
|
|
|
});
|
2017-07-07 18:41:22 +08:00
|
|
|
|
2017-07-08 18:15:41 +08:00
|
|
|
createActionButton('Stop Webserver', function() {
|
|
|
|
console.log("Stopping webserver...");
|
|
|
|
|
|
|
|
webserver.stop(
|
|
|
|
function() {
|
|
|
|
console.log('Success!');
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
console.log('Error!');
|
|
|
|
}
|
2017-07-07 18:41:22 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|