How to use checkExit method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

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

lib.js

Source: lib.js Github

copy
1importPackage(org.mechio.client.basic);
2importPackage(org.mechio.api.motion);
3importPackage(org.jflux.api.common.rk.position);
4//importPackage(org.jflux.api.common.rk.utils);
5
6function checkExit() {
7    var b = controlSystem.isExitingNow();
8    if(controlSystem.isExitingNow()) {
9        throw new Error('now exiting...');
10    }
11}
12
13function SRobot(robot) {
14    checkExit();
15    var myRobot = robot;
16
17    this.move = function(positions, lenMillisec) {
18        checkExit();
19        myRobot.move(positions, lenMillisec);
20    }
21
22    this.getRobotId = function() {
23        checkExit();
24        return myRobot.getRobotId();
25    }
26}
27
28function SAnimPlayer(animPlayer) {
29    checkExit();
30    var myAnimPlayer = animPlayer;
31
32    this.playAnimation = function(animation) {
33        checkExit();
34        return myAnimPlayer.playAnimation(animation);
35    }
36
37    this.loopAnimation = function(animation) {
38        checkExit();
39        return myAnimPlayer.loopAnimation(animation);
40    }
41
42    this.stopAnimation = function(animation) {
43        myAnimPlayer.stopAnimation(animation);
44        checkExit();
45    }
46}
47
48function connectRobot(ipAddress) {
49    checkExit();
50
51    if(ipAddress === undefined) {
52        return new SRobot(MechIO.connectRobot());
53    } else {
54        return new SRobot(MechIO.connectRobot(ipAddress));
55    }
56}
57
58function connectAnimationPlayer(ipAddress) {
59    checkExit();
60
61    if(ipAddress === undefined) {
62        return new SAnimPlayer(MechIO.connectAnimationPlayer());
63    } else {
64        return new SAnimPlayer(MechIO.connectAnimationPlayer(ipAddress));
65    }
66}
67
Full Screen

index.js

Source: index.js Github

copy
1'use strict';
2
3// eslint-disable-next-line import/no-unassigned-import
4require('make-promises-safe');
5
6const Installer = require('./Installer');
7
8(async () => {
9  const installer = new Installer();
10  await checkExit(installer.init());
11  await checkExit(installer.installDeps());
12  await checkExit(installer.findEmscripten());
13  await checkExit(installer.findMSBuild());
14  await checkExit(installer.compileRdkit());
15})();
16
17async function checkExit(promise) {
18  const result = await promise;
19  if (result === false) {
20    console.error('An error occured');
21    process.exit(1);
22  }
23}
24
Full Screen

checkExit.test.js

Source: checkExit.test.js Github

copy
1const { Tx, Input, Outpoint } = require('leap-core');
2const checkExit = require('./checkExit');
3
4const ADDR_1 = '0x4436373705394267350db2c06613990d34621d69';
5
6const makeExitMock = (exitor, amount, color, outpoint) => {
7  const exitingUtxos = {};
8  if (outpoint) {
9    exitingUtxos[outpoint.hex()] = {};
10  }
11  return {
12    exits: new Proxy(
13      {},
14      {
15        get: () => ({ exitor, amount, color }),
16      }
17    ),
18    exitingUtxos,
19  };
20};
21
22describe('checkExit', () => {
23  test('wrong type', () => {
24    const tx = Tx.transfer([], []);
25    expect(() => checkExit({}, tx)).toThrow('Exit tx expected');
26  });
27
28  test('successful tx', () => {
29    const deposit = Tx.deposit(12, 500, ADDR_1, 0);
30    const outpoint = new Outpoint(deposit.hash(), 0);
31    const state = {
32      unspent: {
33        [outpoint.hex()]: deposit.outputs[0].toJSON(),
34      },
35    };
36
37    const bridgeState = makeExitMock(ADDR_1, '500', 0, outpoint);
38
39    const exit = Tx.exit(new Input(outpoint));
40    checkExit(state, exit, bridgeState);
41    expect(bridgeState.exitingUtxos).toEqual({});
42  });
43
44  test('not 1 input', () => {
45    const deposit = Tx.deposit(12, 500, ADDR_1, 0);
46    const outpoint = new Outpoint(deposit.hash(), 0);
47    const state = {
48      unspent: {
49        [outpoint.hex()]: deposit.outputs[0].toJSON(),
50      },
51    };
52
53    const exit = Tx.exit(new Input(outpoint));
54    exit.inputs.push(new Input(outpoint));
55    expect(() =>
56      checkExit(state, exit, makeExitMock(ADDR_1, '500', 0))
57    ).toThrow('Exit tx should have one input');
58  });
59
60  test('non-existent exit', () => {
61    const deposit = Tx.deposit(12, 500, ADDR_1, 0);
62    const outpoint = new Outpoint(deposit.hash(), 0);
63    const state = {
64      unspent: {
65        [outpoint.hex()]: deposit.outputs[0].toJSON(),
66      },
67    };
68    const exit = Tx.exit(new Input(outpoint));
69    expect(() => {
70      checkExit(state, exit, { exits: {} });
71    }).toThrow('Trying to submit incorrect exit');
72  });
73
74  test('non-existent utxo', () => {
75    const deposit = Tx.deposit(12, 500, ADDR_1, 0);
76    const outpoint = new Outpoint(deposit.hash(), 0);
77    const state = {
78      unspent: {},
79    };
80
81    const exit = Tx.exit(new Input(outpoint));
82    expect(() => {
83      checkExit(state, exit, makeExitMock(ADDR_1, '500', 0));
84    }).toThrow('Trying to submit incorrect exit');
85  });
86
87  test('wrong amount: erc20', () => {
88    const deposit = Tx.deposit(12, 500, ADDR_1, 0);
89    const outpoint = new Outpoint(deposit.hash(), 0);
90    const state = {
91      unspent: {
92        [outpoint.hex()]: deposit.outputs[0].toJSON(),
93      },
94    };
95    const exit = Tx.exit(new Input(outpoint));
96    expect(() => {
97      checkExit(state, exit, makeExitMock(ADDR_1, '600', 0));
98    }).toThrow('Trying to submit incorrect exit');
99  });
100
101  test('wrong amount: erc721', () => {
102    const color = 32769 + 1;
103    const deposit = Tx.deposit(12, '500', ADDR_1, color);
104    const outpoint = new Outpoint(deposit.hash(), 0);
105    const state = {
106      unspent: {
107        [outpoint.hex()]: deposit.outputs[0].toJSON(),
108      },
109    };
110    const exit = Tx.exit(new Input(outpoint));
111    expect(() => {
112      checkExit(state, exit, makeExitMock(ADDR_1, '600', color));
113    }).toThrow('Trying to submit incorrect exit');
114  });
115
116  test('wrong color', () => {
117    const deposit = Tx.deposit(12, 500, ADDR_1, 0);
118    const outpoint = new Outpoint(deposit.hash(), 0);
119    const state = {
120      unspent: {
121        [outpoint.hex()]: deposit.outputs[0].toJSON(),
122      },
123    };
124    const exit = Tx.exit(new Input(outpoint));
125    expect(() => {
126      checkExit(state, exit, makeExitMock(ADDR_1, '500', 1));
127    }).toThrow('Trying to submit incorrect exit');
128  });
129});
130
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)