Registry / testing / karma-typescript

karma-typescript

JSON →
library5.5.4jsnpmunverified

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.

npm install karma-typescript
INSTALL
IMPORT
SIG · KARMA-TYPESCRIPT
K
karma-typescript
testingjavascriptv5.5.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

framework
config.set({ frameworks: ["jasmine", "karma-typescript"], // ... });
require('karma-typescript')
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`.
preprocessor
config.set({ preprocessors: { "**/*.ts": "karma-typescript" // or '*.tsx' for React }, // ... });
preprocessors: { '**/*.ts': require('karma-typescript') }
Configure karma-typescript as a preprocessor for your TypeScript files in `karma.conf.js`. This tells Karma to compile TypeScript files before tests run.
reporter
config.set({ reporters: ["progress", "karma-typescript"], // ... });
reporters: ["karma-typescript-reporter"]
To enable the specialized TypeScript reporter and coverage features, include 'karma-typescript' in the `reporters` array in `karma.conf.js`.

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"] } }); };
Debug
Known issues
breakingkarma-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.
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.
affects: >=5.0.0
gotchaVersion 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.
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.
affects: =5.3.0
gotchaMissing or incompatible `acorn` dependency can cause the test run to lock or fail. This has been a recurring bug fix in recent patch versions.
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.
affects: <5.5.2
gotchaWhen `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.
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.
affects: <5.4.0
Errors
Common errors & fixes
Error: Cannot find module 'acorn'
A dependency issue where the 'acorn' package, used for parsing, is not correctly resolved or installed.
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`.
TypeError: Cannot read property 'karmaTypescript' of undefined
The `karma-typescript` plugin is not correctly recognized or initialized by Karma, often due to missing `frameworks` entry.
fix
Ensure `karma-typescript` is listed in the `frameworks` array in your `karma.conf.js`: `frameworks: ["jasmine", "karma-typescript"],`
Coverage threshold not met, exiting with error code 1.
The configured code coverage percentage was not reached by the tests, causing the process to terminate. This is a deliberate feature.
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.
TSxxxx: [TypeScript error message]
A TypeScript compilation error occurred during the test run, indicating issues in your source or test files.
fix
Review the accompanying TypeScript error message and fix the code. Ensure your `tsconfig.json` or `karmaTypescript.compilerOptions` are correctly configured for your project.
Upgrade
Version history
5.5.4latest on npm
Audit
Dependencies
karmarequiredRequired peer dependency as karma-typescript is a plugin for Karma. Supports Karma versions 1 through 6.
typescriptrequiredRequired peer dependency for TypeScript compilation and type checking. Supports TypeScript versions 1 through 5.
Agent activity
2 hits · last 30 days
node
2
Resources
karma-typescript — npm install karma-typescript · libregistry