CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-wdio--jasmine-framework

A WebdriverIO plugin adapter that integrates Jasmine testing framework with WebdriverIO test runner for end-to-end testing.

Pending
Overview
Eval results
Files

adapter.mddocs/

Adapter Implementation

Core adapter implementation that bridges WebdriverIO with the Jasmine testing framework, providing test execution, expectation handling, and reporting integration.

Capabilities

JasmineAdapter Class

The main adapter class that orchestrates Jasmine test execution within WebdriverIO environments.

/**
 * Core adapter class that bridges WebdriverIO with Jasmine testing framework
 */
class JasmineAdapter {
  constructor(
    cid: string,
    config: WebdriverIOJasmineConfig,
    specs: string[],
    capabilities: Capabilities.ResolvedTestrunnerCapabilities,
    reporter: EventEmitter
  );

  /** Initialize the adapter and set up Jasmine environment */
  init(): Promise<JasmineAdapter>;

  /** Set up WebdriverIO expect and matchers with Jasmine environment, integrating async matchers and global expect */
  setupExpect(
    wdioExpect: typeof expect,
    wdioMatchers: typeof matchers,
    getConfig: typeof getConfig
  ): Promise<void>;

  /** Check if adapter has tests to run */
  hasTests(): boolean;

  /** Execute test suite and return failure count */
  run(): Promise<number>;

  /** Custom spec filtering based on grep options */
  customSpecFilter(spec: jasmine.Spec): boolean;

  /** Wrap hooks for async execution with WebdriverIO integration */
  wrapHook(hookName: keyof Services.HookFunctions): () => Promise<void>;

  /** Prepare hook messages for WebdriverIO reporters */
  prepareMessage(hookName: keyof Services.HookFunctions): FormattedMessage;

  /** Format framework messages for consumption by reporters */
  formatMessage(params: FrameworkMessage): FormattedMessage;

  /** Get custom expectation result handler for assertion interception */
  getExpectationResultHandler(jasmine: jasmine.Jasmine): Function;

  /** Create custom expectation result handler with user-defined logic */
  expectationResultHandler(origHandler: Function): Function;
}

Usage Examples:

import JasmineAdapterFactory from "@wdio/jasmine-framework";
import type { EventEmitter } from "node:events";

// Create adapter through factory
const adapter = await JasmineAdapterFactory.init(
  'worker-1',
  {
    jasmineOpts: {
      defaultTimeoutInterval: 30000,
      expectationResultHandler: (passed, data) => {
        if (!passed) {
          console.log('Test failed:', data.message);
        }
      }
    },
    beforeHook: [],
    afterHook: [],
    beforeTest: [],
    afterTest: []
  },
  ['./test/**/*.spec.js'],
  { browserName: 'chrome' },
  reporterEventEmitter
);

// Check if tests are available
if (adapter.hasTests()) {
  const failures = await adapter.run();
  console.log(`Tests completed with ${failures} failures`);
}

Types

interface ReporterOptions {
  cid: string;
  specs: string[];
  cleanStack?: boolean;
  jasmineOpts: JasmineOpts;
}

interface ParentSuite {
  description: string;
  id: string;
  tests: number;
}

interface SuiteEvent extends jasmine.SuiteResult {
  type: 'suite';
  start: Date;
  duration: number | null;
  errors?: jasmine.FailedExpectation[];
  error?: jasmine.FailedExpectation;
}

interface TestEvent extends jasmine.SpecResult {
  type: 'test' | 'hook';
  start: Date;
  duration: number | null;
  errors?: jasmine.FailedExpectation[];
  error?: jasmine.FailedExpectation;
}

interface FrameworkMessage {
  type: string;
  payload?: any;
  err?: jasmine.FailedExpectation;
}

interface FormattedMessage {
  type: string;
  cid?: string;
  specs?: string[];
  uid?: string;
  title?: string;
  parent?: string;
  fullTitle?: string;
  pending?: boolean;
  passed?: boolean;
  file?: string;
  duration?: number;
  currentTest?: string;
  error?: jasmine.FailedExpectation;
  context?: unknown;
  fullName?: string;
  errors?: jasmine.FailedExpectation[];
}

Global Declarations

The adapter extends the global scope with Jasmine test functions that include WebdriverIO-specific parameters:

/**
 * Define a single spec with optional WebdriverIO-specific retry count
 * @param expectation - Textual description of what this spec is checking
 * @param assertion - Function containing test code
 * @param timeout - Custom timeout for async spec
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function it(
  expectation: string,
  assertion?: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

/**
 * A focused spec - only focused specs will be executed
 * @param expectation - Textual description of what this spec is checking
 * @param assertion - Function containing test code
 * @param timeout - Custom timeout for async spec
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function fit(
  expectation: string,
  assertion?: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

/**
 * A temporarily disabled spec - will be reported as pending
 * @param expectation - Textual description of what this spec is checking
 * @param assertion - Function containing test code
 * @param timeout - Custom timeout for async spec
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function xit(
  expectation: string,
  assertion?: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

/**
 * Run shared setup before each spec in the describe block
 * @param action - Function containing setup code
 * @param timeout - Custom timeout for async beforeEach
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function beforeEach(
  action: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

/**
 * Run shared teardown after each spec in the describe block
 * @param action - Function containing teardown code
 * @param timeout - Custom timeout for async afterEach
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function afterEach(
  action: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

/**
 * Run shared setup once before all specs in the describe block
 * @param action - Function containing setup code
 * @param timeout - Custom timeout for async beforeAll
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function beforeAll(
  action: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

/**
 * Run shared teardown once after all specs in the describe block
 * @param action - Function containing teardown code
 * @param timeout - Custom timeout for async afterAll
 * @param retries - Custom retry count (WebdriverIO specific)
 */
declare function afterAll(
  action: jasmine.ImplementationCallback,
  timeout?: number,
  retries?: number
): void;

Install with Tessl CLI

npx tessl i tessl/npm-wdio--jasmine-framework

docs

adapter.md

configuration.md

index.md

tile.json