Karma TypeScript Preprocessor

0.4.0 · abandoned · verified Sun Apr 19

This package, `karma-typescript-preprocessor`, provides a Karma runner plugin designed to compile TypeScript files on the fly during unit testing. It integrates directly into the Karma configuration, allowing developers to test TypeScript code without a separate, explicit compilation step prior to running tests. The package is currently at version 0.4.0, with its last update occurring approximately seven years ago. Given its age, it is no longer actively maintained and may not support recent TypeScript versions or Karma features. While it offered configurable TypeScript compiler options like `target`, `module`, and `sourceMap` directly within `karma.conf.js`, its primary differentiator was simplifying test setups by handling TypeScript compilation internally, contrasting with the more feature-rich and actively maintained `karma-typescript` package which offers bundling, coverage remapping, and broader framework support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a complete `karma.conf.js` setup for `karma-typescript-preprocessor`, including file patterns, preprocessor declaration, and custom TypeScript compiler options like `target` and `module`.

/**
 * karma.conf.js
 * Configuration for karma-typescript-preprocessor.
 */
module.exports = function(config) {
  config.set({
    // Base path that will be used to resolve all relative paths for files and exclude.
    basePath: '',

    // Frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-framework
    frameworks: ['jasmine'], // Example: using Jasmine testing framework

    // List of files / patterns to load in the browser
    files: [
      'src/**/*.ts', // Your TypeScript source files
      'test/**/*.ts' // Your TypeScript test files
    ],

    // Preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      '**/*.ts': ['typescript']
    },

    // Configuration for the TypeScript preprocessor
    typescriptPreprocessor: {
      options: {
        sourceMap: true, // (optional) Generates corresponding .map file.
        target: 'ES5',  // (optional) Specify ECMAScript target version: 'ES3' (default), or 'ES5'
        module: 'amd', // (optional) Specify module code generation: 'commonjs' or 'amd'
        noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type.
        removeComments: true // (optional) Do not emit comments to output.
      },
      // Function to transform filenames, e.g., .ts to .js
      transformPath: function(path) {
        return path.replace(/\.ts$/, '.js');
      }
    },

    // Test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],

    // Web server port
    port: 9876,

    // Enable / disable colors in the output (reporters and logs)
    colors: true,

    // Level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // Enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,

    // Start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  });
};

view raw JSON →