Make tests and updated the export of AppServer

This commit is contained in:
Michael Bykovski 2017-07-21 11:48:05 +02:00
parent 4d462072bb
commit f993aab1c2
4 changed files with 3014 additions and 325 deletions

3297
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,9 @@
import exec from 'cordova/exec';
import * as ImportedAppServer from './appserver/AppServer';
// Export the Appserver
export const AppServer = ImportedAppServer;
const WEBSERVER_CLASS = 'Webserver';
const START_FUNCTION = 'start';
const ONREQUEST_FUNCTION = 'onRequest';

View File

@ -1,3 +1,14 @@
function request(method, url, data, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
callback(this);
}
};
xhttp.open(method, url, true);
xhttp.send(data);
}
exports.defineAutoTests = function() {
describe('Webserver (window.webserver)', function () {
@ -19,14 +30,27 @@ exports.defineAutoTests = function() {
describe('Do a request', function() {
it('should do a request', function() {
it('should do a request with plaintext', function() {
webserver.onRequest(
function(request) {
// Check for a request is made
webserver.sendResponse(
request.requestId,
{
status: 200,
headers: {
'Content-Type': 'text/plain',
'TestHeader': 'Just a testheader'
},
body: 'Test success!'
}
)
}
);
websever.start();
webserver.stop();
request('GET', 'localhost:8080', undefined, function (response) {
expect(response.responseText).toBe('Test success!');
});
});
});
};

View File

@ -3,6 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.AppServer = undefined;
exports.start = start;
exports.onRequest = onRequest;
exports.sendResponse = sendResponse;
@ -12,8 +13,15 @@ var _exec = require('cordova/exec');
var _exec2 = _interopRequireDefault(_exec);
var _AppServer = require('./appserver/AppServer');
var ImportedAppServer = _interopRequireWildcard(_AppServer);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var AppServer = exports.AppServer = ImportedAppServer;
var WEBSERVER_CLASS = 'Webserver';
var START_FUNCTION = 'start';
var ONREQUEST_FUNCTION = 'onRequest';