cypress-bootstrap
Version:
Cypress Bootstrap is a project scaffolding tool that sets up a Cypress automation framework with a standardized folder structure and Page Object Model (POM) design. It helps teams quickly start testing with built-in best practices and sample specs.
93 lines (80 loc) • 2.61 kB
JavaScript
/**
* Cypress Bootstrap CLI
*
* This is a command-line interface for the Cypress Bootstrap package.
* It provides commands to set up and configure the framework.
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Define the commands
const commands = {
setup: {
description: 'Set up the Cypress Bootstrap framework in your project',
action: runSetup,
},
help: {
description: 'Show help information',
action: showHelp,
},
version: {
description: 'Show the version of the Cypress Bootstrap package',
action: showVersion,
},
};
// Parse the command-line arguments
const args = process.argv.slice(2);
const command = args[0] || 'setup'; // Default to 'setup' if no command is provided
// Execute the command
if (commands[command]) {
commands[command].action();
} else {
console.error(`Unknown command: ${command}`);
showHelp();
process.exit(1);
}
// Function to run the setup script
function runSetup() {
console.log('Setting up Cypress Bootstrap framework...');
try {
// Run the setup script
require('../scripts/setup.js');
console.log('\nSetup completed successfully!');
console.log('You can now start using the Cypress Bootstrap framework.');
console.log('Run "npx cypress open" to open the Cypress Test Runner.');
} catch (error) {
console.error('Error running setup script:', error.message);
console.error('Please try running the setup script manually:');
console.error(' npm run setup');
process.exit(1);
}
}
// Function to show help information
function showHelp() {
console.log('Cypress Bootstrap CLI');
console.log('');
console.log('Usage:');
console.log(' npx cypress-bootstrap <command>');
console.log('');
console.log('Commands:');
Object.keys(commands).forEach(cmd => {
console.log(` ${cmd.padEnd(10)} ${commands[cmd].description}`);
});
console.log('');
console.log('Examples:');
console.log(' npx cypress-bootstrap setup # Set up the framework');
console.log(' npx cypress-bootstrap help # Show help information');
console.log(' npx cypress-bootstrap version # Show the version');
}
// Function to show the version
function showVersion() {
try {
const packageJsonPath = path.join(__dirname, '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
console.log(`Cypress Bootstrap v${packageJson.version}`);
} catch (error) {
console.error('Error reading package.json:', error.message);
process.exit(1);
}
}