CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jasmine

CLI for Jasmine, a simple JavaScript testing framework for browsers and Node

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

configuration.mddocs/

Configuration Management

Jasmine provides a comprehensive configuration system supporting JSON and JavaScript config files with CLI overrides, environment variable support, and flexible file loading strategies.

Capabilities

Configuration Loading

Load configuration from files with automatic discovery and multiple format support.

/**
 * Loads configuration from the specified file
 * @param configFilePath - Path to config file, defaults to spec/support/jasmine.json
 * @returns Promise that resolves when configuration is loaded
 */
loadConfigFile(configFilePath?: string): Promise<void>;

/**
 * Loads configuration from the specified object
 * @param config - Configuration object
 */
loadConfig(config: Configuration): void;

File Discovery Order:

  1. spec/support/jasmine.mjs (ES module, preferred)
  2. spec/support/jasmine.json (JSON format)
  3. spec/support/jasmine.js (CommonJS module)

Usage Examples:

const Jasmine = require('jasmine');
const jasmine = new Jasmine();

// Load default config file
await jasmine.loadConfigFile();

// Load specific config file
await jasmine.loadConfigFile('config/test.json');

// Load configuration object directly
jasmine.loadConfig({
  spec_dir: 'test',
  spec_files: ['**/*-test.js'],
  helpers: ['test/helpers/**/*.js'],
  random: true
});

Configuration Interface

Complete configuration object structure with all supported options.

interface Configuration {
  /** The directory that spec files are contained in, relative to the project base directory */
  spec_dir?: string;
  
  /** An array of spec file paths or globs that match spec files */
  spec_files?: string[];
  
  /** An array of helper file paths or globs that match helper files */
  helpers?: string[];
  
  /** An array of module names to load at the start of execution */
  requires?: string[];
  
  /** Specifies how to load files with names ending in .js */
  jsLoader?: 'import' | 'require';
  
  /** Whether to fail specs that contain no expectations */
  failSpecWithNoExpectations?: boolean;
  
  /** Whether to stop each spec on the first expectation failure */
  stopSpecOnExpectationFailure?: boolean;
  
  /** Whether to stop suite execution on the first spec failure */
  stopOnSpecFailure?: boolean;
  
  /** Whether the default reporter should list pending specs even if there are failures */
  alwaysListPendingSpecs?: boolean;
  
  /** Whether to run specs in a random order */
  random?: boolean;
  
  /** Whether to show verbose deprecation warnings */
  verboseDeprecations?: boolean;
  
  /** An array of reporters (JavaScript config files only) */
  reporters?: Reporter[];
  
  /** A function that will be called exactly once before the test suite runs */
  globalSetup?: () => void | Promise<void>;
  
  /** The number of milliseconds to wait for an asynchronous globalSetup to complete */
  globalSetupTimeout?: number;
  
  /** A function that will be called exactly once after the test suite runs */
  globalTeardown?: () => void | Promise<void>;
  
  /** The number of milliseconds to wait for an asynchronous globalTeardown to complete */
  globalTeardownTimeout?: number;
  
  /** Environment configuration passed to jasmine-core */
  env?: object;
}

File and Module Configuration

Configure spec files, helpers, and required modules with glob pattern support.

/**
 * Adds files that match the specified patterns to the list of spec files
 * @param patterns - Array of spec file paths or globs relative to spec directory
 */
addMatchingSpecFiles(patterns: string[]): void;

/**
 * Adds files that match the specified patterns to the list of helper files
 * @param patterns - Array of helper file paths or globs relative to spec directory
 */
addMatchingHelperFiles(patterns: string[]): void;

/**
 * Adds a single spec file to the list
 * @param filePath - The path to the file to be loaded
 */
addSpecFile(filePath: string): void;

/**
 * Adds a single helper file to the list
 * @param filePath - The path to the file to be loaded
 */
addHelperFile(filePath: string): void;

/**
 * Adds required modules to be loaded at startup
 * @param requires - Array of module names to require
 */
addRequires(requires: string[]): void;

/**
 * Configures the default reporter that is installed if no other reporter is specified
 * @param options - Configuration options for the default console reporter
 */
configureDefaultReporter(options: ConsoleReporterOptions): void;

interface ConsoleReporterOptions {
  /** Whether to colorize the output */
  showColors?: boolean;
  /** Custom print function for output */
  print?: (text: string) => void;
  /** Function to filter/modify stack traces */
  stackFilter?: (stack: string) => string;
  /** Function that takes a random seed and returns the command to reproduce that seed */
  randomSeedReproductionCmd?: (seed: string) => string;
  /** Whether to list pending specs even if there are failures */
  alwaysListPendingSpecs?: boolean;
}

Usage Examples:

const jasmine = new Jasmine();

// Add spec files with glob patterns
jasmine.addMatchingSpecFiles([
  '**/*-spec.js',
  '**/*-test.js',
  '!**/*-integration-test.js' // Exclude integration tests
]);

// Add helper files
jasmine.addMatchingHelperFiles([
  'helpers/**/*.js',
  'support/**/*.js'
]);

