How to use runnable.run method in ava

Best JavaScript code snippet using ava

runnable.spec.js

Source:runnable.spec.js Github

copy

Full Screen

...206 it('should not invoke the callback', function(done) {207 var spy = sinon.spy();208 var runnable = new Runnable('foo', spy);209 runnable.pending = true;210 runnable.run(function(err) {211 if (err) {212 return done(err);213 }214 expect(spy, 'was not called');215 done();216 });217 });218 });219 describe('when sync', function() {220 describe('without error', function() {221 it('should invoke the callback', function(done) {222 var spy = sinon.spy();223 var runnable = new Runnable('foo', spy);224 runnable.run(function(err) {225 if (err) {226 return done(err);227 }228 expect(spy, 'was called times', 1);229 done();230 });231 });232 });233 describe('when an exception is thrown', function() {234 it('should invoke the callback with error', function(done) {235 var stub = sinon.stub().throws('Error', 'fail');236 var runnable = new Runnable('foo', stub);237 runnable.run(function(err) {238 expect(err.message, 'to be', 'fail');239 expect(stub, 'was called');240 done();241 });242 });243 });244 describe('when an exception is thrown and is allowed to remain uncaught', function() {245 it('throws an error when it is allowed', function() {246 var stub = sinon.stub().throws('Error', 'fail');247 var runnable = new Runnable('foo', stub);248 runnable.allowUncaught = true;249 function fail() {250 runnable.run(function() {});251 }252 expect(fail, 'to throw', 'fail');253 });254 });255 });256 describe('when timeouts are disabled', function() {257 it('should not error with timeout', function(done) {258 var runnable = new Runnable('foo', function(done) {259 setTimeout(function() {260 setTimeout(done);261 }, 2);262 });263 runnable.timeout(1);264 runnable.enableTimeouts(false);265 runnable.run(function(err) {266 expect(err, 'to be falsy');267 done();268 });269 });270 });271 describe('when async', function() {272 describe('without error', function() {273 it('should invoke the callback', function(done) {274 var runnable = new Runnable('foo', function(done) {275 setTimeout(done);276 });277 runnable.run(function(err) {278 expect(err, 'to be falsy');279 done();280 });281 });282 });283 describe('when the callback is invoked several times', function() {284 describe('without an error', function() {285 it('should emit a single "error" event', function(done) {286 var callbackSpy = sinon.spy();287 var errorSpy = sinon.spy();288 var runnable = new Runnable('foo', function(done) {289 process.nextTick(done);290 setTimeout(done);291 setTimeout(done);292 setTimeout(done);293 });294 // XXX too many diff assertions and very flimsy assertion that this295 // event was only emitted once. think of a better way.296 runnable.on('error', errorSpy).on('error', function(err) {297 process.nextTick(function() {298 expect(errorSpy, 'was called times', 1);299 expect(err.message, 'to be', 'done() called multiple times');300 expect(callbackSpy, 'was called times', 1);301 done();302 });303 });304 runnable.run(callbackSpy);305 });306 });307 describe('with an error', function() {308 it('should emit a single "error" event', function(done) {309 var callbackSpy = sinon.spy();310 var errorSpy = sinon.spy();311 var runnable = new Runnable('foo', function(done) {312 done(new Error('fail'));313 setTimeout(done);314 done(new Error('fail'));315 setTimeout(done);316 setTimeout(done);317 });318 // XXX too many diff assertions and very flimsy assertion that this319 // event was only emitted once. think of a better way.320 runnable.on('error', errorSpy).on('error', function(err) {321 process.nextTick(function() {322 expect(errorSpy, 'was called times', 1);323 expect(324 err.message,325 'to be',326 "fail (and Mocha's done() called multiple times)"327 );328 expect(callbackSpy, 'was called times', 1);329 done();330 });331 });332 runnable.run(callbackSpy);333 });334 });335 });336 describe('when an exception is thrown', function() {337 it('should invoke the callback', function(done) {338 var runnable = new Runnable(339 'foo',340 sinon.stub().throws('Error', 'fail')341 );342 runnable.run(function(err) {343 expect(err.message, 'to be', 'fail');344 done();345 });346 });347 it('should not throw its own exception if passed a non-object', function(done) {348 var runnable = new Runnable('foo', function(done) {349 /* eslint no-throw-literal: off */350 throw null;351 });352 runnable.run(function(err) {353 expect(err.message, 'to be', Runnable.toValueOrError().message);354 done();355 });356 });357 });358 describe('when an exception is thrown and is allowed to remain uncaught', function() {359 it('throws an error when it is allowed', function(done) {360 var runnable = new Runnable('foo', function(done) {361 throw new Error('fail');362 });363 runnable.allowUncaught = true;364 function fail() {365 runnable.run(function() {});366 }367 expect(fail, 'to throw', 'fail');368 done();369 });370 });371 describe('when an error is passed', function() {372 it('should invoke the callback', function(done) {373 var runnable = new Runnable('foo', function(done) {374 done(new Error('fail'));375 });376 runnable.run(function(err) {377 expect(err.message, 'to be', 'fail');378 done();379 });380 });381 });382 describe('when done() is invoked with a non-Error object', function() {383 it('should invoke the callback', function(done) {384 var runnable = new Runnable('foo', function(done) {385 done({386 error: 'Test error'387 });388 });389 runnable.run(function(err) {390 expect(391 err.message,392 'to be',393 'done() invoked with non-Error: {"error":"Test error"}'394 );395 done();396 });397 });398 });399 describe('when done() is invoked with a string', function() {400 it('should invoke the callback', function(done) {401 var runnable = new Runnable('foo', function(done) {402 done('Test error');403 });404 runnable.run(function(err) {405 expect(406 err.message,407 'to be',408 'done() invoked with non-Error: Test error'409 );410 done();411 });412 });413 });414 it('should allow updating the timeout', function(done) {415 var spy = sinon.spy();416 var runnable = new Runnable('foo', function(done) {417 setTimeout(spy, 1);418 setTimeout(spy, 100);419 });420 runnable.timeout(50);421 runnable.run(function(err) {422 expect(err, 'to be truthy');423 expect(spy, 'was called times', 1);424 done();425 });426 });427 it('should allow a timeout of 0');428 });429 describe('when fn returns a promise', function() {430 describe('when the promise is fulfilled with no value', function() {431 var fulfilledPromise = {432 then: function(fulfilled) {433 setTimeout(fulfilled);434 }435 };436 it('should invoke the callback', function(done) {437 var runnable = new Runnable('foo', function() {438 return fulfilledPromise;439 });440 runnable.run(function(err) {441 expect(err, 'to be falsy');442 done();443 });444 });445 });446 describe('when the promise is fulfilled with a value', function() {447 var fulfilledPromise = {448 then: function(fulfilled, rejected) {449 setTimeout(function() {450 fulfilled({});451 });452 }453 };454 it('should invoke the callback', function(done) {455 var runnable = new Runnable('foo', function() {456 return fulfilledPromise;457 });458 runnable.run(function(err) {459 expect(err, 'to be falsy');460 done();461 });462 });463 });464 describe('when the promise is rejected', function() {465 var expectedErr = new Error('fail');466 var rejectedPromise = {467 then: function(fulfilled, rejected) {468 setTimeout(function() {469 rejected(expectedErr);470 });471 }472 };473 it('should invoke the callback', function(done) {474 var runnable = new Runnable('foo', function() {475 return rejectedPromise;476 });477 runnable.run(function(err) {478 expect(err, 'to be', expectedErr);479 done();480 });481 });482 });483 describe('when the promise is rejected without a reason', function() {484 var expectedErr = new Error('Promise rejected with no or falsy reason');485 var rejectedPromise = {486 then: function(fulfilled, rejected) {487 setTimeout(function() {488 rejected();489 });490 }491 };492 it('should invoke the callback', function(done) {493 var runnable = new Runnable('foo', function() {494 return rejectedPromise;495 });496 runnable.run(function(err) {497 expect(err.message, 'to be', expectedErr.message);498 done();499 });500 });501 });502 describe('when the promise takes too long to settle', function() {503 var foreverPendingPromise = {504 then: function() {}505 };506 it('should throw the timeout error', function(done) {507 var runnable = new Runnable('foo', function() {508 return foreverPendingPromise;509 });510 runnable.file = '/some/path';511 runnable.timeout(10);512 runnable.run(function(err) {513 expect(514 err.message,515 'to match',516 /Timeout of 10ms exceeded.*\(\/some\/path\)$/517 );518 done();519 });520 });521 });522 });523 describe('when fn returns a non-promise', function() {524 it('should invoke the callback', function(done) {525 var runnable = new Runnable('foo', function() {526 return {527 then: 'i ran my tests'528 };529 });530 runnable.run(done);531 });532 });533 describe('if timed-out', function() {534 it('should ignore call to `done` and not execute callback again', function(done) {535 var runnable = new Runnable('foo', function(done) {536 setTimeout(done, 20);537 });538 runnable.timeout(10);539 runnable.run(function(err) {540 expect(err.message, 'to match', /^Timeout of 10ms/);541 // timedOut is set *after* this callback is executed542 process.nextTick(function() {543 expect(runnable.timedOut, 'to be truthy');544 done();545 });546 });547 });548 });549 describe('if async', function() {550 it('this.skip() should call callback with Pending', function(done) {551 var runnable = new Runnable('foo', function(done) {552 // normally "this" but it gets around having to muck with a context553 runnable.skip();554 });555 runnable.run(function(err) {556 expect(err.constructor, 'to be', Pending);557 done();558 });559 });560 it('this.skip() should halt synchronous execution', function(done) {561 var aborted = true;562 var runnable = new Runnable('foo', function(done) {563 // normally "this" but it gets around having to muck with a context564 runnable.skip();565 aborted = false;566 });567 runnable.run(function() {568 expect(aborted, 'to be true');569 done();570 });571 });572 });573 });574 describe('#isFailed()', function() {575 it('should return `true` if test has not failed', function() {576 var runnable = new Runnable('foo', function() {});577 // runner sets the state578 runnable.run(function() {579 expect(runnable.isFailed(), 'to be false');580 });581 });582 it('should return `true` if test has failed', function() {583 var runnable = new Runnable('foo', function() {});584 // runner sets the state585 runnable.state = STATE_FAILED;586 runnable.run(function() {587 expect(runnable.isFailed(), 'to be false');588 });589 });590 it('should return `false` if test is pending', function() {591 var runnable = new Runnable('foo', function() {});592 // runner sets the state593 runnable.isPending = function() {594 return true;595 };596 runnable.run(function() {597 expect(runnable.isFailed(), 'to be false');598 });599 });600 });601 describe('#resetTimeout()', function() {602 it('should not time out if timeouts disabled after reset', function(done) {603 var runnable = new Runnable('foo', function() {});604 runnable.timeout(10);605 runnable.resetTimeout();606 runnable.enableTimeouts(false);607 setTimeout(function() {608 expect(runnable.timedOut, 'to be', false);609 done();610 }, 20);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1runnable.run("test", function (err, result) {2 if (err) {3 console.log("error", err);4 } else {5 console.log("result", result);6 }7});

Full Screen

Using AI Code Generation

copy

Full Screen

1require(['avalon','runnable'], function(avalon,runnable) {2 var vm = avalon.define({3 show: function() {4 alert("hello");5 }6 });7 avalon.scan();8 runnable.run("test");9});10#### avalon.runnable.run(id)11#### avalon.runnable.runAll()

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const myScript = require('./myScript');3test('myScript', t => {4 const input = 'my input';5 const expectedOutput = 'my expected output';6 t.is(myScript(input), expectedOutput);7});8module.exports = (input) => {9 return 'my expected output';10}

Full Screen

Using AI Code Generation

copy

Full Screen

1var runnables = require('runnables');2var runnable = runnables.getRunnable('JavaScript');3runnable.run('console.log("Hello world");', function (err, result) {4});5var runnables = require('runnables');6var runnable = runnables.getRunnable('JavaScript');7runnable.run('console.log("Hello world");', function (err, result) {8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var runnable = require('runnable');2runnable.run('/path/to/avalon', 'test.js', ['arg1','arg2'],function(err, result) {3 if (err) {4 console.log('Error:', err);5 } else {6 console.log('Result:', result);7 }8});9var runnable = require('runnable');10runnable.run('/path/to/avalon', 'test.js', ['arg1','arg2'], {cwd: '/path/to/working/directory'}, function(err, result) {11 if (err) {12 console.log('Error:', err);13 } else {14 console.log('Result:', result);15 }16});17var runnable = require('runnable');18runnable.run('/path/to/avalon', 'test.js', ['arg1','arg2'], {cwd: '/path/to/working/directory', env: {AVALON_HOME: '/path/to/avalon'}}, function(err, result) {19 if (err) {20 console.log('Error:', err);21 } else {22 console.log('Result:', result);23 }24});25var runnable = require('runnable');26runnable.run('/path/to/avalon', 'test.js', ['arg1','arg2'], {cwd: '/path/to/working/directory', env: {AVALON_HOME: '/path/to/avalon'}, timeout: 1000}, function(err, result) {27 if (err) {28 console.log('Error:', err);29 } else {30 console.log('Result:', result);31 }32});33### runnable.runSync(cmd, args, options)

Full Screen

Using AI Code Generation

copy

Full Screen

1const test = require('ava');2const {runnable} = require('runnable');3const {getSum} = require('./index.js');4test('getSum', t => {5 const sum = runnable.run(getSum, 1, 2);6 t.is(sum, 3);7});8exports.getSum = (a, b) => a + b;

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