Best JavaScript code snippet using qawolf
test.js
Source:test.js
1var fs = require('fs');2var path = require('path');3var assert = require('assert');4var vm = require('vm');5var babel = require("@babel/core");6var buildDictionary = require('../buildDictionary');7var translator;8var runtime = fs.readFileSync(path.join(__dirname, '../runtime.js'), 'utf-8');9describe('', function () {10 before(function () {11 process.chdir('./test/repo');12 var dictionary = buildDictionary('en-US');13 var pluralize = require('pluralize');14 var ordinal = require('ordinal');15 var zhTWTranslator = require('./zhTWTranslator');16 translator = {17 'en-US': {18 dictionary: dictionary,19 pluralize: pluralize,20 ordinalize: ordinal21 },22 'zh-TW': zhTWTranslator23 };24 });25 after(function () {26 process.chdir('../..');27 });28 it('string literal', function () {29 var result = babel.transformFileSync("./StringLiteral.js", {30 plugins: [require('..')]31 });32 var context = {};33 vm.createContext(context);34 vm.runInContext(runtime, context);35 vm.runInContext("i18n = I18n();", context);36 context.i18n.translator = translator;37 context.i18n.language = 'en-US';38 assert.equal(vm.runInContext(result.code, context), "OK");39 });40 describe('template literal', function () {41 it('template literal', function () {42 var result = babel.transformFileSync("./TemplateLiteral.js", {43 plugins: [require('..')]44 });45 var name = "Jack";46 var context = { name: name };47 vm.createContext(context);48 vm.runInContext(runtime, context);49 vm.runInContext("i18n = I18n();", context);50 context.i18n.translator = translator;51 context.i18n.language = 'en-US';52 assert.equal(vm.runInContext(result.code, context), `Hello, ${name}!`);53 });54 it('{}ç{}å±æ§', function () {55 var result = babel.transformFileSync("./TemplateLiteral.{}ç{}å±æ§.js", {56 plugins: [require('..')]57 });58 var object = 'customer', property = 'name';59 var context = {60 object: object,61 property: property62 };63 vm.createContext(context);64 vm.runInContext(runtime, context);65 vm.runInContext("i18n = I18n();", context);66 context.i18n.translator = translator;67 context.i18n.language = 'en-US';68 assert.equal(vm.runInContext(result.code, context), `${property} property of ${object}`);69 });70 it('pluralize', function () {71 var result = babel.transformFileSync("./TemplateLiteral.pluralize.js", {72 plugins: [require('..')]73 });74 var n = 3;75 var context = { n: n };76 vm.createContext(context);77 vm.runInContext(runtime, context);78 vm.runInContext("i18n = I18n();", context);79 context.i18n.translator = translator;80 context.i18n.language = 'en-US';81 assert.equal(vm.runInContext(result.code, context), `${n} messages`);82 n = 1;83 context.n = n;84 assert.equal(vm.runInContext(result.code, context), `${n} message`);85 });86 it('ordinalize', function () {87 var result = babel.transformFileSync("./TemplateLiteral.ordinalize.js", {88 plugins: [require('..')]89 });90 var n = 3;91 var context = { n: n };92 vm.createContext(context);93 vm.runInContext(runtime, context);94 vm.runInContext("i18n = I18n();", context);95 context.i18n.translator = translator;96 context.i18n.language = 'en-US';97 assert.equal(vm.runInContext(result.code, context), `The 3rd message`);98 });99 it('map', function () {100 var result = babel.transformFileSync("./TemplateLiteral.map.js", {101 plugins: [require('..')]102 });103 var n = 3;104 var context = { n: n };105 vm.createContext(context);106 vm.runInContext(runtime, context);107 vm.runInContext("i18n = I18n();", context);108 context.i18n.translator = translator;109 context.i18n.language = 'en-US';110 assert.equal(vm.runInContext(result.code, context), "Apr");111 });112 });113 var React = {114 createElement(type, props, children) {115 return {116 type: type,117 props: props,118 children: children119 };120 },121 Fragment: function () { }122 };123 var Icon = function () { };124 describe('jsx element', function () {125 it('jsx element', function () {126 var result = babel.transformFileSync("./JSXElement.js", {127 presets: [require('@babel/preset-react')],128 plugins: [require('..')]129 });130 var context = {131 React: React,132 Icon: Icon133 };134 vm.createContext(context);135 vm.runInContext(runtime, context);136 vm.runInContext("i18n = I18n(); i18n.React = React;", context);137 context.i18n.translator = translator;138 context.i18n.language = 'en-US';139 assert.deepEqual(140 vm.runInContext(result.code, context),141 React.createElement("div", {}, [142 "",143 React.createElement(Icon, { type: "plus" }),144 "New"145 ])146 );147 });148 it('jsx fragment', function () {149 var result = babel.transformFileSync("./JSXFragment.js", {150 presets: [require('@babel/preset-react')],151 plugins: [require('..')]152 });153 var context = {154 React: React,155 Icon: Icon156 };157 vm.createContext(context);158 vm.runInContext(runtime, context);159 vm.runInContext("i18n = I18n(); i18n.React = React;", context);160 context.i18n.translator = translator;161 context.i18n.language = 'en-US';162 assert.deepEqual(163 vm.runInContext(result.code, context),164 React.createElement(React.Fragment, {}, [165 "",166 React.createElement(Icon, { type: "plus" }),167 "New"168 ])169 );170 });171 it('{}ç{}å±æ§', function () {172 var result = babel.transformFileSync("./JSXElement.{}ç{}å±æ§.js", {173 presets: [require('@babel/preset-react')],174 plugins: [require('..')]175 });176 var object = 'customer', property = 'name';177 var context = {178 React: React,179 object: object,180 property: property181 };182 vm.createContext(context);183 vm.runInContext(runtime, context);184 vm.runInContext("i18n = I18n(); i18n.React = React;", context);185 context.i18n.translator = translator;186 context.i18n.language = 'en-US';187 assert.deepEqual(188 vm.runInContext(result.code, context),189 React.createElement("span", {}, [190 "", property, " property of ", object, ""191 ])192 );193 });194 it('pluralize', function () {195 var result = babel.transformFileSync("./JSXElement.pluralize.js", {196 presets: [require('@babel/preset-react')],197 plugins: [require('..')]198 });199 var n = 3;200 var context = {201 React: React,202 Icon: Icon,203 n: n204 };205 vm.createContext(context);206 vm.runInContext(runtime, context);207 vm.runInContext("i18n = I18n(); i18n.React = React;", context);208 context.i18n.translator = translator;209 context.i18n.language = 'en-US';210 assert.deepEqual(211 vm.runInContext(result.code, context),212 React.createElement("span", {}, [213 "",214 n,215 " messages"216 ])217 );218 n = 1;219 context.n = n;220 assert.deepEqual(221 vm.runInContext(result.code, context),222 React.createElement("span", {}, [223 "",224 n,225 " message"226 ])227 );228 });229 it('jsx fragment pluralize', function () {230 var result = babel.transformFileSync("./JSXFragment.pluralize.js", {231 presets: [require('@babel/preset-react')],232 plugins: [require('..')]233 });234 var n = 3;235 var context = {236 React: React,237 Icon: Icon,238 n: n239 };240 vm.createContext(context);241 vm.runInContext(runtime, context);242 vm.runInContext("i18n = I18n(); i18n.React = React;", context);243 context.i18n.translator = translator;244 context.i18n.language = 'en-US';245 assert.deepEqual(246 vm.runInContext(result.code, context),247 React.createElement(React.Fragment, {}, [248 "",249 n,250 " messages"251 ])252 );253 n = 1;254 context.n = n;255 assert.deepEqual(256 vm.runInContext(result.code, context),257 React.createElement(React.Fragment, {}, [258 "",259 n,260 " message"261 ])262 );263 });264 it('string prop', function () {265 var result = babel.transformFileSync("./JSXElement.stringProp.js", {266 presets: [require('@babel/preset-react')],267 plugins: [require('..')]268 });269 var context = {270 React: React271 };272 vm.createContext(context);273 vm.runInContext(runtime, context);274 vm.runInContext("i18n = I18n(); i18n.React = React;", context);275 context.i18n.translator = translator;276 context.i18n.language = 'en-US';277 assert.deepEqual(278 vm.runInContext(result.code, context),279 React.createElement("span", { title: "OK" })280 );281 });282 it('member element', function () {283 var result = babel.transformFileSync("./JSXElement.memberElement.js", {284 presets: [require('@babel/preset-react')],285 plugins: [require('..')]286 });287 var Radio = { Button: function () { } };288 var context = {289 React: React,290 Radio: Radio291 };292 vm.createContext(context);293 vm.runInContext(runtime, context);294 vm.runInContext("i18n = I18n(); i18n.React = React;", context);295 context.i18n.translator = translator;296 context.i18n.language = 'en-US';297 assert.deepEqual(298 vm.runInContext(result.code, context),299 React.createElement(Radio.Button, { value: "text" }, ["Text"])300 );301 });302 it('jsx empty expression', function () {303 var result = babel.transformFileSync("./JSXElement.JSXEmptyExpression.js", {304 presets: [require('@babel/preset-react')],305 plugins: [require('..')]306 });307 var context = {308 React: React,309 Icon: Icon310 };311 vm.createContext(context);312 vm.runInContext(runtime, context);313 vm.runInContext("i18n = I18n(); i18n.React = React;", context);314 context.i18n.translator = translator;315 context.i18n.language = 'en-US';316 assert.deepEqual(317 vm.runInContext(result.code, context),318 React.createElement("div", {}, [319 "",320 React.createElement(Icon, { type: "plus" }),321 "New"322 ])323 );324 });325 it('space', function () {326 var result = babel.transformFileSync("./JSXElement.space.js", {327 presets: [require('@babel/preset-react')],328 plugins: [require('..')]329 });330 var context = {331 React: React332 };333 vm.createContext(context);334 vm.runInContext(runtime, context);335 vm.runInContext("i18n = I18n(); i18n.React = React;", context);336 context.i18n.translator = translator;337 context.i18n.language = 'en-US';338 assert.deepEqual(339 vm.runInContext(result.code, context),340 React.createElement("div", {}, [341 " me you you him",342 React.createElement("div", null),343 "it it it"344 ])345 );346 });347 it('space.prettier', function () {348 var result = babel.transformFileSync("./JSXElement.space.prettier.js", {349 presets: [require('@babel/preset-react')],350 plugins: [require('..')]351 });352 var context = {353 React: React354 };355 vm.createContext(context);356 vm.runInContext(runtime, context);357 vm.runInContext("i18n = I18n(); i18n.React = React;", context);358 context.i18n.translator = translator;359 context.i18n.language = 'en-US';360 assert.deepEqual(361 vm.runInContext(result.code, context),362 React.createElement("p", {}, [363 "Click ",364 React.createElement("a", {}, ["here"]),365 " for detail"366 ])367 );368 });369 });370 it('stringIndex.TemplateLiteral', function () {371 var result = babel.transformFileSync("./stringIndex.TemplateLiteral.js", {372 plugins: [require('..')]373 });374 var object = 'customer', property = 'name';375 var context = {376 object: object,377 property: property378 };379 vm.createContext(context);380 vm.runInContext(runtime, context);381 vm.runInContext("i18n = I18n();", context);382 context.i18n.translator = translator;383 context.i18n.language = 'en-US';384 assert.equal(vm.runInContext(result.code, context), `${property} property of ${object}`);385 });386 it('stringIndex.JSXElement', function () {387 var result = babel.transformFileSync("./stringIndex.JSXElement.js", {388 presets: [require('@babel/preset-react')],389 plugins: [require('..')],390 parserOpts: { plugins: ['jsx'] }391 });392 var object = 'customer', property = 'name';393 var context = {394 React: React,395 object: object,396 property: property397 };398 vm.createContext(context);399 vm.runInContext(runtime, context);400 vm.runInContext("i18n = I18n(); i18n.React = React;", context);401 context.i18n.translator = translator;402 context.i18n.language = 'en-US';403 assert.deepEqual(404 vm.runInContext(result.code, context),405 React.createElement("span", {}, [406 "", property, " property of ", object, ""407 ])408 );409 });410 describe('escape', function () {411 it('string literal', function () {412 var result = babel.transformFileSync("./escape.StringLiteral.js", {413 plugins: [require('..')]414 });415 var context = {};416 vm.createContext(context);417 vm.runInContext(runtime, context);418 vm.runInContext("i18n = I18n();", context);419 context.i18n.translator = translator;420 context.i18n.language = 'en-US';421 assert.equal(vm.runInContext(result.code, context), "Cannot contain following characters: \\()[]{}");422 });423 it('template literal', function () {424 var result = babel.transformFileSync("./escape.TemplateLiteral.js", {425 plugins: [require('..')]426 });427 var name = 'f';428 var context = { name: name };429 vm.createContext(context);430 vm.runInContext(runtime, context);431 vm.runInContext("i18n = I18n();", context);432 context.i18n.translator = translator;433 context.i18n.language = 'en-US';434 assert.equal(vm.runInContext(result.code, context), `function ${name}() { }\t// empty function`);435 });436 it('jsx element', function () {437 var result = babel.transformFileSync("./escape.JSXElement.js", {438 presets: [require('@babel/preset-react')],439 plugins: [require('..')]440 });441 var name = 'f';442 var context = {443 React: React,444 name: name445 };446 vm.createContext(context);447 vm.runInContext(runtime, context);448 vm.runInContext("i18n = I18n(); i18n.React = React;", context);449 context.i18n.translator = translator;450 context.i18n.language = 'en-US';451 assert.deepEqual(452 vm.runInContext(result.code, context),453 React.createElement("div", {}, [454 "function ", name, "() { }\t// empty function"455 ])456 );457 });458 it('jsx fragment', function () {459 var result = babel.transformFileSync("./escape.JSXFragment.js", {460 presets: [require('@babel/preset-react')],461 plugins: [require('..')]462 });463 var name = 'f';464 var context = {465 React: React,466 name: name467 };468 vm.createContext(context);469 vm.runInContext(runtime, context);470 vm.runInContext("i18n = I18n(); i18n.React = React;", context);471 context.i18n.translator = translator;472 context.i18n.language = 'en-US';473 assert.deepEqual(474 vm.runInContext(result.code, context),475 React.createElement(React.Fragment, {}, [476 "function ", name, "() { }\t// empty function"477 ])478 );479 });480 });481 it('ignore', function () {482 var result = babel.transformFileSync("./ignore.js", {483 plugins: [require('..')]484 });485 var context = {};486 vm.createContext(context);487 vm.runInContext(runtime, context);488 vm.runInContext("i18n = I18n();", context);489 context.i18n.translator = translator;490 context.i18n.language = 'en-US';491 assert.equal(vm.runInContext(result.code, context), "ç¡®å®");492 });493 it('explicit', function () {494 var result = babel.transformFileSync("./explicit.js", {495 plugins: [require('..')]496 });497 var context = {};498 vm.createContext(context);499 vm.runInContext(runtime, context);500 vm.runInContext("i18n = I18n();", context);501 context.i18n.translator = translator;502 context.i18n.language = 'en-US';503 assert.equal(vm.runInContext(result.code, context), "OK");504 });505 it('key', function () {506 var result = babel.transformFileSync("./key.js", {507 plugins: [require('..')]508 });509 var context = {};510 vm.createContext(context);511 vm.runInContext(runtime, context);512 vm.runInContext("i18n = I18n();", context);513 context.i18n.translator = translator;514 context.i18n.language = 'en-US';515 assert.equal(vm.runInContext(result.code, context), "Are you sure you want to delete this message?");516 });517 it('key.TemplateLiteral', function () {518 var result = babel.transformFileSync("./key.TemplateLiteral.js", {519 plugins: [require('..')]520 });521 var object = 'customer', property = 'name';522 var context = {523 object: object,524 property: property525 };526 vm.createContext(context);527 vm.runInContext(runtime, context);528 vm.runInContext("i18n = I18n();", context);529 context.i18n.translator = translator;530 context.i18n.language = 'en-US';531 assert.equal(vm.runInContext(result.code, context), `${property} property of ${object}`);532 });533 it('key.JSXElement', function () {534 var result = babel.transformFileSync("./key.JSXElement.js", {535 presets: [require('@babel/preset-react')],536 plugins: [require('..')],537 parserOpts: { plugins: ['jsx'] }538 });539 var object = 'customer', property = 'name';540 var context = {541 React: React,542 object: object,543 property: property544 };545 vm.createContext(context);546 vm.runInContext(runtime, context);547 vm.runInContext("i18n = I18n(); i18n.React = React;", context);548 context.i18n.translator = translator;549 context.i18n.language = 'en-US';550 assert.deepEqual(551 vm.runInContext(result.code, context),552 React.createElement("span", {}, [553 "", property, " property of ", object, ""554 ])555 );556 });557 it('explicit.key', function () {558 var result = babel.transformFileSync("./explicit.key.js", {559 plugins: [require('..')]560 });561 var context = {};562 vm.createContext(context);563 vm.runInContext(runtime, context);564 vm.runInContext("i18n = I18n();", context);565 context.i18n.translator = translator;566 context.i18n.language = 'en-US';567 assert.equal(vm.runInContext(result.code, context), "Are you sure you want to delete this message?");568 });569 it('en-US', function () {570 var result = babel.transformFileSync("./en-US.js", {571 plugins: [require('..')]572 });573 var n = 3;574 var context = { n: n, console: console };575 vm.createContext(context);576 vm.runInContext(runtime, context);577 vm.runInContext("i18n = I18n();", context);578 context.i18n.translator = translator;579 context.i18n.language = 'en-US';580 assert.equal(vm.runInContext(result.code, context), `${n} todos left`);581 n = 1;582 context.n = n;583 assert.equal(vm.runInContext(result.code, context), `${n} todo left`);584 });585 describe('untranslated', function () {586 it('string literal', function () {587 var result = babel.transformFileSync("./untranslated.StringLiteral.js", {588 plugins: [require('..')]589 });590 var context = {};591 vm.createContext(context);592 vm.runInContext(runtime, context);593 vm.runInContext("i18n = I18n();", context);594 context.i18n.translator = translator;595 context.i18n.language = 'en-US';596 assert.equal(vm.runInContext(result.code, context), "ä¼");597 });598 it('template literal', function () {599 var result = babel.transformFileSync("./untranslated.TemplateLiteral.js", {600 plugins: [require('..')]601 });602 var a = "好";603 var context = { a: a };604 vm.createContext(context);605 vm.runInContext(runtime, context);606 vm.runInContext("i18n = I18n();", context);607 context.i18n.translator = translator;608 context.i18n.language = 'en-US';609 assert.equal(vm.runInContext(result.code, context), `${a}ä¼`);610 });611 it('jsx element', function () {612 var result = babel.transformFileSync("./untranslated.JSXElement.js", {613 presets: [require('@babel/preset-react')],614 plugins: [require('..')]615 });616 var a = "好";617 var context = {618 React: React,619 a: a620 };621 vm.createContext(context);622 vm.runInContext(runtime, context);623 vm.runInContext("i18n = I18n(); i18n.React = React;", context);624 context.i18n.translator = translator;625 context.i18n.language = 'en-US';626 assert.deepEqual(627 vm.runInContext(result.code, context),628 React.createElement("div", {}, [629 "", a, "ä¼"630 ])631 );632 });633 it('{}{}', function () {634 var result = babel.transformFileSync("./untranslated.{}{}.js", {635 plugins: [require('..')]636 });637 var a = "好", b = "æ¯";638 var context = { a: a, b: b };639 vm.createContext(context);640 vm.runInContext(runtime, context);641 vm.runInContext("i18n = I18n();", context);642 context.i18n.translator = translator;643 context.i18n.language = 'en-US';644 assert.equal(vm.runInContext(result.code, context), `${a}ä¼${b}ä¼`);645 });646 });647 it('zh-TW', function () {648 var result = babel.transformFileSync("./StringLiteral.js", {649 plugins: [require('..')]650 });651 var context = {};652 vm.createContext(context);653 vm.runInContext(runtime, context);654 vm.runInContext("i18n = I18n();", context);655 context.i18n.translator = translator;656 context.i18n.language = 'zh-TW';657 assert.equal(vm.runInContext(result.code, context), require('chinese-conv').tify("ç¡®å®"));658 });659 describe('error', function () {660 describe('index out of bound', function () {661 it('template literal', function () {662 var result = babel.transformFileSync("./error.indexOutOfBound.TemplateLiteral.js", {663 plugins: [require('..')]664 });665 var n = 3;666 var context = { n: n };667 vm.createContext(context);668 vm.runInContext(runtime, context);669 vm.runInContext("i18n = I18n();", context);670 context.i18n.translator = translator;671 context.i18n.language = 'en-US';672 assert.throws(() => {673 vm.runInContext(result.code, context);674 }, context.i18n.IndexOutOfBound);675 });676 it('jsx element', function () {677 var result = babel.transformFileSync("./error.indexOutOfBound.JSXElement.js", {678 presets: [require('@babel/preset-react')],679 plugins: [require('..')],680 parserOpts: { plugins: ['jsx'] }681 });682 var context = {683 React: React,684 Icon: Icon685 };686 vm.createContext(context);687 vm.runInContext(runtime, context);688 vm.runInContext("i18n = I18n(); i18n.React = React;", context);689 context.i18n.translator = translator;690 context.i18n.language = 'en-US';691 assert.throws(() => {692 vm.runInContext(result.code, context);693 }, context.i18n.IndexOutOfBound);694 });695 it('jsx fragment', function () {696 var result = babel.transformFileSync("./error.indexOutOfBound.JSXFragment.js", {697 presets: [require('@babel/preset-react')],698 plugins: [require('..')],699 parserOpts: { plugins: ['jsx'] }700 });701 var context = {702 React: React,703 Icon: Icon704 };705 vm.createContext(context);706 vm.runInContext(runtime, context);707 vm.runInContext("i18n = I18n(); i18n.React = React;", context);708 context.i18n.translator = translator;709 context.i18n.language = 'en-US';710 assert.throws(() => {711 vm.runInContext(result.code, context);712 }, context.i18n.IndexOutOfBound);713 });714 });715 it('missing quantity', function () {716 var result = babel.transformFileSync("./error.missingQuantity.js", {717 plugins: [require('..')]718 });719 var n = 3;720 var context = { n: n };721 vm.createContext(context);722 vm.runInContext(runtime, context);723 vm.runInContext("i18n = I18n();", context);724 context.i18n.translator = translator;725 context.i18n.language = 'en-US';726 assert.throws(() => {727 vm.runInContext(result.code, context);728 }, context.i18n.MissingQuantity);729 });730 it('missing ordinal', function () {731 var result = babel.transformFileSync("./error.missingOrdinal.js", {732 plugins: [require('..')]733 });734 var n = 3;735 var context = { n: n };736 vm.createContext(context);737 vm.runInContext(runtime, context);738 vm.runInContext("i18n = I18n();", context);739 context.i18n.translator = translator;740 context.i18n.language = 'en-US';741 assert.throws(() => {742 vm.runInContext(result.code, context);743 }, context.i18n.MissingOrdinal);744 });745 });746 it('include', function () {747 var result = babel.transformFileSync("./StringLiteral.mjs", {748 plugins: [require('..')]749 });750 assert.equal(result.code, '"ç¡®å®";');751 });752 it('exclude', function () {753 var result = babel.transformFileSync("./exclude.js", {754 plugins: [require('..')]755 });756 assert.equal(result.code, '"ç¡®å®";');757 });...
score_test.js
Source:score_test.js
1/*2 Copyright 2019 by Quopt IT Services BV3 You may obtain a copy of the License at4 https://raw.githubusercontent.com/Quopt/ITR-webclient/master/LICENSE5 Unless required by applicable law or agreed to in writing, software6 distributed under the License is distributed on an "AS IS" BASIS,7 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.8 See the License for the specific language governing permissions and9 limitations under the License.10 This nodejs program takes the following parameters11 action=scoretest12 testid=id of the test to score13 candidate=reference id of the candidate14 user_id=user_id of the user (guid) logged in15 access_token=security token of the user logged in16 basedir=folder where the client side information is stored17*/18const vm = require('vm');19const process = require('process');20const fs = require("fs");21const path = require('path');22// first parse the command line parameters23let candidate="";24let basedir="";25let datadir="";26let norm1="";27let norm2="";28let norm3="";29let par_found_count=0;30// check if we have sufficient parameters to run31let commandline_args = process.argv.slice(2);32let current_arg = "";33for (let i=0; i < commandline_args.length; i++) {34 try {35 current_arg = commandline_args[i];36 current_arg = current_arg.split('=');37 switch (current_arg[0]) {38 case 'candidate' : candidate=current_arg[1]; break;39 case 'norm1' : norm1=current_arg[1]; break;40 case 'norm2' : norm2=current_arg[1]; break;41 case 'norm3' : norm3=current_arg[1]; break;42 case 'basedir' : basedir=current_arg[1]; break;43 case 'datadir' : datadir=current_arg[1]; break;44 }45 if (current_arg[1].trim() != "") par_found_count++;46 } catch (err) {}47}48if (par_found_count != 6) {49 console.log(`Incorrect parameters found. This nodejs program takes the following parameters 50 candidate=reference id of the candidate51 norm1=uuid of the first norm to apply52 norm2=uuid of the second norm to apply53 norm3=uuid of the third norm to apply54 datadir=folder where the in, test and out files are or will be stored55 basedir=folder where the client side information is stored`);56 process.exit(9);57}58const context={};59vm.createContext(context);60// read the javascript files from the basedir and add them to the context61var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSBattery.js'), 'utf8'); vm.runInContext(data, context);62var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSCandidate.js'), 'utf8'); vm.runInContext(data, context);63var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSCandidateSession.js'), 'utf8'); vm.runInContext(data, context);64var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSCompanies.js'), 'utf8'); vm.runInContext(data, context);65var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSCreditUsages.js'), 'utf8'); vm.runInContext(data, context);66var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSGraph.js'), 'utf8'); vm.runInContext(data, context);67var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSReport.js'), 'utf8'); vm.runInContext(data, context);68var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSScript.js'), 'utf8'); vm.runInContext(data, context);69var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSTest.js'), 'utf8'); vm.runInContext(data, context);70var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSUsers.js'), 'utf8'); vm.runInContext(data, context);71var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'DataModel', 'ITSScreenTemplates.js'), 'utf8'); vm.runInContext(data, context);72var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITSActions.js'), 'utf8'); vm.runInContext(data, context);73var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITSControllers.js'), 'utf8'); vm.runInContext(data, context);74var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITSHelpers.js'), 'utf8'); vm.runInContext(data, context);75var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITSMessageBus.js'), 'utf8'); vm.runInContext(data, context);76var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITSStatistics.js'), 'utf8'); vm.runInContext(data, context);77var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITSTranslate.js'), 'utf8'); vm.runInContext(data, context);78var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'ITS_UI.js'), 'utf8'); vm.runInContext(data, context);79var data = fs.readFileSync(path.join(basedir, 'ITSScript', 'Support', 'simple-statistics.js'), 'utf8'); vm.runInContext(data, context);80var data = fs.readFileSync(path.join(basedir, 'js', 'datejs', 'date-en-029.js'), 'utf8'); vm.runInContext(data, context);81var data = `82 ITSInstance = {}83 ITSInstance.ID = newGuid();84 ITSInstance.companies = new ITSCompanies(ITSInstance);85 ITSInstance.users = new ITSUsers(ITSInstance);86 ITSInstance.tests = new ITSTests(ITSInstance);87 ITSInstance.candidates = new ITSCandidates(ITSInstance);88 ITSInstance.candidateSessions = new ITSCandidateSessions(ITSInstance);89 ITSInstance.batteries = new ITSBatteries(ITSInstance);90 ITSInstance.screenTemplates = new ITSScreenTemplates(ITSInstance);91 ITSInstance.reports = new ITSReports(ITSInstance);92 ITSInstance.graph = new ITSGraph(ITSInstance,ITSInstance);93 ITSInstance.translator = new ITSTranslator(ITSInstance);94 ITSInstance.hook = {};95 ITSInstance.MessageBus = new ITSMessageBus();96 ITSLanguage="en";97`;98vm.runInContext(data, context);99// now load the test definition in the context100var test_definition = fs.readFileSync(path.join(datadir, candidate + '.test'), 'utf8');101var test_data = fs.readFileSync(path.join(datadir, candidate + '.in'), 'utf8');102context.test_definition = test_definition;103//console.log(test_data);104context.test_data = JSON.parse(test_data);105context.norm1 = norm1;106context.norm2 = norm2;107context.norm3 = norm3;108// prepare test definition109vm.runInContext('temp_test = ITSInstance.tests.addNewTest();', context);110vm.runInContext('temp_scores = {};', context);111vm.runInContext('ITSJSONLoad(temp_test, test_definition, temp_test, ITSInstance, \'ITSTest\');', context);112// prepare dummy session, sessiontest and candidate113vm.runInContext('temp_session = ITSInstance.candidateSessions.newCandidateSession();', context);114vm.runInContext('temp_session_test = temp_session.newCandidateSessionTest(temp_test);', context);115vm.runInContext('temp_candidate = ITSInstance.candidates.newCandidate();', context);116// score test ITSTest.prototype.scoreTest = function (session, sessionTest, candidate, results, scores, ITSInstance)117vm.runInContext('temp_test.scoreTest(temp_session,temp_session_test,temp_candidate,test_data, temp_scores , ITSInstance)', context);118vm.runInContext('norm1index = temp_test.findNormById(norm1);', context);119vm.runInContext('norm2index = temp_test.findNormById(norm2);', context);120vm.runInContext('norm3index = temp_test.findNormById(norm3);', context);121if (norm1 != "") {122 vm.runInContext('temp_test.norms[norm1index].normTest(temp_session,temp_session_test,temp_candidate,test_data, temp_scores , ITSInstance,1)', context);123}124if (norm2 != "") {125 vm.runInContext('temp_test.norms[norm2index].normTest(temp_session,temp_session_test,temp_candidate,test_data, temp_scores , ITSInstance,2)', context);126}127if (norm3 != "") {128 vm.runInContext('temp_test.norms[norm3index].normTest(temp_session,temp_session_test,temp_candidate,test_data, temp_scores , ITSInstance,3)', context);129}130//console.log(context.temp_scores);//, context.temp_test.scales[1]);131//console.log(context.norm2, context.norm2index)132vm.runInContext('X = temp_test.norms[norm2index].findNormColumnsWithScaleID(temp_test.scales[1].id);',context);133//console.log(context.X, context.X.normColumnValues.length, context.temp_scores["__"+context.temp_test.scales[1].id]);134fs.writeFileSync(path.join(datadir, candidate + '.out'), JSON.stringify(context.temp_scores), 'utf8')135// now rewrite the in file with the id's of the questions so the session can be properly loaded in the ITS later136var i, keys = Object.getOwnPropertyNames(context.test_data);137for (i = 0; i < keys.length; i += 1) {138 //console.log( keys[i], context.test_data[keys[i]] );139 vm.runInContext('temp_screen = temp_test.findScreenByName("'+keys[i]+'");', context);140 if (typeof context.temp_screen != "undefined") {141 //console.log(context.temp_screen.varName, context.temp_screen.id);142 context.test_data["__"+context.temp_screen.id] = context.test_data[keys[i]];143 context.find_more = context.test_data[keys[i]];144 var j, keys_more = Object.getOwnPropertyNames(context.find_more);145 for (j = 0; j < keys_more.length; j += 1) {146 vm.runInContext('temp_screen_component = temp_screen.findComponentByComponentName("'+keys_more[j]+'");', context);147 if (typeof context.temp_screen_component != "undefined") {148 context.test_data["__"+context.temp_screen.id]["__"+context.temp_screen_component.id] = context.test_data[keys[i]][keys_more[j]];149 }150 }151 // temp_screen.findComponentByComponentName152 }153}...
vm.js
Source:vm.js
1var test = require('tape');2var vm = require('../');3test('vmRunInNewContext', function (t) {4 t.plan(6);5 6 t.equal(vm.runInNewContext('a + 5', { a : 100 }), 105);7 8 (function () {9 var vars = { x : 10 };10 t.equal(vm.runInNewContext('x++', vars), 10);11 t.equal(vars.x, 11);12 })();13 14 (function () {15 var vars = { x : 10 };16 t.equal(vm.runInNewContext('var y = 3; y + x++', vars), 13);17 t.equal(vars.x, 11);18 t.equal(vars.y, 3);19 })();20 21 t.end();22});23test('vmRunInContext', function (t) {24 t.plan(2);25 var context = vm.createContext({ foo: 1 });26 vm.runInContext('var x = 1', context);27 t.deepEqual(context, { foo: 1, x: 1 });28 vm.runInContext('var y = 1', context);29 t.deepEqual(context, { foo: 1, x: 1, y: 1 });...
Using AI Code Generation
1const { run } = require("qawolf");2const path = require("path");3const { run } = require("qawolf");4const path = require("path");5const browser = await run(path.join(__dirname, "test.html"));6const result = await browser.evaluate(() => {7 return 1 + 1;8});9console.log(result);10await browser.close();11 window.onload = () => {12 window.qawolf = {13 create: () => ({14 evaluate: () => 2,15 }),16 };17 };
Using AI Code Generation
1const { run } = require("qawolf");2const path = require("path");3const test = async () => {4 const browser = await run(path.join(__dirname, "test.json"));5 await browser.close();6};7test();
Using AI Code Generation
1const { run } = require('qawolf');2run('test', async ({ page }) => {3const puppeteer = require('puppeteer');4const browser = await puppeteer.launch();5const page = await browser.newPage();6});7const puppeteer = require('puppeteer');8const browser = await puppeteer.launch();9const page = await browser.newPage();10});11const puppeteer = require('puppeteer');12const browser = await puppeteer.launch();13const page = await browser.newPage();14});15const puppeteer = require('puppeteer');16const browser = await puppeteer.launch();17const page = await browser.newPage();18});19const puppeteer = require('puppeteer');20const browser = await puppeteer.launch();21const page = await browser.newPage();22});23const puppeteer = require('puppeteer');24const browser = await puppeteer.launch();25const page = await browser.newPage();26});27const puppeteer = require('puppeteer');28const browser = await puppeteer.launch();29const page = await browser.newPage();30});31const puppeteer = require('puppeteer');32const browser = await puppeteer.launch();33const page = await browser.newPage();34});35const puppeteer = require('puppeteer');36const browser = await puppeteer.launch();37const page = await browser.newPage();38});39const puppeteer = require('puppeteer');40const browser = await puppeteer.launch();41const page = await browser.newPage();42});43const puppeteer = require('puppeteer');44const browser = await puppeteer.launch();45const page = await browser.newPage();46await page.goto('https
Using AI Code Generation
1const { chromium } = require('qawolf');2const { test, expect } = require('@playwright/test');3const path = require('path');4test.describe('Test', () => {5 let browser;6 let page;7 test.beforeAll(async () => {8 browser = await chromium.launch();9 });10 test.beforeEach(async () => {11 page = await browser.newPage();12 });13 test.afterAll(async () => {14 await browser.close();15 });16 test('test', async () => {17 const context = await browser.newContext();18 const page = await context.newPage();19 await page.click('input[name="q"]');20 await page.fill('input[name="q"]', 'test');21 await page.press('input[name="q"]', '
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!