File: commands/test/test.js

Recommend this page to a friend!
  Classes of Till Wehowski  >  Widget CLI  >  commands/test/test.js  >  Download  
File: commands/test/test.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Widget CLI
Process commands entered by the user
Author: By
Last change:
Date: 5 years ago
Size: 4,595 bytes
 

Contents

Class file image Download
/* webfan (C) Till Wehowski, Webfan.de - All rights reserved. */ 'use strict'; var frdl = require('frdl'); var util = require('util'); var util_opts = { showHidden : true, depth : 4 }; var taskGroup = false, group = false, sqlTask = frdl.task().ql, cliTask = frdl.task().cli ; exports.finalize = function(CLI){ CLI.log('Finalize the "test" command'); group.resume(); CLI.data.data = CLI.messageLog; CLI.emit('cmd.finalized', CLI.data.data); }; exports.prepare = function(CLI){ CLI.log('Prepare the "test" command'); CLI.finalState.add('cmd.finalized'); taskGroup = 'test '+ frdl.Guid.newGuid(); group = frdl.task(taskGroup); group.pause(); frdl.task(taskGroup, 'schedule', new cliTask( '$ js frdl.alert.log("test [arguments] #specify your tests as arguments to the test command, e.g `vm` or `task`...");' , false, 0)); CLI.once('catch', function(err){ group.clearAll(); CLI.finalState.cancel(); if(frdl.alert)frdl.alert.error(err, false, 0); }); CLI.addToken('test', '*', function(c, result_length, token, current_option){ frdl.task(taskGroup, 'schedule', new cliTask( '$ js frdl.alert.log("$ test '+token+'");' , false, 0)); }); CLI.addToken('test', 'task', function(c, result_length, token, current_option){ try{ var ev = 'ev_'+ frdl.Guid.newGuid(); CLI.finalState.add(ev); frdl.task(taskGroup, 'schedule', (function(){ frdl.task(taskGroup, 'schedule', (function(){alert("hello wold! ($ js from test task)");}) ,100); frdl.task(taskGroup, 'schedule', new cliTask( '$ js alert("hello wold! ($ js from test task)")' , 'frdl.alert', 100)); frdl.task(taskGroup, 'schedule', new cliTask( 'help' , 'frdl.alert', 1)); CLI.emit(ev); }),2); }catch(err){ CLI.error(err); } }); CLI.addToken('test', 'vm', function(c, result_length, token, current_option){ var ev = 'ev_'+ frdl.Guid.newGuid(); CLI.finalState.add(ev); frdl.task(taskGroup, 'schedule', (function(){ try{ var ts = 'declare var id :any;declare var anOldContextVar :any;var m = "Ooops, a local scope var!?! @...";id="newID=#myID";frdl.alert.log(m, false, 0);anOldContextVar += \' modified\';'; var vm = require('vm'); var script = vm.createScript(ts,{ compile : 'text/typescript' }); var _newContext = script.runInNewContext({ id : 'oldID=barFoo', anOldContextVar : 'anOldContextVarValue' }); alert(script.code); _newContext = vm.runInContext(script.code, _newContext, { }); frdl.alert.log(util.inspect(_newContext, util_opts), false, 0); }catch(err){ CLI.emit('catch', err); } }),2); frdl.task(taskGroup, 'schedule', (function(){ try{ var js = 'declare var id :any;var m = "Ooops, a modified context!?! @...";id="newID=#myID";'; var vm = require('vm'); var _newContext = vm.runInContext(js, { id : 'oldID=barFoo' }, { compile : 'text/typescript' }); frdl.alert.log(util.inspect(_newContext, util_opts), false, 0); }catch(err){ CLI.emit('catch', err); } }),3); frdl.task(taskGroup, 'schedule', (function(){ try{ var js = 'window.alert(window.JSON.stringify(angular));'; var vm = require('vm'); var _newContext = vm.runInContext(js, frdl.UI.widgets[0]); }catch(err){ CLI.emit('catch', err); } }),4); frdl.task(taskGroup, 'schedule', (function(){ try{ var js = function(){window.alert(window.JSON.stringify(html()));}; var vm = require('vm'); var _newContext = vm.runInContext(js, frdl.UI.widgets[0]); }catch(err){ CLI.emit('catch', err); } CLI.emit(ev); }),5); }); };