How do I run karma / jasmine tests for an Angular 1.5.8 project that uses javascript, coffeescript, and typescript source?

140 Views Asked by At

I am working on a production system that currently uses CoffeeScript and JavaScript. We are looking to progressively migrate the source code to TypeScript in anticipation of an eventual migration to Angular 2.

I am using karma with the below karma.conf.js configuration file. As I started to add TypeScript support, I started to rapidly go down a rabbit hole of potential fixes and dead-ends. Do I need to use karma-systemjs? Can karma-systemjs handle CoffeeScript? Can karma-systemjs and browserify work together? Should I be switching to Webpack? Should I be using karma-typescript instead? If so, can it handle CoffeeScript?

The myriad options are way confusing. Any guidance would be much appreciated.

/*global module */

"use strict";

module.exports = function(config){
  config.set({

    basePath: '../',

    files : [
      'node_modules/angular/angular.js',
      'node_modules/angular-mocks/angular-mocks.js',
      'node_modules/angular-ui-bootstrap/dist/ui-bootstrap.js',
      'node_modules/angular-ui-calendar/src/calendar.js',
      'node_modules/angular-ui-grid/ui-grid.js',
      'node_modules/angular-ui-router/release/angular-ui-router.js',
      'node_modules/ui-select/dist/select.js',
      'node_modules/angular-aria/angular-aria.js',
      'node_modules/angular-animate/angular-animate.js',
      'node_modules/angular-material/angular-material.js',
      'node_modules/angular-sanitize/angular-sanitize.js',
      'node_modules/pouchdb/dist/pouchdb.js',
      'app/config/**/*.js',
      'app/source/**/*.js',
      'test/unit/**/*.js'
    ],

    autoWatch: true,

    frameworks: ['browserify', 'jasmine'],

    browsers: ['PhantomJS'],
    //browsers: ['Chrome'], // Use "Chrome" for debugging since phantomjs can swallow some errors

    plugins: [
      'karma-browserify',
      'karma-jasmine',
      'karma-phantomjs-launcher',
      'karma-chrome-launcher'
    ],

    preprocessors: {
      'app/config/**/*.js': ['browserify'],
      'app/source/**/*.js': ['browserify'],
      'test/unit/**/*.js': [ 'browserify']
    },

    browserify: {
      debug: true,
      transform: ['coffeeify', 'babelify'],
      extensions: [ ".coffee"]
    },

    // 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,

    // 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
  });
};

0

There are 0 best solutions below