{"id":11204,"library":"karma-typescript","title":"Karma TypeScript Preprocessor and Reporter","description":"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.","status":"active","version":"5.5.4","language":"javascript","source_language":"en","source_url":"https://github.com/monounity/karma-typescript","tags":["javascript","angularjs","angular2","browserify","commonjs","coverage","css modules","docker","istanbul","typescript"],"install":[{"cmd":"npm install karma-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add karma-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add karma-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency as karma-typescript is a plugin for Karma. Supports Karma versions 1 through 6.","package":"karma","optional":false},{"reason":"Required peer dependency for TypeScript compilation and type checking. Supports TypeScript versions 1 through 5.","package":"typescript","optional":false}],"imports":[{"note":"karma-typescript is configured as a framework and preprocessor, not imported directly into application code. Ensure 'karma-typescript' is included in the `frameworks` array in `karma.conf.js`.","wrong":"require('karma-typescript')","symbol":"framework","correct":"config.set({\n  frameworks: [\"jasmine\", \"karma-typescript\"],\n  // ...\n});"},{"note":"Configure karma-typescript as a preprocessor for your TypeScript files in `karma.conf.js`. This tells Karma to compile TypeScript files before tests run.","wrong":"preprocessors: { '**/*.ts': require('karma-typescript') }","symbol":"preprocessor","correct":"config.set({\n  preprocessors: {\n    \"**/*.ts\": \"karma-typescript\" // or '*.tsx' for React\n  },\n  // ...\n});"},{"note":"To enable the specialized TypeScript reporter and coverage features, include 'karma-typescript' in the `reporters` array in `karma.conf.js`.","wrong":"reporters: [\"karma-typescript-reporter\"]","symbol":"reporter","correct":"config.set({\n  reporters: [\"progress\", \"karma-typescript\"],\n  // ...\n});"}],"quickstart":{"code":"module.exports = function(config) {\n    config.set({\n        basePath: './',\n        frameworks: [\"jasmine\", \"karma-typescript\"],\n        files: [\n            \"src/**/*.ts\" // Use '*.tsx' for React projects\n        ],\n        preprocessors: {\n            \"**/*.ts\": \"karma-typescript\" // Use '*.tsx' for React projects\n        },\n        reporters: [\"progress\", \"karma-typescript\"],\n        browsers: [\"ChromeHeadless\"], // Use ChromeHeadless for CI environments\n        karmaTypescript: {\n            compilerOptions: {\n                esModuleInterop: true,\n                module: \"CommonJS\",\n                target: \"ES5\"\n            },\n            include: [\"src/**/*.ts\"],\n            exclude: [\"node_modules\"]\n        }\n    });\n};","lang":"javascript","description":"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."},"warnings":[{"fix":"Upgrade Karma to a compatible version (e.g., `npm install karma@^6 --save-dev`) and ensure `typescript` peer dependency is met. Refer to the `peerDependencies` section for exact ranges.","message":"karma-typescript versions 5.x require Karma 5.x or 6.x. Earlier versions of Karma may not be fully supported, leading to unexpected behavior or compilation issues.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Ensure you are using `karma-typescript@5.4.0` or higher to avoid issues present in version 5.3.0. Always check the latest patch releases for bug fixes.","message":"Version 5.3.0 of karma-typescript was noted as 'messed up' by the maintainer and was quickly followed by 5.4.0. Users on 5.3.0 might encounter unresolved bugs that were fixed in 5.4.0.","severity":"gotcha","affected_versions":"=5.3.0"},{"fix":"Upgrade to `karma-typescript@5.5.2` or newer to ensure the correct `acorn` dependency is available and avoid test run lockups. If issues persist, try `npm install acorn` explicitly.","message":"Missing or incompatible `acorn` dependency can cause the test run to lock or fail. This has been a recurring bug fix in recent patch versions.","severity":"gotcha","affected_versions":"<5.5.2"},{"fix":"Update to `karma-typescript@5.4.0` or newer, which includes a fix to prevent the process from being killed when coverage thresholds aren't met in `singleRun: false` mode.","message":"When `singleRun` is set to `false`, karma-typescript might still kill the process if coverage thresholds aren't met. This behavior can be unexpected during watch mode.","severity":"gotcha","affected_versions":"<5.4.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Upgrade `karma-typescript` to the latest patch release (e.g., `npm install karma-typescript@latest --save-dev`) or explicitly install `acorn`: `npm install acorn --save-dev`.","cause":"A dependency issue where the 'acorn' package, used for parsing, is not correctly resolved or installed.","error":"Error: Cannot find module 'acorn'"},{"fix":"Ensure `karma-typescript` is listed in the `frameworks` array in your `karma.conf.js`: `frameworks: [\"jasmine\", \"karma-typescript\"],`","cause":"The `karma-typescript` plugin is not correctly recognized or initialized by Karma, often due to missing `frameworks` entry.","error":"TypeError: Cannot read property 'karmaTypescript' of undefined"},{"fix":"Adjust the coverage thresholds in your `karma.conf.js` under `karmaTypescript.coverageOptions.threshold`, or set `karmaTypescript.coverageOptions.failOnThresholdNotMet: false` if you do not want failures on unmet thresholds.","cause":"The configured code coverage percentage was not reached by the tests, causing the process to terminate. This is a deliberate feature.","error":"Coverage threshold not met, exiting with error code 1."},{"fix":"Review the accompanying TypeScript error message and fix the code. Ensure your `tsconfig.json` or `karmaTypescript.compilerOptions` are correctly configured for your project.","cause":"A TypeScript compilation error occurred during the test run, indicating issues in your source or test files.","error":"TSxxxx: [TypeScript error message]"}],"ecosystem":"npm"}