or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-vue--cli-plugin-e2e-cypress

Vue CLI plugin that adds End-to-End testing support using Cypress testing framework.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@vue/cli-plugin-e2e-cypress@5.0.x

To install, run

npx @tessl/cli install tessl/npm-vue--cli-plugin-e2e-cypress@5.0.0

index.mddocs/

Vue CLI Plugin E2E Cypress

Vue 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.

Package Information

  • Package Name: @vue/cli-plugin-e2e-cypress
  • Package Type: npm
  • Language: JavaScript
  • Installation: vue add e2e-cypress

Core Imports

This 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

Basic Usage

# 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.js

Architecture

This Vue CLI plugin consists of several key components:

  • Main Plugin Function: Registers the test:e2e command with the Vue CLI service
  • Generator: Creates initial test structure and configuration files when the plugin is added
  • Migrator: Handles updates and migrations for existing projects
  • UI Integration: Provides Vue CLI UI interface for running tests
  • Template System: Generates Cypress configuration and test files

Capabilities

Command Registration

Registers 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[];
}

Test Execution Command

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=development

Default Mode Configuration

Defines the default execution mode for the test:e2e command.

/**
 * Default modes configuration for commands
 */
const defaultModes: {
  'test:e2e': string;
} = {
  'test:e2e': 'production'
};

Project Generation

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 file
  • tests/e2e/plugins/index.js: Cypress plugins configuration
  • tests/e2e/support/index.js: Cypress support file
  • tests/e2e/support/commands.js: Custom Cypress commands
  • tests/e2e/specs/test.js: Example test specification
  • tests/e2e/_eslintrc.js: ESLint configuration for e2e tests

Project Migration

Migrator 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>;
}

Vue CLI UI Integration

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;
}

Utility Functions

/**
 * 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;

Types

/**
 * 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;
}

Dependencies

Runtime Dependencies

  • @vue/cli-shared-utils: Vue CLI shared utilities for logging, process execution, and module resolution (version ^5.0.9)
  • eslint-plugin-cypress: ESLint plugin providing Cypress-specific rules and globals (version ^2.11.2)

Peer Dependencies

  • @vue/cli-service: Vue CLI service (versions 3.x, 4.x, or 5.x)
  • cypress: Cypress testing framework (any version)

Generated DevDependencies

  • cypress: Cypress testing framework (version ^9.7.0 by default)

Configuration

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.

Environment Variables

Cypress tests support environment variables through:

  • cypress.json: Global configuration
  • cypress.env.json: Environment-specific variables
  • Environment variables prefixed with CYPRESS_

Variables are accessible in tests via Cypress.env('VARIABLE_NAME').