Vue CLI plugin that adds End-to-End testing support using Cypress testing framework.
npx @tessl/cli install tessl/npm-vue--cli-plugin-e2e-cypress@5.0.0Vue CLI plugin that adds End-to-End testing support using Cypress testing framework. It provides a comprehensive testing solution that integrates Cypress into the Vue CLI ecosystem, offering both interactive GUI mode for development and headless mode for CI/CD pipelines.
vue add e2e-cypressThis package is a Vue CLI plugin that extends the Vue CLI service with additional commands and functionality. It is not directly imported in application code but instead registers commands and integrates with the Vue CLI system.
// Vue CLI plugins are loaded automatically by the CLI service
// No direct imports needed in application code# Install the plugin in an existing Vue project
vue add e2e-cypress
# Run e2e tests in interactive mode
vue-cli-service test:e2e
# Run e2e tests in headless mode (for CI)
vue-cli-service test:e2e --headless
# Run tests against a specific URL
vue-cli-service test:e2e --url=http://localhost:8080
# Run a specific test file in headless mode
vue-cli-service test:e2e --headless --spec=tests/e2e/specs/test.jsThis Vue CLI plugin consists of several key components:
test:e2e command with the Vue CLI serviceRegisters the test:e2e command with Vue CLI service for running Cypress tests.
/**
* Main plugin function that registers the test:e2e command
* @param api - Vue CLI Plugin API instance
* @param options - Plugin configuration options
*/
function plugin(api: PluginAPI, options: PluginOptions): void;
interface PluginAPI {
registerCommand(name: string, options: CommandOptions, handler: CommandHandler): void;
service: {
run(command: string): Promise<{ url: string; server?: any }>;
};
getCwd(): string;
}
interface CommandOptions {
description: string;
usage: string;
options: Record<string, string>;
details: string;
}
interface CommandHandler {
(args: CommandArgs, rawArgs: string[]): Promise<any>;
}
interface CommandArgs {
headless?: boolean;
mode?: string;
url?: string;
spec?: string;
config?: string | string[];
}The test:e2e command that executes Cypress tests with various configuration options.
Command: vue-cli-service test:e2e [options]
Options:
--headless: Run in headless mode without GUI--mode: Specify the mode the dev server should run in (default: production)--url: Run e2e tests against given URL instead of auto-starting dev server-s, --spec: (headless only) Run a specific spec file, defaults to "all"Usage Examples:
# Interactive mode with GUI
vue-cli-service test:e2e
# Headless mode for CI/CD
vue-cli-service test:e2e --headless
# Test against custom URL
vue-cli-service test:e2e --url=https://staging.example.com
# Run specific test file
vue-cli-service test:e2e --headless --spec=tests/e2e/specs/login.spec.js
# Development mode
vue-cli-service test:e2e --mode=developmentDefines the default execution mode for the test:e2e command.
/**
* Default modes configuration for commands
*/
const defaultModes: {
'test:e2e': string;
} = {
'test:e2e': 'production'
};Generator function that creates the initial Cypress test structure when the plugin is added to a project.
/**
* Generator function that sets up Cypress testing structure
* @param api - Vue CLI Generator API instance
*/
function generator(api: GeneratorAPI): void;
interface GeneratorAPI {
render(templatePath: string, data: TemplateData): void;
extendPackage(packageUpdate: PackageUpdate): void;
hasPlugin(pluginName: string): boolean;
}
interface TemplateData {
hasTS: boolean;
hasESLint: boolean;
}
interface PackageUpdate {
devDependencies: Record<string, string>;
scripts: Record<string, string>;
}Generated Structure:
cypress.json: Cypress configuration filetests/e2e/plugins/index.js: Cypress plugins configurationtests/e2e/support/index.js: Cypress support filetests/e2e/support/commands.js: Custom Cypress commandstests/e2e/specs/test.js: Example test specificationtests/e2e/_eslintrc.js: ESLint configuration for e2e testsMigrator function that handles updates to existing projects when the plugin is upgraded.
/**
* Migrator function that handles plugin upgrades and ensures Cypress dependency
* @param api - Vue CLI Migrator API instance
*/
function migrator(api: MigratorAPI): void;
interface MigratorAPI {
extendPackage(packageUpdateFn: PackageUpdateFunction): void;
}
interface PackageUpdateFunction {
(pkg: PackageJSON): PackageUpdate | undefined;
}
interface PackageJSON {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
optionalDependencies?: Record<string, string>;
}UI integration function that provides graphical interface for running tests in Vue CLI UI.
/**
* UI integration function for Vue CLI UI
* @param api - Vue CLI UI API instance
*/
function uiIntegration(api: UIAPI): void;
interface UIAPI {
describeTask(taskDescriptor: TaskDescriptor): void;
}
interface TaskDescriptor {
match: RegExp;
description: string;
link: string;
prompts: UIPrompt[];
onBeforeRun: BeforeRunHandler;
}
interface UIPrompt {
name: string;
type: 'confirm' | 'list' | 'input';
default: any;
description: string;
choices?: UIChoice[];
}
interface UIChoice {
name: string;
value: string;
}
interface BeforeRunHandler {
(context: { answers: Record<string, any>; args: string[] }): void;
}/**
* Removes specified arguments from command line arguments array
* @param rawArgs - Array of command line arguments
* @param argToRemove - Name of argument to remove (without --)
* @param offset - Number of additional arguments to remove (default: 1)
*/
function removeArg(rawArgs: string[], argToRemove: string, offset?: number): void;/**
* Plugin configuration options
*/
interface PluginOptions {
[key: string]: any;
}
/**
* Cypress execution modes
*/
type CypressMode = 'open' | 'run';
/**
* Server execution mode
*/
type ServerMode = 'development' | 'production' | 'test';
/**
* Test execution result
*/
interface TestResult {
success: boolean;
exitCode?: number;
}The plugin creates a cypress.json configuration file with the following default settings:
{
"pluginsFile": "tests/e2e/plugins/index.js"
}Additional Cypress configuration options can be added to this file. See the Cypress Configuration documentation for all available options.
Cypress tests support environment variables through:
cypress.json: Global configurationcypress.env.json: Environment-specific variablesCYPRESS_Variables are accessible in tests via Cypress.env('VARIABLE_NAME').