Skip to content

Commit

Permalink
feat: error handling for better messages and changes for executing sc…
Browse files Browse the repository at this point in the history
…ript files (#36)

* release: v3.8.0

Signed-off-by: toliaqat <[email protected]>

* release: v3.8.1-beta.0

Signed-off-by: toliaqat <[email protected]>

* feat: error handling for better messages and changes for executing script files

---------

Signed-off-by: toliaqat <[email protected]>
Co-authored-by: toliaqat <[email protected]>
  • Loading branch information
rabi-siddique and toliaqat authored Mar 28, 2024
1 parent 9f967f2 commit 5412d82
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions bin/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "Hello, stdout!"
echo "Error occurred" >&2
20 changes: 12 additions & 8 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { exec, execSync } = require('child_process');
const helpers = require('../helpers');
const playwright = require('../commands/playwright-keplr');
const keplr = require('../commands/keplr');
Expand Down Expand Up @@ -58,13 +57,18 @@ module.exports = (on, config) => {

async execute(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject({ error, stdout, stderr });
} else {
resolve({ stdout, stderr });
}
});
const { exec } = require('child_process');
try {
exec(command, (error, stdout, stderr) => {
if (error) {
reject(error);
} else {
resolve({ stdout, stderr });
}
});
} catch (e) {
reject(e);
}
});
},

Expand Down
1 change: 1 addition & 0 deletions synpress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = defineConfig({
fixturesFolder,
screenshotsFolder: 'tests/e2e/screenshots',
videosFolder: 'tests/e2e/videos',
bashScriptsFolder: process.cwd() +'/bin',
chromeWebSecurity: true,
viewportWidth: 1920,
viewportHeight: 1080,
Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/specs/keplr/keplr-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe('Keplr', () => {
context('Test commands', () => {
const scriptsFolder = Cypress.config('bashScriptsFolder');
it('Executes a command and verifies stdout and stderr', () => {
const command = 'echo "Hello, stdout!" && echo "Error occurred" >&2';

Expand All @@ -12,6 +13,18 @@ describe('Keplr', () => {
});
});

it('Executes a commands from a file and verifies stdout and stderr', () => {
const fileName = 'script.sh';

cy.execute(`sh ${scriptsFolder}/${fileName}`).then(
({ stdout, stderr, error }) => {
expect(stdout.trim()).to.equal('Hello, stdout!');
expect(stderr.trim()).to.equal('Error occurred');
expect(error).to.be.undefined;
},
);
});

it(`should complete Keplr setup by importing an existing wallet using 24 word phrase`, () => {
cy.setupWallet().then(setupFinished => {
expect(setupFinished).to.be.true;
Expand Down

0 comments on commit 5412d82

Please sign in to comment.