Make tests and updated the export of AppServer
This commit is contained in:
parent
4d462072bb
commit
f993aab1c2
3297
package-lock.json
generated
3297
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,9 @@
|
|||||||
import exec from 'cordova/exec';
|
import exec from 'cordova/exec';
|
||||||
|
|
||||||
|
import * as ImportedAppServer from './appserver/AppServer';
|
||||||
|
|
||||||
|
// Export the Appserver
|
||||||
|
export const AppServer = ImportedAppServer;
|
||||||
const WEBSERVER_CLASS = 'Webserver';
|
const WEBSERVER_CLASS = 'Webserver';
|
||||||
const START_FUNCTION = 'start';
|
const START_FUNCTION = 'start';
|
||||||
const ONREQUEST_FUNCTION = 'onRequest';
|
const ONREQUEST_FUNCTION = 'onRequest';
|
||||||
|
@ -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() {
|
exports.defineAutoTests = function() {
|
||||||
|
|
||||||
describe('Webserver (window.webserver)', function () {
|
describe('Webserver (window.webserver)', function () {
|
||||||
@ -19,14 +30,27 @@ exports.defineAutoTests = function() {
|
|||||||
|
|
||||||
describe('Do a request', function() {
|
describe('Do a request', function() {
|
||||||
|
|
||||||
it('should do a request', function() {
|
it('should do a request with plaintext', function() {
|
||||||
webserver.onRequest(
|
webserver.onRequest(
|
||||||
function(request) {
|
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();
|
websever.start();
|
||||||
webserver.stop();
|
|
||||||
|
request('GET', 'localhost:8080', undefined, function (response) {
|
||||||
|
expect(response.responseText).toBe('Test success!');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
Object.defineProperty(exports, "__esModule", {
|
Object.defineProperty(exports, "__esModule", {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
|
exports.AppServer = undefined;
|
||||||
exports.start = start;
|
exports.start = start;
|
||||||
exports.onRequest = onRequest;
|
exports.onRequest = onRequest;
|
||||||
exports.sendResponse = sendResponse;
|
exports.sendResponse = sendResponse;
|
||||||
@ -12,8 +13,15 @@ var _exec = require('cordova/exec');
|
|||||||
|
|
||||||
var _exec2 = _interopRequireDefault(_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 }; }
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
|
var AppServer = exports.AppServer = ImportedAppServer;
|
||||||
var WEBSERVER_CLASS = 'Webserver';
|
var WEBSERVER_CLASS = 'Webserver';
|
||||||
var START_FUNCTION = 'start';
|
var START_FUNCTION = 'start';
|
||||||
var ONREQUEST_FUNCTION = 'onRequest';
|
var ONREQUEST_FUNCTION = 'onRequest';
|
||||||
|
Loading…
Reference in New Issue
Block a user