Skip to content

Commit

Permalink
feat: integrate custom cypress command for executing shell commands (#34
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rabi-siddique authored Mar 28, 2024
1 parent 19c1401 commit a50014e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions plugins/keplr-plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
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 @@ -54,6 +55,19 @@ module.exports = (on, config) => {
console.log('\u001B[36m', 'INFO:', message, '\u001B[0m');
return true;
},

async execute(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
reject({ error, stdout, stderr });
} else {
resolve({ stdout, stderr });
}
});
});
},

// playwright commands for Keplr
initPlaywright: playwright.init,
assignWindows: playwright.assignWindows,
Expand Down
4 changes: 4 additions & 0 deletions support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,7 @@ Cypress.Commands.add('addNewTokensFound', () => {
Cypress.Commands.add('getTokenAmount', tokenName => {
return cy.task('getTokenAmount', { tokenName });
});

Cypress.Commands.add('execute', command => {
return cy.task('execute', command);
});
10 changes: 10 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,16 @@

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

cy.execute(command).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 a50014e

Please sign in to comment.