Net Possibility Multiplier

karma-typescript-plugin

0.1.2 • Public • Published

karma-typescript-plugin

npm

Yet another typescript preprocessor for Karma with coverage remap.

That's it.

Installation

npm install --save-dev karma-typescript-plugin

Dependencies

npm install --save-dev istanbul karma-coverage remap-istanbul typescript

This module has peer dependencies with other modules:

Configuration

// karma.conf.js
module.exports = function (config) {
  config.set({
    plugins: [
      'karma-typescript-plugin',
      'karma-coverage'
    ],
 
    preprocessors: {
      '**/*.ts': ['typescript', 'coverage']
    },
 
    reporters: [
      'progress',
      'coverage',
      'typescript'
    ]
  });
};

TypeScript preprocessor

The preprocessor will transpire TypeScript code on the fly. It will use the project tsconfig.json and will use AMD modules for easy integration with karma-requirejs and enables sourceMaps for code coverage.

options

All preprocessor settings are optional and default values should be ok for most of the cases.

// karma.conf.js
module.exports = function (config) {
  config.set({
    typescriptPreprocessor: {
      /**
      * Returns generated file name.
      * 
      * The file will not be saved in any moment. This is only used in the url.
      * 
      * @param string tsFilePath The original file path.
      * @returns string The generated file virtual path.
      */
      transformPath: (tsFilePath => tsFilePath.replace(/\.tsx?$/i, '.js')),
      
      /**
      * TypeScript package to use instead of project typescript package.
      */
      typescript: require('typescript'),
      
      /**
      * Override tsconfig.json compiler options.
      */
      compilerOptions: {
        //...
      }
    }
  });
};

Typescript reporter

The reporter is basically a copy of karma-remap-istanbul but will read the transpired code from a plugin internal memory cache.

install

npm i karma-typescript-plugin

Downloadsweekly downloads

4

version

0.1.2

license

MIT

repository

Gitbitbucket

last publish

collaborators

  • avatar
Report a vulnerability