Karma TypeScript Preprocessor and Reporter

5.5.4 · active · verified Sun Apr 19

karma-typescript is a Karma plugin designed to simplify running unit tests for TypeScript projects. It seamlessly integrates TypeScript compilation, type checking, and test execution within the Karma test runner without requiring separate build steps. It also provides remapped test coverage reports via Istanbul, ensuring accurate coverage data even after transpilation. The current stable version is 5.5.4, with recent releases focusing on bug fixes and compatibility updates for newer versions of Karma and TypeScript. Its key differentiators include built-in type checking, automatic source map generation for debugging, and robust remapped coverage reporting, making it a comprehensive solution for testing TypeScript code.

Common errors

Warnings

Install

Imports

Quickstart

This configuration sets up Karma with Jasmine and karma-typescript to compile and run tests on TypeScript files located in the 'src' directory, producing remapped coverage reports.

module.exports = function(config) {
    config.set({
        basePath: './',
        frameworks: ["jasmine", "karma-typescript"],
        files: [
            "src/**/*.ts" // Use '*.tsx' for React projects
        ],
        preprocessors: {
            "**/*.ts": "karma-typescript" // Use '*.tsx' for React projects
        },
        reporters: ["progress", "karma-typescript"],
        browsers: ["ChromeHeadless"], // Use ChromeHeadless for CI environments
        karmaTypescript: {
            compilerOptions: {
                esModuleInterop: true,
                module: "CommonJS",
                target: "ES5"
            },
            include: ["src/**/*.ts"],
            exclude: ["node_modules"]
        }
    });
};

view raw JSON →