How to use ava.run method in ava

Best JavaScript code snippet using ava

Trend_analysis.js

Source:Trend_analysis.js Github

copy

Full Screen

1Tools = JSON.parse(get_cookie("checkednodes"));2// console.log(Tools)3var begin = new Date($("#start", window.parent.document).val());4var end = new Date($("#end", window.parent.document).val());5var Result = [];6$.ajaxSetup({7 async: false //取消异步 8});9function get_cookie(Name) {10 var search = Name + "=" //查询检索的值11 var returnvalue = ""; //返回值12 if (parent.window.document.cookie.length > 0) {13 sd = parent.window.document.cookie.indexOf(search);14 if (sd != -1) {15 sd += search.length;16 end = parent.window.document.cookie.indexOf(";", sd);17 if (end == -1)18 end = parent.window.document.cookie.length;19 //unescape() 函数可对通过 escape() 编码的字符串进行解码。20 returnvalue = unescape(parent.window.document.cookie.substring(sd, end))21 }22 }23 return returnvalue;24}25var convertTime = function (date) {26 var timestamp = Date.parse(date);27 return timestamp / 1000;28};29function SortEff(Data) {30 var Eff = [];31 var Use = [];32 var On = [];33 var Name = [];34 var sumOn = 0;35 var sumOnline = 0;36 var sumAlarm = 0;37 var sumOffline = 0;38 var sumRun = 0;39 var sumWholetime = 0;40 var sumEffRatio = 0;41 var sumUseRatio = 0;42 var sumOnRatio = 0;43 var sumOnlineRatio = 0;44 var sumAlarmRatio = 0;45 var sumOfflineRatio = 0;46 Data.forEach(function (data, index) {47 Eff[index] = data.RunEff;48 Name[index] = data.MTNAME;49 Use[index] = data.UseRatio;50 On[index] = data.OnRatio;51 sumOn += data.OnTime;52 sumOnline += data.OnlineTime;53 sumAlarm += data.AlarmTime;54 sumOffline += data.OfflineTime;55 sumRun += data.RunTime56 sumWholetime += data.WholeTime;57 sumEffRatio += data.RunEff;58 sumUseRatio += data.UseRatio;59 sumOnRatio += data.OnRatio;60 sumOnlineRatio += data.OnlineRatio;61 sumAlarmRatio += data.AlarmRatio;62 sumOfflineRatio += data.OfflineRatio;63 });64 var monthRun = sumRun / sumOn;//总运行效率65 var monthUse = sumRun / sumWholetime;//总利用率66 var monthOn = sumOn / sumWholetime;//总开机率67 // maxEff = Math.max.apply(null, Eff); //最高效率68 // max_index = Eff.indexOf(maxEff); //最高效率索引69 // minEff = Math.min.apply(null, Eff); //最低效率70 // min_index = Eff.indexOf(minEff); //最低效率索引71 // maxUse = Math.max.apply(null, Use); //最高利用率72 // maxUse_index = Use.indexOf(maxUse); //最高利用率索引73 // minUse = Math.min.apply(null, Use); //最低利用率74 // minUse_index = Use.indexOf(minUse); //最低利用率索引75 // maxOn = Math.max.apply(null, On); //最高开机率76 // maxOn_index = On.indexOf(maxOn); //最高开机率索引77 // minOn = Math.min.apply(null, On); //最低开机率78 // minOn_index = On.indexOf(minOn); //最低开机率索引79 // avaEff = sumEffRatio / Data.length; //平均效率80 // avaUse = sumUseRatio / Data.length; //平均利用率、运行率81 // avaOn = sumOnRatio / Data.length; //平均开机率82 // avaOnline = sumOnlineRatio / Data.length; //平均空闲率83 // avaAlarm = sumAlarmRatio / Data.length; //平均报警率84 // avaOffline = sumOfflineRatio / Data.length; //平均关机率85 // //[0最高效率、1最高效率设备、2最低效率、3最低效率设备、4平均效率、5总运行时间、6总开机时间86 // //7最高利用率、8最高利用率设备、9最低利用率、10最低利用率设备、11平均利用率、12总自然时间、87 // //13最高利用率、14最高利用率设备、15最低利用率、16最低利用率设备、17平均开机、18总空闲、19总报警88 // //20总关机、21平均空闲、22平均报警、23平均关机 ]89 // return [maxEff, Name[max_index], minEff, Name[min_index], avaEff,90 // sumRun, sumOn, maxUse, Name[maxUse_index], minUse, Name[minUse_index], avaUse, sumWholetime,91 // maxOn, Name[maxOn_index], minOn, Name[minOn_index], avaOn, sumOnline,92 // sumAlarm, sumOffline, avaOnline, avaAlarm, avaOffline93 // ]94 return [monthRun, monthUse, monthOn];95};96var Static = function (mtdata) {97 length = mtdata.length;98 Runtime = 0;99 Onlinetime = 0;100 Alarmtime = 0;101 Offlinetime = 0;102 AlarmNum = 0;103 Wholetime = convertTime((mtdata[length - 1]).ENDTIME) - convertTime(mtdata[0].BEGINTIME)104 mtdata.forEach(function (onedata, index) {105 if (mtdata[index].STATUS == "RUNNING") {106 Runtime += mtdata[index]["DURATION"]107 };108 if (mtdata[index].STATUS == "ALARM") {109 Alarmtime += mtdata[index]["DURATION"];110 AlarmNum += 1;111 };112 if (mtdata[index].STATUS == "ONLINE") {113 Onlinetime += mtdata[index]["DURATION"]114 };115 if (mtdata[index].STATUS == "OFFLINE") {116 Offlinetime += mtdata[index]["DURATION"]117 };118 });119 Runtime = Runtime / 3600.0;120 Onlinetime = Onlinetime / 3600.0;121 Alarmtime = Alarmtime / 3600.0;122 Offlinetime = Offlinetime / 3600.0;123 Wholetime = Wholetime / 3600.0;124 Ontime = Wholetime - Offlinetime;125 RunEff = Runtime / Ontime;126 UseRatio = Runtime / Wholetime;127 OnRatio = Ontime / Wholetime;128 RunRatio = Runtime / Wholetime;129 OnlineRatio = Onlinetime / Wholetime;130 AlarmRatio = Alarmtime / Wholetime;131 OfflineRatio = Offlinetime / Wholetime;132 OnRatio = Ontime / Wholetime;133 return {134 "MTID": mtdata[0].MTID,135 "RunTime": Runtime,136 "OnTime": Ontime,137 "OnlineTime": Onlinetime,138 "AlarmTime": Alarmtime,139 "OfflineTime": Offlinetime,140 "RunEff": RunEff,141 "WholeTime": Wholetime,142 "UseRatio": UseRatio,143 "OnRatio": OnRatio,144 "RunRatio": RunRatio,145 "OnlineRatio": OnlineRatio,146 "AlarmRatio": AlarmRatio,147 "OfflineRatio": OfflineRatio,148 "OnRatio": OnRatio,149 "AlarmNum": AlarmNum150 };151};152function GenDatelable(begin, end) {153 yearBegin = begin.getFullYear();154 yearEnd = end.getFullYear();155 monthBegin = begin.getMonth();156 monthEnd = end.getMonth();157 var month = monthBegin;158 var year = yearBegin;159 var date = [];160 if (yearBegin == yearEnd) {161 monthNum = monthEnd - monthBegin + 1;162 } else {163 monthNum = (12 - monthBegin) + (yearEnd - yearBegin - 1) * 12 + monthEnd + 1;164 };165 for (var index = 0; index < monthNum - 1; index++) {166 month = month + 1;167 if (month > 12) {168 year = year + 1;169 month = month - 12;170 }171 date[index] = String(year) + '-' + String(month);172 };173 return date;174};175function GenpayloadDate(begin, end) {176 var begintime = [];177 var endtime = [];178 Datelable = GenDatelable(begin, end);179 // console.log(Datelable);180 for (var index = 0; index < Datelable.length; index++) {181 if (index == 0) {182 begintime[index] = begin;183 } else begintime[index] = new Date(Datelable[index]);184 if (index == Datelable.length - 1) {185 endtime[index] = end;186 } else endtime[index] = new Date(Datelable[index + 1]);187 }188 return [Datelable, begintime, endtime];189};190function Caculate(begin, end) {191 var Begin = [];192 var End = [];193 var ObjRun = [];194 var ObjUse = [];195 var ObjOn = [];196 var nodataNodes = [];197 var mtools = [];198 [Datelable, Begin, End] = GenpayloadDate(begin, end);199 for (var IND = 0; IND < Datelable.length; IND++) {200 $.get("/api/CACULATE/" + Datelable[IND], function (data, resp) {201 // console.log("/api/CACULATE/" + Datelable[IND])202 if (resp == "success" && data.length != 0) {203 var ObjRunMonth = { "Month": "", "AvaRun": "" };204 var ObjUseMonth = { "Month": "", "AvaUse": "" };205 var ObjOnMonth = { "Month": "", "AvaOn": "" };206 ObjRunMonth.Month = data.MONTHLABLE;207 ObjRunMonth.AvaRun = data.RUNRATIO;208 ObjUseMonth.Month = data.MONTHLABLE;209 ObjUseMonth.AvaUse = data.USERATIO;210 ObjOnMonth.Month = data.MONTHLABLE;211 ObjOnMonth.AvaOn = data.ONRATIO;212 ObjRun.push(ObjRunMonth);213 ObjUse.push(ObjUseMonth);214 ObjOn.push(ObjOnMonth);215 } else {216 for (var index = 0; index < Tools.length; index++) {217 mtools.push(Tools[index].id);218 }219 var payload = {220 "MTID": JSON.stringify(mtools),221 'BEGINTIME': Begin[IND],222 'ENDTIME': End[IND],223 }224 $.post("/api/STATICS", payload, function (data, resp) {225 if (resp == "success") {226 Result = data.RESULT;227 nodataNodes = data.nodataNodes;228 // if (nodataNodes.length != 0) {229 // message = "";230 // nodataNodes.forEach(function (node) {231 // message += node + ","232 // })233 // alert("查询不到" + message + "设备数据,只显示可查询到的数据或请重新选择查询条件(设备列表/时间区间)");234 // }235 Eff_result = SortEff(Result);236 // console.log(Eff_result)237 var ObjRunMonth = { "Month": "", "AvaRun": "" };238 var ObjUseMonth = { "Month": "", "AvaUse": "" };239 var ObjOnMonth = { "Month": "", "AvaOn": "" };240 ObjRunMonth.Month = Datelable[IND];241 ObjRunMonth.AvaRun = Eff_result[0];242 ObjUseMonth.Month = Datelable[IND];243 ObjUseMonth.AvaUse = Eff_result[1];244 ObjOnMonth.Month = Datelable[IND];245 ObjOnMonth.AvaOn = Eff_result[2];246 // console.log(ObjRunMonth);247 ObjRun.push(ObjRunMonth);248 ObjUse.push(ObjUseMonth);249 ObjOn.push(ObjOnMonth);250 var Monthdata = {251 "MONTHLABLE": Datelable[IND],252 "USERATIO": ObjUseMonth.AvaUse,253 "RUNRATIO": ObjRunMonth.AvaRun,254 "ONRATIO": ObjOnMonth.AvaOn255 };256 $.post("/api/CACULATE/Create", Monthdata, function (data, resp) {257 if (resp == "success") {258 // console.log("save successfuly")259 }260 })261 } else {262 alert("请检查查询条件后重试!")263 window.stop();264 }265 });266 }267 })268 };269 // console.log(ObjRun)270 $("#chartTrend1").kendoChart({271 dataSource: ObjRun,272 title: {273 text: "设备运行效率"274 },275 legend: {276 position: "top",277 visible: false278 },279 series: [{280 type: "column",281 field: "AvaRun",282 name: "柱状图"283 },284 {285 type: "line",286 field: "AvaRun",287 name: "折线图"288 }289 ],290 categoryAxis: {291 field: "Month",292 majorGridLines: {293 visible: false294 },295 line: {296 visible: false297 }298 },299 valueAxis: {300 line: {301 visible: false302 },303 labels: {304 format: "{0:p1}"305 },306 minorGridLines: {307 visible: true308 },309 axisCrossingValue: 0310 },311 tooltip: {312 visible: true,313 format: "Value:{0:p1}",314 // template: "#= series.name #: #= value #"315 }316 });317 $("#chartTrend2").kendoChart({318 dataSource: ObjUse,319 title: {320 text: "设备总利用率"321 },322 legend: {323 position: "top",324 visible: false325 },326 series: [{327 type: "column",328 field: "AvaUse",329 name: "柱状图"330 },331 {332 type: "line",333 field: "AvaUse",334 name: "折线图"335 }336 ],337 categoryAxis: {338 field: "Month",339 majorGridLines: {340 visible: false341 },342 line: {343 visible: false344 }345 },346 valueAxis: {347 line: {348 visible: false349 },350 labels: {351 format: "{0:p1}"352 },353 minorGridLines: {354 visible: true355 },356 axisCrossingValue: 0357 },358 tooltip: {359 visible: true,360 format: "Value:{0:p1}",361 // template: "#= series.name #: #= value #"362 }363 });364 $("#chartTrend3").kendoChart({365 dataSource: ObjOn,366 title: {367 text: "设备总开机率"368 },369 legend: {370 position: "top",371 visible: false372 },373 series: [{374 type: "column",375 field: "AvaOn",376 name: "柱状图"377 },378 {379 type: "line",380 field: "AvaOn",381 name: "折线图"382 }383 ],384 categoryAxis: {385 field: "Month",386 majorGridLines: {387 visible: false388 },389 line: {390 visible: false391 }392 },393 valueAxis: {394 line: {395 visible: false396 },397 labels: {398 format: "{0:p1}"399 },400 minorGridLines: {401 visible: true402 },403 axisCrossingValue: 0404 },405 tooltip: {406 visible: true,407 format: "Value:{0:p1}",408 // template: "#= series.name #: #= value #"409 }410 });411};412$(document).ready(function () {413 Caculate(begin, end);414 // Eff_result=SortEff(Result);...

