How to use ExitError method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

core-cli.test.js

Source:core-cli.test.js Github

copy

Full Screen

1"use strict";2const ValidationError = require("@lerna/validation-error");3const loggingOutput = require("@lerna-test/logging-output");4const initFixture = require("@lerna-test/init-fixture")(__dirname);5const coreCLI = require("..");6function prepare(cwd) {7 // DRY setup for yargs instance8 return coreCLI([], cwd)9 .exitProcess(false)10 .detectLocale(false)11 .showHelpOnFail(false)12 .wrap(null);13}14async function parse(instance, args) {15 return new Promise((resolve, reject) => {16 instance.parse(args, (exitError, argv, output) => {17 if (exitError) {18 // parity with synchronous errors19 Object.assign(exitError, { argv, output });20 reject(exitError);21 } else {22 resolve({ exitError, argv, output });23 }24 });25 });26}27describe("core-cli", () => {28 let cwd;29 beforeAll(async () => {30 cwd = await initFixture("toposort");31 });32 it("provides global options", async () => {33 const cli = prepare(cwd);34 cli.command("test-cmd", "will pass");35 const { argv } = await parse(cli, [36 "test-cmd",37 "--loglevel=warn",38 "--concurrency=10",39 "--no-progress",40 "--no-sort",41 "--max-buffer=1024",42 ]);43 expect(argv).toMatchObject({44 loglevel: "warn",45 concurrency: 10,46 progress: false,47 sort: false,48 maxBuffer: 1024,49 });50 });51 it("demands a command", async () => {52 const cli = prepare(cwd);53 try {54 await parse(cli, ["--loglevel", "silent"]);55 } catch (exitError) {56 expect(exitError.message).toMatch("A command is required.");57 }58 expect.hasAssertions();59 });60 it("recommends commands", async () => {61 const cli = prepare(cwd);62 cli.command("you", "shall not pass");63 try {64 await parse(cli, ["yooou"]);65 } catch (exitError) {66 const [unknownCmd, didYouMean] = loggingOutput("error");67 expect(unknownCmd).toBe('Unknown command "yooou"');68 expect(didYouMean).toBe("Did you mean you?");69 expect(exitError.message).toBe("Unknown argument: yooou");70 }71 expect.hasAssertions();72 });73 it("does not re-log ValidationError messages", async () => {74 const cli = prepare(cwd);75 cli.command("boom", "explodey", {}, () => {76 throw new ValidationError("test", "go boom");77 });78 try {79 await parse(cli, ["boom"]);80 } catch (exitError) {81 expect(exitError.name).toBe("ValidationError");82 expect(exitError.message).toBe("go boom");83 expect(loggingOutput("error")).toEqual(["go boom"]);84 }85 expect.hasAssertions();86 });87 it("does not re-log ValidationError messages (async)", async () => {88 const cli = prepare(cwd);89 cli.command("boom", "explodey", {}, async () => {90 throw new ValidationError("test", "...boom");91 });92 // paradoxically, this does NOT reject...93 await parse(cli, ["boom"]);94 expect(loggingOutput("error")).toEqual(["...boom"]);95 });96 it("does not log errors with a pkg property", async () => {97 const cli = prepare(cwd);98 cli.command("run", "a package error", {}, () => {99 const err = new Error("oops");100 err.pkg = {}; // actual content doesn't matter here101 throw err;102 });103 try {104 await parse(cli, ["run"]);105 } catch (exitError) {106 expect(exitError.message).toBe("oops");107 expect(loggingOutput("error")).toEqual([]);108 }109 expect.hasAssertions();110 });111 it("logs generic command errors", async () => {112 const cli = prepare(cwd);113 const spy = jest.spyOn(cli, "exit");114 cli.command("handler", "a generic error", {}, async () => {115 const err = new Error("yikes");116 throw err;117 });118 // paradoxically, this does NOT reject...119 await parse(cli, ["handler"]);120 expect(loggingOutput("error")).toEqual(["yikes"]);121 expect(spy).toHaveBeenLastCalledWith(122 1,123 expect.objectContaining({124 message: "yikes",125 })126 );127 });128 it("coerces string exit codes to 1", async () => {129 const cli = prepare(cwd);130 const spy = jest.spyOn(cli, "exit");131 cli.command("errname", "a string code", {}, async () => {132 const err = new Error("kersplode");133 err.code = "E401";134 throw err;135 });136 // paradoxically, this does NOT reject...137 await parse(cli, ["errname"]);138 expect(spy).toHaveBeenLastCalledWith(139 1,140 expect.objectContaining({141 message: "kersplode",142 })143 );144 });145 it("preserves exotic exit codes", async () => {146 const cli = prepare(cwd);147 const spy = jest.spyOn(cli, "exit");148 cli.command("exotic", "exit code", {}, async () => {149 const err = new Error("fancy fancy");150 err.code = 127;151 throw err;152 });153 // paradoxically, this does NOT reject...154 await parse(cli, ["exotic"]);155 expect(spy).toHaveBeenLastCalledWith(156 127,157 expect.objectContaining({158 message: "fancy fancy",159 })160 );161 });...

Full Screen

Full Screen

procutil.js

Source:procutil.js Github

copy

Full Screen

1var util = require('util')2var cp = require('child_process')3var Promise = require('bluebird')4var log = require('./logger').createLogger('util:procutil')5function ExitError(code) {6 Error.call(this)7 this.name = 'ExitError'8 this.code = code9 this.message = util.format('Exit code "%d"', code)10 Error.captureStackTrace(this, ExitError)11}12util.inherits(ExitError, Error)13// Export14module.exports.ExitError = ExitError15// Export16module.exports.fork = function(filename, args) {17 log.info('Forking "%s %s"', filename, args.join(' '))18 var resolver = Promise.defer()19 var proc = cp.fork.apply(cp, arguments)20 function sigintListener() {21 proc.kill('SIGINT')22 }23 function sigtermListener() {24 proc.kill('SIGTERM')25 }26 process.on('SIGINT', sigintListener)27 process.on('SIGTERM', sigtermListener)28 proc.on('error', function(err) {29 resolver.reject(err)30 proc.kill()31 })32 proc.on('exit', function(code, signal) {33 if (signal) {34 resolver.resolve(code)35 }36 else if (code > 0 && code !== 130 && code !== 143) {37 resolver.reject(new ExitError(code))38 }39 else {40 resolver.resolve(code)41 }42 })43 return resolver.promise.cancellable()44 .finally(function() {45 process.removeListener('SIGINT', sigintListener)46 process.removeListener('SIGTERM', sigtermListener)47 })48 .catch(Promise.CancellationError, function() {49 return new Promise(function(resolve) {50 proc.on('exit', function() {51 resolve()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var exitError = devicefarmer.exitError;3var devicefarmer = require('devicefarmer-stf');4var exitError = devicefarmer.exitError;5var devicefarmer = require('devicefarmer-stf');6var exitError = devicefarmer.exitError;

Full Screen

Using AI Code Generation

copy

Full Screen

1var exec = require('child_process').exec;2var exitError = require('devicefarmer-stf').ExitError;3var child = exec('adb devices', function (error, stdout, stderr) {4 if (error !== null) {5 if (error instanceof exitError) {6 console.log('exit code: ' + error.code);7 console.log('signal received: ' + error.signal);8 }9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var DeviceFarmer = require('devicefarmer-stf');2deviceFarmer.getDevice(function (err, device) {3 device.exitError(function (err) {4 });5});6var DeviceFarmer = require('devicefarmer-stf');7deviceFarmer.getDevice(function (err, device) {8 device.exit(function (err) {9 });10});11var DeviceFarmer = require('devicefarmer-stf');12deviceFarmer.getDevice(function (err, device) {13 device.getInfo(function (err) {14 });15});16var DeviceFarmer = require('devicefarmer-stf');17deviceFarmer.getDevice(function (err, device) {18 device.getProperty('ro.build.version.release', function (err, value) {19 });20});21var DeviceFarmer = require('devicefarmer-stf');22deviceFarmer.getDevice(function (err, device) {23 device.getProperties(function (err, values) {24 });25});26var DeviceFarmer = require('devicefarmer-stf');27deviceFarmer.getDevice(function (err, device) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var devices = devicefarmer.getDevices();3devices.then(function(devices){4 var device = devices[0];5 device.exitError();6 console.log('executed exitError()');7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf-client');2device.connect().then(function(){3 device.shell('am start -n com.example.android.apis/.ApiDemos').then(function(){4 device.shell('am start -n com.example.android.apis/.ApiDemos').then(function(){5 console.log('done');6 },function(err){7 console.log('err: ',err);8 });9 },function(err){10 console.log('err: ',err);11 });12});13err: { [ExitError: exit code 1]14 stderr: 'Error type 3\nError: Activity class {com.example.android.apis/com.example.android.apis.ApiDemos} does not exist.\n' }15err: { [ExitError: exit code 1]16 stderr: 'Error type 3\nError: Activity class {com.example.android.apis/com.example.android.apis.ApiDemos} does not exist.\n' }17shell: { [ExitError: exit code 1]18 stderr: 'Error type 3\nError: Activity class {com.example.android.apis/com.example.android.apis.ApiDemos} does not exist.\n' }19shell: { [ExitError: exit code 1]20 stderr: 'Error type 3\nError: Activity class {com.example.android.apis/com.example.android.apis.ApiDemos} does not exist.\n' }

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 devicefarmer-stf 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