Convert Figma logo to code with AI

stryker-mutator logostryker-js

Mutation testing for JavaScript and friends

2,573
247
2,573
116

Top Related Projects

Mutation testing for .NET core and .NET framework!

PHP Mutation Testing library

Quick Overview

Stryker is a mutation testing framework for JavaScript and TypeScript. It helps developers ensure the quality of their tests by introducing small changes (mutations) to the source code and checking if the tests still pass. This helps identify weaknesses in the test suite and improve the overall test coverage.

Pros

  • Comprehensive Mutation Testing: Stryker supports a wide range of mutation operators, allowing for thorough testing of the codebase.
  • Language Support: Stryker supports both JavaScript and TypeScript, making it applicable to a wide range of projects.
  • Customizable Configuration: Stryker provides a flexible configuration system, allowing users to tailor the mutation testing process to their specific needs.
  • Integrations: Stryker integrates with popular testing frameworks and CI/CD tools, making it easy to incorporate into existing development workflows.

Cons

  • Performance Impact: Mutation testing can be computationally intensive, especially for large codebases, which may slow down the development process.
  • Learning Curve: Configuring and using Stryker effectively may require some initial effort, as it introduces a new concept (mutation testing) to the development workflow.
  • Potential False Positives: Mutation testing can sometimes identify "false positive" issues, where the tests pass but the mutated code is still incorrect, requiring manual investigation.
  • Ecosystem Maturity: Compared to other testing tools, the Stryker ecosystem may be less mature, with fewer resources and community support available.

Code Examples

// Example 1: Configuring Stryker
const config = {
  mutate: ['src/**/*.js'],
  testRunner: 'jest',
  reporters: ['html', 'clear-text', 'progress'],
  coverageAnalysis: 'perTest',
};

module.exports = config;

This code snippet shows an example Stryker configuration file, where the user specifies the files to mutate, the test runner to use, the reporters to generate output, and the coverage analysis strategy.

// Example 2: Defining a Mutation Operator
class ConstantFolding extends Mutator {
  static mutatorName = 'ConstantFolding';

  mutate(node) {
    if (node.type === 'BinaryExpression') {
      return this.mutateBinaryExpression(node);
    }
    return null;
  }

  mutateBinaryExpression(node) {
    const left = this.evaluateNode(node.left);
    const right = this.evaluateNode(node.right);
    const operator = node.operator;

    const result = this.calculateResult(left, right, operator);
    return t.numericLiteral(result);
  }

  // ...
}

This code example demonstrates how to define a custom mutation operator in Stryker. The ConstantFolding operator mutates binary expressions by evaluating the left and right operands and replacing the expression with a numeric literal.

// Example 3: Using Stryker in a TypeScript Project
import { StrykerOptions } from '@stryker-mutator/api/core';

const config: StrykerOptions = {
  mutate: ['src/**/*.ts'],
  testRunner: 'jest',
  reporters: ['html', 'clear-text', 'progress'],
  coverageAnalysis: 'perTest',
  tsconfigFile: 'tsconfig.json',
};

module.exports = config;

This TypeScript example shows how to configure Stryker for a TypeScript project, including specifying the tsconfigFile option to ensure proper handling of TypeScript-specific features.

Getting Started

To get started with Stryker, follow these steps:

  1. Install Stryker and its dependencies:

    npm install --save-dev @stryker-mutator/core @stryker-mutator/javascript-mutator @stryker-mutator/jest-runner
    
  2. Create a Stryker configuration file (e.g., stryker.conf.js) in the root of your project:

    module.exports = {
      mutate: ['src/**/*.js'],
      test
    

Competitor Comparisons

Mutation testing for .NET core and .NET framework!

Pros of Stryker-net

  • Native support for .NET languages (C#, F#, VB.NET)
  • Integrated with popular .NET testing frameworks (NUnit, xUnit, MSTest)
  • Supports .NET Core and .NET Framework projects

Cons of Stryker-net

  • Smaller community and fewer contributors compared to Stryker-js
  • Limited language support (only .NET languages)
  • Fewer mutation operators available

Code Comparison

Stryker-js (JavaScript):

const stryker = require('@stryker-mutator/core');
const runStryker = async () => {
  const result = await stryker.runMutationTest({
    mutate: ['src/**/*.js'],
    testRunner: 'jest'
  });
};

Stryker-net (C#):

using Stryker.Core.Initialisation;
var result = await new StrykerRunner().RunMutationTestAsync(
    new StrykerOptions
    {
        ProjectPath = "path/to/project",
        TestRunner = "dotnet"
    });

Both Stryker-js and Stryker-net are mutation testing frameworks, but they target different ecosystems. Stryker-js focuses on JavaScript and related technologies, while Stryker-net is tailored for .NET applications. The choice between them depends on the programming language and environment of your project.

PHP Mutation Testing library

Pros of Infection

  • Specifically designed for PHP, offering deep integration with PHP ecosystems
  • Supports advanced PHP features like traits and interfaces
  • Generally faster execution time for PHP projects

Cons of Infection

  • Limited to PHP projects, lacking cross-language support
  • Smaller community and ecosystem compared to Stryker
  • Less frequent updates and potentially slower bug fixes

Code Comparison

Infection (PHP):

<?php
$mutator = new PlusEqualsMutator();
$mutator->mutate($node);

Stryker (JavaScript):

const mutator = new PlusEqualsMutator();
mutator.mutate(node);

While the basic concept is similar, Infection's code is PHP-specific, whereas Stryker's JavaScript implementation can be adapted for multiple languages.

Key Differences

  • Language support: Infection focuses solely on PHP, while Stryker supports multiple languages including JavaScript, TypeScript, and C#
  • Ecosystem: Stryker has a larger community and more frequent updates
  • Performance: Infection may perform better for PHP projects due to its specialized nature
  • Flexibility: Stryker offers more options for configuration and customization across different languages and frameworks

Both tools serve the purpose of mutation testing, but the choice between them largely depends on the project's primary language and specific requirements.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Mutation testing badge Build Status NPM Node version Slack Chat

Stryker

StrykerJS

Professor X: For someone who hates mutants... you certainly keep some strange company. William Stryker: Oh, they serve their purpose... as long as they can be controlled.

Welcome to StrykerJS's monorepo. This is where all official stryker packages are maintained. If you're new to monorepos: don't be scared. You'll find the packages in the packages folder.

If you're interested in why we chose a monorepo, please read babeljs's design document about monorepos. We use it for the same reasons as they do.

Introduction

For an introduction to mutation testing and Stryker's features, see stryker-mutator.io.

Getting started

Please follow the quickstart on the website.

For small js projects, you can try the following command:

npm install --save-dev @stryker-mutator/core
# Only for small projects:
npx stryker run

It will run stryker with default values:

  • Uses npm test as your test command
  • Searches for files to mutate in the lib and src directories

Usage

$ npx stryker <command> [options] [configFile]

See usage on stryker-mutator.io

Supported mutators

See our website for the list of currently supported mutators.

Configuration

See configuration on stryker-mutator.io.

NPM DownloadsLast 30 Days