sergeyt / karma-typescript-preprocessor

TypeScript preprocessor for karma-runner
MIT License
50 stars 20 forks source link

err: cannot finde module (using jspm/system.js) #35

Open telekosmos opened 9 years ago

telekosmos commented 9 years ago

Hi there I am trying to use karma to unit tests an Aurelia simple application. The application files are written in typescript; not so the test files. The application files compiles ok when using tsc or a gulp task (by using gulp-typescript plugin). But when I run karma start I get several Cannot find module 'aurelia-*' errors.

The karma.conf.js file is like so:

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

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '.',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jspm', 'jasmine'],

    jspm: {
      // Edit this to your needs
      loadFiles: ['src/**/*.ts', 'test/unit/**/*.js'],
      paths: {
        '*.js': '*.js',
        '*.ts': '*.ts'
      }
    },

    // list of files / patterns to load in the browser
    files: [],
    // list of files to exclude
    exclude: [
    ],

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

    'babelPreprocessor': {
      options: {
        sourceMap: 'inline',
        modules: 'system',
        moduleIds: false,
        optional: [
          "es7.decorators",
          "es7.classProperties"
        ]
      }
    }, // EO babelPreprocessor

    'typescriptPreprocessor': {
      options: {
        sourceMap: false,
        target: "ES5",
        module: "<%= (amd)? 'amd': 'commonjs' %>",
        noImplicitAny: false,
        removeComments: true,
        noResolve: true
      },
      typings: [
        'typings/tsd.d.ts'
      ],
      // transforming the filenames
      transformPath: function(path) {
        return path.replace(/\.ts$/, '.js');
      }
    }, // EO typescriptPreprocessor

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

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

    // 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'],
    browsers: ['PhantomJS'],

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

Setting karma log to LOG_DEBUG in karma.conf.js what I get when running karma is:

$ karma start
(...)
DEBUG [preprocessor.typescript]: preprocessing "/Users/telekosmos/Sites/generators/yotest.new/src/app.ts".
ERROR [preprocessor.typescript]: /Users/telekosmos/Sites/generators/yotest.new/src/app.ts.ktp.ts(3,22): 
error TS2307: Cannot find module 'aurelia-router'.

ERROR [preprocessor.typescript]: /Users/telekosmos/Sites/generators/yotest.new/src/app.ts.ktp.ts(3,22): 
error TS2307: Cannot find module 'aurelia-router'.

/Users/telekosmos/Sites/generators/yotest.new/src/app.ts.ktp.ts(3,22): 
error TS2307: Cannot find module 'aurelia-router'.
DEBUG [preprocessor.typescript]: preprocessed "/Users/telekosmos/Sites/generators/yotest.new/src/app.ts"
(...)

More errors like this, one per typescript file, are thrown but not showed here as they are similar to this one.

I'm a bit confused as I tried several things (including globs for typings, overriding jspm files, ...) but nothing seems to work. So, may anyone provide some hint or come up with any other approach?

Thanks in advance!!!

w

sergeyt commented 8 years ago

the preprocessor is just rewritten using https://github.com/sergeyt/typescript-simple, so now it should support latest compiler with all compiler options. Please retry again.