UNPKG

valence-test

Version:

Test applications running in Valence and 5250 screens with Fusion5250

86 lines (79 loc) 2.21 kB
global.__base = __dirname + '/'; global.__util = __base + 'util/'; const fs = require('fs'), http = require('http'), schedule = require('node-schedule'), shell = require('shelljs'), config = require(global.__base + 'config.json'), helper = require(global.__util + 'helper'), email = require(global.__util + 'email'), /** * Test email configuration */ testEmail = (req, res) => { email.send(null, true, true).then(() => { res.end(JSON.stringify({ success : true })); }).catch((err) => { let errInfo = JSON.parse(JSON.stringify(err)); Object.assign(errInfo, { success : false }); res.end(JSON.stringify(errInfo)); }); }, /** * Run the tests */ runTests = (req, res) => { if (!helper.isEmpty(res)) { res.writeHead(200, { 'Context-Type' : 'text/plain' }); res.end('Tests Started'); } shell.exec('npm run codeceptjs'); }; /** * create HTTP Server */ http.createServer(function (req, res) { if (req.url === '/testEmail') { /** * test email */ testEmail(req, res); } else if (req.url === '/runTests') { /** * run all the tests now */ runTests(req, res); } else { /** * serve static pages */ fs.readFile(__dirname + req.url, function (err, data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return; } res.writeHead(200); res.end(data); }); } }).listen(config.port); /** * setup the schedule based on config * @type {RecurrenceRule} */ let rule = new schedule.RecurrenceRule(); rule.hour = config.schedule.hour; rule.minute = config.schedule.minute; if (config.schedule.dayOfWeek) { rule.dayOfWeek = config.schedule.dayOfWeek; } schedule.scheduleJob(rule, function () { runTests(); });