// Add individual files
jasmine.addSpecFile('spec/unit/user-service.spec.js');
jasmine.addHelperFile('spec/helpers/database-helper.js');

// Add required modules
jasmine.addRequires(['@babel/register', 'tsconfig-paths/register']);

JavaScript Module Loading

Configure module loading strategy for ES modules and CommonJS compatibility.

// Configuration options for module loading
interface ModuleLoadingConfig {
  /** Specifies how to load files with names ending in .js */
  jsLoader: 'import' | 'require';
}

Usage Examples:

// ES module configuration (jasmine.mjs)
export default {
  spec_dir: 'spec',
  spec_files: ['**/*-spec.mjs'],
  jsLoader: 'import', // Use dynamic import()
  env: {
    forbidDuplicateNames: true
  }
};

// CommonJS configuration (jasmine.json)
{
  "spec_dir": "test",
  "spec_files": ["**/*-test.js"],
  "jsLoader": "require",
  "random": true
}

// Mixed environment handling
const config = {
  spec_dir: 'spec',
  spec_files: [
    '**/*-spec.js',   // CommonJS specs
    '**/*-spec.mjs'   // ES module specs
  ],
  jsLoader: 'import', // Use import for better compatibility
  helpers: ['helpers/**/*.js']
};

Global Setup and Teardown

Configure global setup and teardown functions for test suite initialization and cleanup.

interface GlobalHooksConfig {
  /** A function that will be called exactly once before the test suite runs */
  globalSetup?: () => void | Promise<void>;
  
  /** The number of milliseconds to wait for globalSetup to complete (default: 5000) */
  globalSetupTimeout?: number;
  
  /** A function that will be called exactly once after the test suite runs */
  globalTeardown?: () => void | Promise<void>;
  
  /** The number of milliseconds to wait for globalTeardown to complete (default: 5000) */
  globalTeardownTimeout?: number;
}

Usage Examples:

// JavaScript config file (jasmine.js)
const { spawn } = require('child_process');

module.exports = {
  spec_dir: 'spec',
  spec_files: ['**/*-spec.js'],
  
  globalSetup: async () => {
    console.log('Starting test database...');
    // Start database, create test data, etc.
    await startTestDatabase();
  },
  
  globalSetupTimeout: 10000, // 10 seconds
  
  globalTeardown: async () => {
    console.log('Cleaning up test environment...');
    // Stop database, clean up files, etc.
    await stopTestDatabase();
  },
  
  globalTeardownTimeout: 5000 // 5 seconds
};

async function startTestDatabase() {
  // Implementation for starting test database
}

async function stopTestDatabase() {
  // Implementation for stopping test database
}

Reporter Configuration

Configure multiple reporters in JavaScript configuration files.

interface ReporterConfig {
  /** An array of reporters (only supported in JavaScript config files) */
  reporters?: Reporter[];
}

interface Reporter {
  jasmineStarted?(suiteInfo: any): void;
  jasmineDone?(suiteInfo: any): void;
  specDone?(result: any): void;
  suiteDone?(result: any): void;
  reporterCapabilities?: { parallel?: boolean };
}

Usage Example:

// jasmine.js config file
const fs = require('fs');

const customReporter = {
  specDone: (result) => {
    if (result.status === 'failed') {
      fs.appendFileSync('failed-specs.log', `${result.fullName}\n`);
    }
  }
};

const parallelReporter = {
  reporterCapabilities: { parallel: true },
  jasmineDone: (result) => {
    console.log(`Tests completed: ${result.overallStatus}`);
  }
};

module.exports = {
  spec_dir: 'spec',
  spec_files: ['**/*-spec.js'],
  reporters: [customReporter, parallelReporter]
};

Environment Variable Support

Override configuration using environment variables and CLI arguments.

Environment Variables:

  • JASMINE_CONFIG_PATH: Path to configuration file

Usage Examples:

# Use custom config file
JASMINE_CONFIG_PATH=config/ci.json npx jasmine

# CLI overrides take precedence over config file
npx jasmine --config=config/local.json --parallel=4 --verbose

Default Configuration Example

Complete example configuration showing all available options:

// spec/support/jasmine.mjs
export default {
  // File locations
  spec_dir: 'spec',
  spec_files: [
    '**/*[sS]pec.?(m)js'
  ],
  helpers: [
    'helpers/**/*.?(m)js'
  ],
  requires: [
    '@babel/register'
  ],
  
  // Module loading
  jsLoader: 'import',
  
  // Test execution behavior
  failSpecWithNoExpectations: false,
  stopSpecOnExpectationFailure: false,
  stopOnSpecFailure: false,
  alwaysListPendingSpecs: true,
  random: true,
  verboseDeprecations: false,
  
  // Global hooks
  globalSetupTimeout: 5000,
  globalTeardownTimeout: 5000,
  
  // Environment configuration passed to jasmine-core
  env: {
    forbidDuplicateNames: true,
    throwOnExpectationFailure: false,
    random: true,
    hideDisabled: false
  }
};

docs

cli.md

configuration.md

index.md

parallel-runner.md

reporting.md

sequential-runner.md

tile.json