Full Screen

Full Screen

AircraftCommander.spec.js

Source:AircraftCommander.spec.js Github

copy

Full Screen

1import ava from 'ava';2import sinon from 'sinon';3import AircraftCommander from '../../src/assets/scripts/client/aircraft/AircraftCommander';4import AircraftModel from '../../src/assets/scripts/client/aircraft/AircraftModel';5import {6 AIRCRAFT_MOCK_BASE,7 AIRCRAFT_MOCK_WITH_NE_HEADING,8 AIRCRAFT_MOCK_WITH_NORTH_HEADING,9 AIRCRAFT_MOCK_WITH_POSITIVE_SW_HEADING,10 AIRCRAFT_MOCK_WITH_NEGATIVE_SW_HEADING,11 RUN_SAY_HEADING_RESULT_NE,12 RUN_SAY_HEADING_RESULT_NORTH,13 RUN_SAY_HEADING_RESULT_SW,14 SQUAWK_RESPONSE_SUCCESS,15 SQUAWK_RESPONSE_FAILURE16} from './_mocks/aircraftCommanderMocks';17const sandbox = sinon.createSandbox();18let onChangeTransponderCodeFixture;19let findAircraftByIdFixture;20ava.beforeEach(() => {21 onChangeTransponderCodeFixture = () => true;22 findAircraftByIdFixture = () => new AircraftModel(AIRCRAFT_MOCK_WITH_NORTH_HEADING);23});24ava.afterEach(() => {25 sandbox.restore();26});27ava('.runSayHeading() returns correct when heading north', (t) => {28 const commander = new AircraftCommander(onChangeTransponderCodeFixture, findAircraftByIdFixture);29 const aircraft = new AircraftModel(AIRCRAFT_MOCK_WITH_NORTH_HEADING);30 const result = commander.runSayHeading(aircraft);31 t.deepEqual(result, RUN_SAY_HEADING_RESULT_NORTH);32});33ava('.runSayHeading() returns correct when heading has two digits', (t) => {34 const commander = new AircraftCommander(onChangeTransponderCodeFixture, findAircraftByIdFixture);35 const aircraft = new AircraftModel(AIRCRAFT_MOCK_WITH_NE_HEADING);36 const result = commander.runSayHeading(aircraft);37 t.deepEqual(result, RUN_SAY_HEADING_RESULT_NE);38});39ava('.runSayHeading() returns correct when heading is positive', (t) => {40 const commander = new AircraftCommander(onChangeTransponderCodeFixture, findAircraftByIdFixture);41 const aircraft = new AircraftModel(AIRCRAFT_MOCK_WITH_POSITIVE_SW_HEADING);42 const result = commander.runSayHeading(aircraft);43 t.deepEqual(result, RUN_SAY_HEADING_RESULT_SW);44});45ava('.runSayHeading() returns correct when heading is negative', (t) => {46 const commander = new AircraftCommander(onChangeTransponderCodeFixture, findAircraftByIdFixture);47 const aircraft = new AircraftModel(AIRCRAFT_MOCK_WITH_NEGATIVE_SW_HEADING);48 const result = commander.runSayHeading(aircraft);49 t.deepEqual(result, RUN_SAY_HEADING_RESULT_SW);50});51ava('.runSquawk() returns a success response when _onChangeTransponderCode() succeeds', (t) => {52 const commander = new AircraftCommander(onChangeTransponderCodeFixture, findAircraftByIdFixture);53 const aircraft = new AircraftModel(AIRCRAFT_MOCK_BASE);54 const result = commander.runSquawk(aircraft, ['3377']);55 t.deepEqual(result, SQUAWK_RESPONSE_SUCCESS);56});57ava('.runSquawk() returns a failure response when _onChangeTransponderCode() fails', (t) => {58 const commander = new AircraftCommander(onChangeTransponderCodeFixture, findAircraftByIdFixture);59 const aircraft = new AircraftModel(AIRCRAFT_MOCK_BASE);60 sandbox.stub(commander, '_onChangeTransponderCode').returns(false);61 const result = commander.runSquawk(aircraft, ['3377']);62 t.deepEqual(result, SQUAWK_RESPONSE_FAILURE);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const ava = require('ava');2const test = ava.test;3test('foo', t => {4 t.pass();5});6test('bar', async t => {7 const bar = Promise.resolve('bar');8 t.is(await bar, 'bar');9});10const test = require('ava');11test.serial('foo', t => {12 t.pass();13});14test('bar', t => {15 t.pass();16});17const test = require('ava');18test.cb('foo', t => {19 setTimeout(() => {20 t.pass();21 t.end();22 }, 1000);23});24test.cb('bar', t => {25 setTimeout(() => {26 t.pass();27 t.end();28 }, 2000);29});30const test = require('ava');31test.failing('foo', t => {32 t.fail();33});34test('bar', t => {35 t.pass();36});37const test = require('ava');38test.before(t => {39});40test.before(t => {41});42test.after('cleanup', t => {43});44test.after.always(t => {45});46test(t => {47});48const test = require('ava');49test.beforeEach(t => {50 t.context.data = generateUniqueData();51});52test(t => {53 t.is(t.context.data + 'bar', 'foobar');54});55const test = require('ava');56test.afterEach(t => {57});58test(t => {59 t.pass();60});61const test = require('ava');

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const request = require('supertest');3const app = require('../app');4test('GET /', async t => {5 const res = await request(app).get('/');6 t.is(res.status, 200);7 t.is(res.text, 'Hello World!');8});9test('GET /about', async t => {10 const res = await request(app).get('/about');11 t.is(res.status, 200);12 t.is(res.text, 'About Page');13});14test('GET /contact', async t => {15 const res = await request(app).get('/contact');16 t.is(res.status, 200);17 t.is(res.text, 'Contact Page');18});19test('GET /random', async t => {20 const res = await request(app).get('/random');21 t.is(res.status, 404);22 t.is(res.text, 'Page not found');23});24test('GET /random', async t => {25 const res = await request(app).get('/random');26 t.is(res.status, 404);27 t.is(res.text, 'Page not found');28});29test('GET /random', async t => {30 const res = await request(app).get('/random');31 t.is(res.status, 404);32 t.is(res.text, 'Page not found');33});34test('GET /random', async t => {35 const res = await request(app).get('/random');36 t.is(res.status, 404);37 t.is(res.text, 'Page not found');38});39test('GET /random', async t => {40 const res = await request(app).get('/random');41 t.is(res.status, 404);42 t.is(res.text, 'Page not found');43});44test('GET /random', async t => {45 const res = await request(app).get('/random');46 t.is(res.status, 404);47 t.is(res.text, 'Page not found');48});49test('GET /random', async t => {50 const res = await request(app).get('/random');51 t.is(res.status, 404);52 t.is(res.text, 'Page not found');53});54test('GET /random', async t => {55 const res = await request(app).get('/random');56 t.is(res.status, 404);57 t.is(res.text, 'Page not found');58});

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const mymodule = require('./mymodule');3test('foo', t => {4 t.pass();5});6test('bar', async t => {7 const bar = Promise.resolve('bar');8 t.is(await bar, 'bar');9});10test('mymodule', t => {11 t.is(mymodule(5), 10);12});13module.exports = function (n) {14 return n * 2;15};16const test = require('ava');17const assert = require('assert');18test('my passing test', () => {19 assert(1 === 1);20});21const test = require('ava');22const assert = require('assert');23test('my passing test', () => {24 assert.throws(function() {25 throw new Error('whoops');26 }, Error);27});

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var ava = require('ava');3var test = require('ava');4test('my passing test', t => {5 t.pass();6});7ava.run({8 files: [path.join(__dirname, 'test.js')]9});10var ava = require('ava');11var test = require('ava');12test('my passing test', t => {13 t.pass();14});15ava.run({16});17var ava = require('ava');18var test = require('ava');19test('my passing test', t => {20 t.pass();21});22ava.run({23});24var ava = require('ava');25var test = require('ava');26test('my passing test', t => {27 t.pass();28});29ava.run({30});31var ava = require('ava');32var test = require('ava');33test('my passing test', t => {34 t.pass();35});36ava.run({37});38var ava = require('ava');39var test = require('ava');40test('my passing test', t => {41 t.pass();42});43ava.run({44});45var ava = require('ava');46var test = require('ava');47test('my passing test', t => {48 t.pass();49});50ava.run({51});52var ava = require('ava');53var test = require('ava');54test('my passing test', t => {55 t.pass();56});57ava.run({58});59var ava = require('ava');60var test = require('ava');61test('my passing test', t => {62 t.pass();63});64ava.run({65});

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const { run } = require('ava');3const { resolve } = require('path');4async function runTests() {5 const files = [resolve(__dirname, 'test.js')];6 await run(files);7}8runTests();9### ava.run(files, [options])10Default: `process.cwd()`11- [ava](

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const ava = require('ava');3const { run } = require('ava');4const { test } = require('ava');5const { run } = require('ava');6const { test } = require('ava');7const { run } = require('ava');8const test = require('ava');9const ava = require('ava');10const { run } = require('ava');11const { test } = require('ava');12const { run } = require('ava');13const { test } = require('ava');14const { run } = require('ava');15const test = require('ava');16const ava = require('ava');17const { run } = require('ava');18const { test } = require('ava');19const { run } = require('ava');20const { test } = require('ava');21const { run } = require('ava');22const test = require('ava');23const ava = require('ava');24const { run } = require('ava');25const { test } = require('ava');26const { run } = require('ava');27const { test } = require('ava');28const { run } = require('ava');29const test = require('ava');30const ava = require('ava');31const { run } = require('ava');32const { test } = require('ava');33const { run } = require('ava');34const { test } = require('ava');35const { run } = require('ava');36test('m

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ava automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful