Coder Social home page Coder Social logo

karma-typescript's Introduction

karma-typescript

Npm Total Downloads Npm Monthly Downloads

Deprecated

Karma has been deprecated and is not accepting new features or general bug fixes.

This means that this plugin is also deprecated.

For alternatives and rationale, please see https://github.com/karma-runner/karma#karma-is-deprecated-and-is-not-accepting-new-features-or-general-bug-fixes.

I would like to give a huge shoutout to all of you who have contributed with PR:s and comments, you've helped keeping this plugin alive for far more years than I ever thought would be possible.

Karma ❤️ Typescript

  • Run unit tests written in Typescript with full type checking, seamlessly without extra build steps or scripts.
  • Get remapped test coverage with Istanbul.
  • Use plain Typescript or a framework: Angular, AngularJS, React, Sinon, any framework of choice.

Getting Started

Install via npm:

npm install --save-dev karma-typescript

Packages

Package Version Dependencies
karma-typescript Npm Version Dependencies Status
karma-typescript-angular2-transform Npm Version Dependencies Status
karma-typescript-cssmodules-transform Npm Version Dependencies Status
karma-typescript-es6-transform Npm Version Dependencies Status
karma-typescript-postcss-transform Npm Version Dependencies Status

Contributors

Contribute

Contributing guidelines

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

© 2016-2021 Erik Barke, Monounity

karma-typescript's People

Contributors

07akioni avatar abraham avatar acolytec3 avatar adamkasztenny avatar alan-agius4 avatar cleavera avatar csvn avatar danielrentz avatar dependabot[bot] avatar devoto13 avatar erikbarke avatar fchiumeo avatar freshrob avatar g00fy- avatar glennvorhes avatar jods4 avatar leevipietilainen avatar mattwebbio avatar mitchhentges avatar monounity avatar peterblazejewicz avatar provegard avatar ryanvall avatar sedlakr avatar silkentrance avatar sir-marc avatar tokrsen avatar vidartf avatar vladjerca avatar xdamman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

karma-typescript's Issues

"non javascript content" when importing for side-effects

I'm working on turning a legacy JS project to TS and I want to integrate unit tests for the TS code using this great plugin. Unfortunately, the migration of the legacy code sometimes requires importing other modules just for side effects here and there, like import "./module"

Apparently, however, this causes the builtin compiler and bundler to generate the "non javascript content" in the bundle and hence when that module is later imported by some other module not only for side effects, the requiring module gets passed an undefined (because the dependant module has got overridden with "non javascript content") and the code terminates.

I know this is kind of an edge case, however I want to ask whether it might be easy to get fixed.

Thanks!

Karma errors when compiling using tsconfig.json with alternately mapped paths

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true,
    "noEmitHelpers": true,
    "baseUrl": "./src",
    "paths": {
      "cart/*": [ "app/cart/*" ],
      "customer/*": [ "app/customer/*" ],
      "device/*": [ "app/device/*" ],
      "services/*": [ "app/shared/services/*" ],
      "components/*": [ "app/shared/components/*" ],
      "mocks/*": [ "app/shared/mocks/*" ]
    }
  },
  "compileOnSave": false,
  "buildOnSave": false,
  "awesomeTypescriptLoaderOptions": {
    "forkChecker": true,
    "useWebpackText": true
  }
}

Console output when running NPM test

05 12 2016 14:47:11.596:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.1.1

webpack: bundle is now VALID.
webpack: bundle is now INVALID.
05 12 2016 14:47:17.320:INFO [compiler.karma-typescript]: Compiled 136 files in 4791 ms.
05 12 2016 14:47:19.749:ERROR [karma]: Error: Cannot find module 'services/api' from '/Users/pberger/Local Repo/Modesto/retail-ui/src/app'
    at Function.module.exports [as sync] (/Users/pberger/Local Repo/Modesto/retail-ui/node_modules/resolve/lib/sync.js:33:11)
    at Function.resolve.sync (/Users/pberger/Local Repo/Modesto/retail-ui/node_modules/browser-resolve/index.js:321:21)
    at resolveModules (/Users/pberger/Local Repo/Modesto/retail-ui/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:192:45)
    at /Users/pberger/Local Repo/Modesto/retail-ui/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:85:21
    at Array.forEach (native)
    at /Users/pberger/Local Repo/Modesto/retail-ui/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:81:36
    at Array.forEach (native)
    at /Users/pberger/Local Repo/Modesto/retail-ui/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:77:21
    at invokeFunc (/Users/pberger/Local Repo/Modesto/retail-ui/node_modules/lodash.debounce/index.js:160:19)
    at trailingEdge (/Users/pberger/Local Repo/Modesto/retail-ui/node_modules/lodash.debounce/index.js:207:14)
    at Timeout.timerExpired [as _onTimeout] (/Users/pberger/Local Repo/Modesto/retail-ui/node_modules/lodash.debounce/index.js:195:14)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
npm ERR! Test failed.  See above for more details.

Declarations included w/ pre processed files causes error

Hi all, using typescript 1.75 and am bumping into a weird error:

14 12 2016 11:54:10.354:ERROR [karma]: TypeError: Data must be a string or a buffer at Hash.update (crypto.js:74:16) at sha1 (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma/lib/preprocessor.js:11:8) at nextPreprocessor (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma/lib/preprocessor.js:32:18) at instrumentSource (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma-typescript/lib/preprocessor.js:110:13) at /Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma-typescript/lib/preprocessor.js:154:25 at Bundler.bundle (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:67:13) at Object.callback (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma-typescript/lib/preprocessor.js:150:29) at /Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma-typescript/lib/compiler.js:76:20 at Array.forEach (native) at /Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/karma-typescript/lib/compiler.js:66:19 at invokeFunc (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/lodash.debounce/index.js:160:19) at trailingEdge (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/lodash.debounce/index.js:207:14) at Timeout.timerExpired [as _onTimeout] (/Users/kyle/Documents/workspace/karma/DreamcatcherUX/node_modules/lodash.debounce/index.js:195:14) at ontimeout (timers.js:365:14) at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5)

This only happens when I include my declarations folder with the rest of my *.ts source. If I exclude the folder, it works, and opens phantomJS just fine. I'm on node 7.2.1.

It looks like we are passing 'undefined' to the hash.update() function in preprocessor.js. Am I supposed to exclude declaration files for karma-typescript to work? Google-fu didn't really reveal much.

Does this support JSX and *.tsx files?

Hi,

I'm running this plugin on a React/JSX project and am getting the usual "Unexpected token <" errors because TypeScript does not expect JSX tags.

Is there a way to configure the plugin to run TSX files?

feat: load the files in order of dependency when using Triple-slash reference

I have tried the branch 2.1, in order to avoid module loaders, like SystemJS. Its work pretty well, all files are compiled and loaded in the browser without any wrap code.

Now my issues is that karma loads the files apparently in alphabetical order. This causes that some files, that are dependent on other files are loaded first causing errors in run time.

Suppose we have index.ts and module.ts files, then index.ts refers to module.ts and uses some code from it.

module.ts

class Model {

}

index.ts

/// <reference path="./module.ts" />
let class = new Model();

Karma will load index.js (the compiled version of index.js) first, causing the line let class = new Model(); to thrown an error. Because the class Module isn't defined yet.

So, it is possible to resolve and load the files in order of dependency. This is something that TypeScript do when outFile compiler option is used.

Error during angular typings import

Hello,

Great project. It eliminates messing around with karma, webpack etc. Thanks.

I'm having an issue with tests for angular. I'm using @types/angular for typing declarations and I'm trying to import them in my code using the following :
import * as angular from 'angular'

But I'm getting an error that the angular module cannot be found from a directory.

This is my tsconfig compiler options which I added in karmaTypescriptConfig.tsconfig

"compilerOptions": {
        "target":"es5",
        "declaration": false,
        "noEmitOnError": true,
        "emitDecoratorMetadata":true,
        "experimentalDecorators":true,
        "sourceMap":true,
        "module":"commonjs",
        "moduleResolution": "node",
        "typeRoots": ["./node_modules/@types"]
    }

Thoughts on whats going wrong maybe?

Not working with webpack

I'm having trouble getting it to work with webpack, this is my config:

var webpackConfig = require('./webpack.config');

module.exports = function(config) {
    config.set({
        basePath: '',
        frameworks: ['mocha', 'chai', 'sinon', 'karma-typescript'],
        files: [
            { pattern: "test/**/*.ts" }
        ],
        exclude: [
        ],
        preprocessors: {
            'test/**/*.ts': ['webpack'],
            '**/*.ts': ['karma-typescript']
        },
        webpack: {
            module: webpackConfig.module,
            resolve: webpackConfig.resolve
        },
        reporters: ['progress', 'karma-typescript'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Chrome'],
        singleRun: false,
        concurrency: Infinity,
        karmaTypescriptConfig: {
            reports: {
                "text-summary": "coverage"
            }
        }
    })
}

But when I run it I get this output:

Version: webpack 1.13.3
Time: 7ms
webpack: bundle is now VALID.
13 11 2016 17:36:01.946:INFO [compiler.karma-typescript]: Compiled 7 files in 1066 ms.
13 11 2016 17:36:03.637:INFO [builtin-bundler.karma-typescript]: Bundled imports for 1 file in 123 ms.
webpack: bundle is now INVALID.
Hash: f4683f5fa2953dc3a97c
Version: webpack 1.13.3
Time: 8ms

ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' C:/Projects/test/test/main.test.js in C:\Projects\test
webpack: bundle is now VALID.

I couldn't find any reference project that is using webpack and karma-typescript.

Typescript 1.8.10

Is it possible to make it work for Typescript version 1.8? or it requires at least version 2?

When using your example settings, I cannot unit test code which uses Angular2 ?

karma.conf.js

files: [
    { pattern: "src/**/*.ts" }
],

preprocessors: {
    "**/*.ts": [ 'coverage', 'karma-typescript', 'sourcemap' ]
},

And the error message:

Chrome 53.0.2785 (Windows 10 0.0.0) ERROR
Uncaught Error: Could not find module '@angular/core' from 'C:/Github/_forks/angular2-odata/src/config.js'
at node_modules/karma-commonjs/client/commonjs_bridge.js:85

Double-printing of console log and error messages

Great package - I have only one concern, in that it appears to double-print every result, be it a simple console.log('hello') (with nothing else, just a single file without a spec) or a Typescript error (e.g. by having a single file with a single typo). Is there a reason why it would do so?

Also of note, the second result is not colored.

I'm using just the basic config from the README with nothing else in that file.

Edit: I see the same behavior with the stock example project from this repo.
Edit2: I also verified that only one browser instance is running Karma at the time.

SyntaxError: Expected token ']' - in unused interface

Hi, thats me again ;) I have another problem with your plugin (version 2.1.2). It is complicated in my application but I prepared simple example on base of your example-project.

First I define package.json...

{
  "name": "foo-project",
  "private": true,
  "license": "MIT",
  "scripts": {
    "test": "karma start karma.conf.js"
  },
  "dependencies": {
    "@types/jasmine": "^2.5.35",
    "jasmine-core": "^2.4.1",
    "karma": "^1.2.0",
    "karma-phantomjs-launcher": "1.0.2",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-typescript": "2.1.2",
    "typescript": "2.0.9"
  }
}

... and karma.conf.js:

module.exports = function(config) {
    config.set({
        frameworks: ["jasmine", "karma-typescript"],
        files: [
            { pattern: "src/**/*.ts" }
        ],
        preprocessors: {
            "**/*.ts": ["karma-typescript"]
        },
        reporters: ["progress", "karma-typescript"],
        singleRun: true,
        logLevel: config.LOG_DEBUG, //config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
        karmaTypescriptConfig: {
            compilerOptions: {
                noImplicitAny: false,
                target: 'ES5',
                module: 'amd',
                removeComments: true,
                declaration: true,
                experimentalDecorators: true
            }
        },
        browsers: ["PhantomJS"]
    });
};

Then in /src dir I create 2 files:

bar.ts:

module APP {
    export class Bar {
        public sayBar():string {
            return "bar";
        }
    }
}

bar.test.ts:

module APP {
    describe('bar', () => {
        let bar = new Bar();

        it('should say bar', () => {
            expect(bar.sayBar()).toBe('bar');
        });
    });
}

Ok, now I run npm test and everything is fine - 1 test pass and I'm happy. But then I add simple unused interface.
foo.ts:

module APP {
    export interface Foo {
        lorem:string;
    }
}

Now npm test fails with error:

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  SyntaxError: Expected token ']'
  at src/foo.js:9

Full log:

vagrant@vagrant:~/www/fooTests$ npm test

> foo-project@ test /vagrant/fooTests
> karma start karma.conf.js

13 11 2016 14:03:59.315:DEBUG [config]: autoWatch set to false, because of singleRun
13 11 2016 14:03:59.320:DEBUG [plugin]: Loading karma-* from /vagrant/fooTests/node_modules
13 11 2016 14:03:59.322:DEBUG [plugin]: Loading plugin /vagrant/fooTests/node_modules/karma-coverage.
13 11 2016 14:03:59.519:DEBUG [plugin]: Loading plugin /vagrant/fooTests/node_modules/karma-jasmine.
13 11 2016 14:03:59.520:DEBUG [plugin]: Loading plugin /vagrant/fooTests/node_modules/karma-phantomjs-launcher.
13 11 2016 14:03:59.572:DEBUG [plugin]: Loading plugin /vagrant/fooTests/node_modules/karma-typescript.
13 11 2016 14:03:59.744:DEBUG [framework.karma-typescript]: Fallback to default compiler options:  { emitDecoratorMetadata: true,
  experimentalDecorators: true,
  jsx: 'react',
  module: 'commonjs',
  sourceMap: true,
  target: 'ES5' }
13 11 2016 14:03:59.762:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.9
13 11 2016 14:03:59.766:DEBUG [web-server]: Instantiating middleware
13 11 2016 14:03:59.779:DEBUG [reporter]: Trying to load reporter: karma-typescript
13 11 2016 14:03:59.780:DEBUG [reporter]: Trying to load color-version of reporter: karma-typescript (karma-typescript_color)
13 11 2016 14:03:59.780:DEBUG [reporter]: Couldn't load color-version.
13 11 2016 14:03:59.804:DEBUG [preprocessor.karma-typescript]: Processing "/vagrant/fooTests/src/bar.test.ts".
13 11 2016 14:03:59.805:DEBUG [preprocessor.karma-typescript]: Processing "/vagrant/fooTests/src/foo.ts".
13 11 2016 14:03:59.805:DEBUG [preprocessor.karma-typescript]: Processing "/vagrant/fooTests/src/bar.ts".
13 11 2016 14:04:00.312:DEBUG [compiler.karma-typescript]: Reading: /vagrant/fooTests/src/bar.test.ts
13 11 2016 14:04:00.327:DEBUG [compiler.karma-typescript]: Reading: /vagrant/fooTests/src/bar.ts
13 11 2016 14:04:00.331:DEBUG [compiler.karma-typescript]: Reading: /vagrant/fooTests/src/foo.ts
13 11 2016 14:04:00.337:DEBUG [compiler.karma-typescript]: Reading: /vagrant/fooTests/node_modules/@types/jasmine/index.d.ts
13 11 2016 14:04:00.369:DEBUG [compiler.karma-typescript]: Reading: /vagrant/fooTests/node_modules/typescript/lib/lib.d.ts
13 11 2016 14:04:01.996:INFO [compiler.karma-typescript]: Compiled 3 files in 1689 ms.
13 11 2016 14:04:02.120:DEBUG [preprocessor.karma-typescript]: Excluding file /vagrant/fooTests/src/bar.test.ts from instrumentation, done
13 11 2016 14:04:02.121:DEBUG [preprocessor.coverage]: Processing "/vagrant/fooTests/src/foo.ts".
13 11 2016 14:04:02.122:DEBUG [preprocessor.coverage]: Enabling source map generation for "/vagrant/fooTests/src/foo.ts".
13 11 2016 14:04:02.143:DEBUG [preprocessor.coverage]: Processing "/vagrant/fooTests/src/bar.ts".
13 11 2016 14:04:02.143:DEBUG [preprocessor.coverage]: Enabling source map generation for "/vagrant/fooTests/src/bar.ts".
13 11 2016 14:04:02.162:DEBUG [preprocessor.coverage]: Adding source map to instrumented file for "/vagrant/fooTests/src/bar.ts".
13 11 2016 14:04:02.186:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
13 11 2016 14:04:02.187:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
13 11 2016 14:04:02.196:INFO [launcher]: Starting browser PhantomJS
13 11 2016 14:04:02.197:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-28212737
13 11 2016 14:04:02.202:DEBUG [launcher]: /vagrant/fooTests/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs /tmp/karma-28212737/capture.js
13 11 2016 14:04:02.281:DEBUG [web-server]: serving: /vagrant/fooTests/node_modules/karma/static/client.html
13 11 2016 14:04:02.300:DEBUG [web-server]: serving: /vagrant/fooTests/node_modules/karma/static/karma.js
13 11 2016 14:04:02.374:DEBUG [karma]: A browser has connected on socket /#AL7fDFu3ptJcZr6xAAAA
13 11 2016 14:04:02.381:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=AL7fDFu3ptJcZr6xAAAA
13 11 2016 14:04:02.434:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#AL7fDFu3ptJcZr6xAAAA with id 28212737
13 11 2016 14:04:02.435:DEBUG [launcher]: PhantomJS (id 28212737) captured in 0.247 secs
13 11 2016 14:04:02.445:DEBUG [phantomjs.launcher]: 

13 11 2016 14:04:02.447:DEBUG [middleware:karma]: custom files null null
13 11 2016 14:04:02.447:DEBUG [middleware:karma]: Serving static request /context.html
13 11 2016 14:04:02.450:DEBUG [web-server]: serving: /vagrant/fooTests/node_modules/karma/static/context.html
13 11 2016 14:04:02.455:DEBUG [middleware:source-files]: Requesting /absolute/tmp/tmp-6941pTGqMjLFriAN.tmp?da39a3ee5e6b4b0d3255bfef95601890afd80709 /
13 11 2016 14:04:02.456:DEBUG [middleware:source-files]: Fetching /tmp/tmp-6941pTGqMjLFriAN.tmp
13 11 2016 14:04:02.457:DEBUG [middleware:source-files]: Requesting /base/src/bar.js?943624c858a47392c4654adcf91683edb98c5df9 /
13 11 2016 14:04:02.458:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/src/bar.js
13 11 2016 14:04:02.458:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7975a273517f1eb29d7bd018790fd4c7b9a485d5 /
13 11 2016 14:04:02.459:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/node_modules/karma-jasmine/lib/adapter.js
13 11 2016 14:04:02.460:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d /
13 11 2016 14:04:02.460:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
13 11 2016 14:04:02.460:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
13 11 2016 14:04:02.461:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/node_modules/karma-jasmine/lib/boot.js
13 11 2016 14:04:02.461:DEBUG [web-server]: serving (cached): /vagrant/fooTests/src/bar.js
13 11 2016 14:04:02.463:DEBUG [web-server]: serving (cached): /vagrant/fooTests/node_modules/karma-jasmine/lib/adapter.js
13 11 2016 14:04:02.464:DEBUG [web-server]: serving (cached): /vagrant/fooTests/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
13 11 2016 14:04:02.466:DEBUG [web-server]: serving (cached): /vagrant/fooTests/node_modules/karma-jasmine/lib/boot.js
13 11 2016 14:04:02.468:DEBUG [middleware:source-files]: Requesting /base/src/bar.test.js?a9d8d60f1d8d6df55939e81f50d8a94bf664c2f7 /
13 11 2016 14:04:02.469:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/src/bar.test.js
13 11 2016 14:04:02.469:DEBUG [middleware:source-files]: Requesting /base/src/foo.js?841da60c3d61fe8f33c0f0f272689d6ea366ef6e /
13 11 2016 14:04:02.470:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/src/foo.js
13 11 2016 14:04:02.471:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js?963392d0f4120a977206776fcd8ef0004a4bb2a2 /
13 11 2016 14:04:02.472:DEBUG [middleware:source-files]: Fetching /vagrant/fooTests/node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js
13 11 2016 14:04:02.473:DEBUG [web-server]: serving (cached): /vagrant/fooTests/src/bar.test.js
13 11 2016 14:04:02.474:DEBUG [web-server]: serving (cached): /vagrant/fooTests/src/foo.js
13 11 2016 14:04:02.475:DEBUG [web-server]: serving (cached): /vagrant/fooTests/node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js
13 11 2016 14:04:02.478:DEBUG [web-server]: serving: /vagrant/fooTests/node_modules/karma/static/context.js
13 11 2016 14:04:02.485:DEBUG [web-server]: serving: /tmp/tmp-6941pTGqMjLFriAN.tmp
13 11 2016 14:04:02.499:WARN [reporter]: SourceMap position not found for trace: undefined
13 11 2016 14:04:02.500:WARN [reporter]: SourceMap position not found for trace: undefined
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  SyntaxError: Expected token ']'
  at src/foo.js:9


13 11 2016 14:04:02.537:DEBUG [karma]: Run complete, exiting.
13 11 2016 14:04:02.538:DEBUG [launcher]: Disconnecting all browsers
13 11 2016 14:04:02.544:DEBUG [launcher]: Process PhantomJS exited with code 0
13 11 2016 14:04:02.545:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-28212737
13 11 2016 14:04:02.550:DEBUG [launcher]: Finished all browsers
npm ERR! Test failed.  See above for more details.

How to test single file without CommonJS wrapping code

I am working with Typescript files that doesn't export anything. Just flat codes that runs in the global namespace. When I run my tests (also written in TypeScript) karma-typescript output a wrapped code and the test is unable to find the global declared variables, functions, etc.

Is there a way to use this plugin with TypeScript code that doesn't need CommonJS or just use namespaces? Like:

namespace MyNameSpace {

}

I am trying to make a library with Typescript, without using SystemJS or other module loaders.

Loading the SystemJS vs. CommonJS style is causing issues with momentJS

Hi, we're using Moment in a project.

If we want it to not throw errors in our application, we use import moment from 'moment' and be done with it.

This will cause errors on the karma-typescript runner with errors like:
search/search.component.ts(5,8): error TS1192: Module ''moment'' has no default export.

When we change it to import * as moment from 'moment', suddenly all tests run but the application throws errors when we try to use anything related with moment. Basically saying it cannot be found and it doesn't have any exported members.

I've been tinkering around with the karma.conf.js to try and instruct the Karma-Typescript part to handle import moment from 'moment' the same way the SystemJS is doing right now, but up until no luck.

Any suggestions?

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

    frameworks: ["jasmine", "karma-typescript"],
    logLevel: config.LOG_INFO,

    files: [
      {pattern: 'app/assets/base.spec.ts'},
      {pattern: "app/assets/**/*.ts"}
    ],

    exclude: [
      "node_modules",
      "target/node-modules/webjars/",
      "node-modules"
    ],

    map: [
      {'moment': 'node_modules/moment/moment.js' }
    ],


    preprocessors: {
      "app/assets/**/*.ts": ["karma-typescript"]
    },

    exclude: [
      'app/assets/main.ts'
    ],

    reporters: ["progress", "karma-typescript"],

    karmaTypescriptConfig: {
      tsconfig: './tsconfig.json',
      compilerOptions: {
        inlineSourceMap: true,
        module: "commonjs" // overrides tsconfig
      },
      exclude: ["broken"],
      bundlerOptions: {
        ignoredModuleNames: ["react/addons"],
      },
      disableCodeCoverageInstrumentation: false,
      excludeFromCoverage: /\.(d|spec|test)\.ts/,
      remapOptions: {
        warn: function(message){
          console.log(message);
        }
      },
      reports:
      {
        "html": "coverage",
        "text-summary": ""
      },
      transformPath: function(filepath) {
        return filepath.replace(/\.(ts|tsx)$/, ".js");
      }
    },

    coverageReporter: {
      type : 'html',
      dir : 'coverage/'
    },

    browsers: ["Chrome"]
  });
};

TypeError: Cannot read property 'options' of undefined

I'm trying out karma-typescript for the first time, and I have a pretty vanilla setup in my karma.conf.js:

module.exports = function (config) {
  config.set({
    autoWatch: true,
    colors: true,
    files: [
      { pattern: 'test/**/*.spec.ts' }
    ],
    frameworks: ['mocha', 'chai'],
    plugins : [
      'karma-mocha',
      'karma-chai',
      'karma-typescript'
    ],
    preprocessors: {
      '**/*.ts': ['karma-typescript']
    },
    reporters: ['progress', 'karma-typescript']
  });
};

However, this crashes right out of the gate with this error:

22 12 2016 07:18:47.301:ERROR [karma]: TypeError: Cannot read property 'options' of undefined
    at emit (C:\Repos\structured-log\node_modules\karma-typescript\lib\compiler.js:165:54)
    at C:\Repos\structured-log\node_modules\karma-typescript\lib\compiler.js:63:9
    at invokeFunc (C:\Repos\structured-log\node_modules\lodash.debounce\index.js:160:19)
    at trailingEdge (C:\Repos\structured-log\node_modules\lodash.debounce\index.js:207:14)
    at Timeout.timerExpired [as _onTimeout] (C:\Repos\structured-log\node_modules\lodash.debounce\index.js:195:14)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

I'm using the following versions:

  • node 6.9.1
  • typescript 2.1.4
  • karma 1.3.0
  • karma-typescript 2.1.5

Is this a bug, or have I misconfigured anything? From looking at the source, it seems as the crash happens when it tries to read the tsconfig. I do have a tsconfig.json present. I tried setting it explicitly through the karmaTypescriptConfig as well, but that didn't make any difference.

Error: No provider for "framework:karma-typescript"!

Hi,

I get the following error when using karma-typescript starting at version v2.1.0. This bug does not occur when using the version at commit number 59d06b2050f3073d545edc25a5c5b11ab9de25e7 which is how I am currently working around this bug.
I'm using exactly the config provided in the examples and since it works with an older commit, I can only assume some breaking change went unnoticed betweem 59d06 and v2.1.0

Setup:

MacOSX 10.11.6
nodejs: v4.5.0
npm: 2.15.9
karma: 1.3.0

error:

[12:27:19] Error: No provider for "framework:karma-typescript"! (Resolving: framework:karma-typescript)
    at error (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/node_modules/di/lib/injector.js:22:12)
    at Object.parent.get (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/node_modules/di/lib/injector.js:9:13)
    at get (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/node_modules/di/lib/injector.js:54:19)
    at /Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/lib/server.js:143:20
    at Array.forEach (native)
    at Server._start (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/lib/server.js:142:21)
    at invoke (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/node_modules/di/lib/injector.js:75:15)
    at Server.start (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/karma/lib/server.js:103:18)
    at Gulp.<anonymous> (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/gulpfile.js:304:12)
    at module.exports (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /Users/hadrienmilano/appdy/codebase/eum/synthetic/synthetic-shepherd-webui/node_modules/gulp/bin/gulp.js:129:20
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickCallback (node.js:349:13)

RangeError Maximum call stack size exceeded

I've started using karma-typescript. Much cleaner than using 'istanbul' directly.
But I keep hitting the following error

 karma start --singleRun true

13 11 2016 09:33:49.434:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.9
13 11 2016 09:33:53.742:INFO [compiler.karma-typescript]: Compiled 57 files in 3732 ms.
13 11 2016 09:33:57.330:ERROR [karma]: RangeError: Maximum call stack size exceeded
    at RegExp.exec (native)
    at RegExp.test (native)
    at Parser.pp.canInsertSemicolon (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:566:17)
    at Parser.pp$3.parseExprAtom (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1775:31)
    at Parser.pp$3.parseExprSubscripts (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1715:21)
    at Parser.pp$3.parseMaybeUnary (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOps (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1637:21)
    at Parser.pp$3.parseMaybeConditional (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1597:21)
    at Parser.pp$3.parseExprList (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:2165:22)
    at Parser.pp$3.parseSubscripts (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1741:35)
    at Parser.pp$3.parseExprSubscripts (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1718:17)
    at Parser.pp$3.parseMaybeUnary (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1692:19)
    at Parser.pp$3.parseExprOp (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1656:43)
    at Parser.pp$3.parseExprOps (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1639:17)
    at Parser.pp$3.parseMaybeConditional (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1620:21)
    at Parser.pp$3.parseMaybeAssign (/Users/joost1/source/typescript-react-redux-example/node_modules/detective/node_modules/acorn/dist/acorn.js:1597:21)

I'm on OS X (Darwin 16.1.0). I upgraded to node 7.1.0 but that didn't fix it.
I traced the error through acorn > detective > module-deps > browserify > karma-typescript. The versions of karma-typescript I've tried are 2.1.2 and 2.1.1.

You can find the project here.

ERROR [compiler.karma-typescript] however Karma doesn't fail

Whenever there's a compilation error, eg:

ERROR [compiler.karma-typescript]: src/hello.component.ts(9,16): error TS2322: Type 'string' is not assignable to type 'void'.

Karma should fail too. Instead, it continues and tests may pass even if there are TypeScript compilation errors.

Is there any way to avoid this behaviour?

Example output:

16 11 2016 13:50:33.253:ERROR [compiler.karma-typescript]: src/hello.component.ts(9,16): error TS2322: Type 'string' is not assignable to type 'void'.

16 11 2016 13:50:33.259:INFO [compiler.karma-typescript]: Compiled 3 files in 1160 ms.
16 11 2016 13:50:33.761:INFO [builtin-bundler.karma-typescript]: Bundled imports for 1 file in 0 ms.
16 11 2016 13:50:33.762:INFO [watcher]: Changed file "/Users/miszy/htdocs/karma-typescript/example-project/src/hello.component.ts".
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 SUCCESS (0.003 secs / 0.001 secs)

Can not load karma-typescript, it is not registered

For versions 2.0.4 and 2.0.5 i get this error when starting karma
image

This doesn't happen for versions <= 2.0.3

Also if I change the files and have autowatch :true , the files aren't loaded anew but stay the same, so i need to close the karma and rerun it

Thanks!

Issue Importing External Modules

Hi there. I've had some issues getting this set up with my project. I've seen similar issues to the one I'm having but none of the suggestions seem to work for me.

Here's the error I'm getting:

12 12 2016 16:17:43.442:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.1.4
12 12 2016 16:17:48.493:INFO [compiler.karma-typescript]: Compiled 19 files in 4392 ms.
12 12 2016 16:17:50.662:INFO [builtin-bundler.karma-typescript]: Bundled imports for 18 file(s) in 1644 ms.
12 12 2016 16:17:50.993:WARN [karma]: No captured browser, open http://localhost:9876/
12 12 2016 16:17:51.003:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
12 12 2016 16:17:51.004:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
12 12 2016 16:17:51.041:INFO [launcher]: Starting browser PhantomJS
12 12 2016 16:17:51.487:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#43zUcKqnejEGdiWSAAAA with id 4536780
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  Error: Could not find module 
  
  './splice' from
  
  '/var/www/front-end/node_modules/redux-form/lib/structure/plain' using paths
  
  [./splice]
  [/var/www/front-end/node_modules/redux-form/lib/structure/splice]
  [/var/www/front-end/node_modules/redux-form/lib/structure/splice.js]
  [/var/www/front-end/node_modules/redux-form/lib/structure/spliceindex.js]
  [/var/www/front-end/node_modules/redux-form/lib/structure/splice/index.js]
  
  at node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js:51

I was including chai for expect() and that was giving similar issues, so I removed that and started getting the above.

Here's my tsconfig.json:

{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "es5",
        "jsx": "react",
        "baseUrl": ".",
        "typeRoots": ["./node_modules/@types"],
        "paths": {
            "*": ["src/typings/"]
        }
    },
    "filesGlob": [
        "src/**/*.ts",
        "src/**/*.tsx",
        "src/*.ts",
        "src/*.tsx"
    ],
    "exclude": [
        "node_modules"
    ]
}

And my karma.conf.js:

var webpackConfig = require("./webpack.config.js");

module.exports = function (config) {
    config.set({
        basePath: "",
        frameworks: [
            "mocha",
            "chai",
            "sinon",
            "phantomjs-shim",
            "karma-typescript"
        ],

        files: [
            "src/**/*.ts",
            "src/**/*.tsx"
        ],
        exclude: [
        ],

        preprocessors: {
            "src/**/*.{ts,tsx}": ["karma-typescript"]
        },

        karmaTypescriptConfig: {
            tsconfig: "./tsconfig.json",
            excludeFromCoverage: /(d|spec|test)\.ts/
        },

        reporters: ["progress", "karma-typescript"],

        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ["PhantomJS"],
        singleRun: false,
        concurrency: Infinity
    });
}

I'm using node version 6.9.1.

Thanks!

Debugger steps into instrumented version of non-spec code

tl;dr: Chrome debugger uses instrumented version of non-spec code instead of original TypeScript code. How can I disable instrumentation during debugging of tests?

I created an example of the problem in my own branch: https://github.com/VilleSalonen/karma-typescript/tree/broken-example

Preliminary steps:

git clone https://github.com/VilleSalonen/karma-typescript.git
cd karma-typescript
git checkout broken-example
cd example-project
npm install
npm test

Open Debug view of Karma, navigate to hello.component.ts and set breakpoints on lines 14 and 15:

image

Refresh the page and step into log1 function on line 14. log1 is imported from non-spec file example1.ts so it has been instrumented. Chrome steps into the instrumented version of the code:

image

However if you step into log2 function on line 15, you get the original TypeScript code. log2 is imported from example2.spec.ts so it has not been instrumented:

image

Never ending command when there is no matched files

Hi!
I have some trouble with karma-typescript. It works perfectly fine until there is a mistake in the test or there is no files that match file-path pattern and lib can't create coverage.

Scenario

  • Download karma-typescript v2.0.9
  • Enter to example_project dir
  • Change package.json (added karma-phantomjs-launcher):
{
  "name": "karma-typescript-example-project",
  "version": "1.0.0",
  "description": "",
  "author": "monounity",
  "contributors": [
    {
      "name": "erikbarke"
    }
  ],
  "private": true,
  "license": "MIT",
  "scripts": {
    "test": "karma start karma.conf.js",
    "dev": "clear && rm -rf coverage && cp ../index.js node_modules/karma-typescript && cp -R ../lib/* node_modules/karma-typescript/lib/ && karma start"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.31",
    "jasmine-core": "^2.4.1",
    "karma": "^1.2.0",
    "karma-phantomjs-launcher": "1.0.2",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-typescript": "../",
    "typescript": "^1.8.10"
  }
}
  • Change karma.conf.js (changed browser to PhantomJS, add singleRun and change pattern)
module.exports = function(config) {
    config.set({
        frameworks: ["jasmine", "karma-typescript"],
        files: [
            { pattern: "foo/**/*.ts" }
        ],
        preprocessors: {
            "**/*.ts": ["karma-typescript"]
        },
        reporters: ["progress", "karma-typescript"],
        singleRun: true,
        browsers: ["PhantomJS"]
    });
};
  • run karma start karma.conf.js

What happend?

What is obviously there is no files that match pattern - I'm getting the error PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.028 secs / 0 secs, but command doesn't stop. When I'm trying to kill this by ctrl+c, I'm getting 31 10 2016 22:06:18.602:DEBUG [launcher]: Disconnecting all browsers info (when log.debug is turned on). I have to kill node process. The same thing is happening when I have some mistakes in my tests and coverage can't be generated.
Jakub Górowski

My platform

  • Vagrant 1.8.1 with bento/ubuntu-15.04 box
  • Host system: Mint 18
  • NodeJS v5.10 (I can't install 6.x on Ubuntu 15.04)
  • NPM 3.8.3

Log with debug mode

vagrant@vagrant:~/www/node_modules/karma-typescript/example-project$ karma start karma.conf.js 
31 10 2016 22:03:31.081:DEBUG [plugin]: Loading karma-* from /vagrant/node_modules/karma-typescript/example-project/node_modules
31 10 2016 22:03:31.086:DEBUG [plugin]: Loading plugin /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-commonjs.
31 10 2016 22:03:31.088:DEBUG [plugin]: Loading plugin /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-coverage.
31 10 2016 22:03:31.299:DEBUG [plugin]: Loading plugin /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-jasmine.
31 10 2016 22:03:31.301:DEBUG [plugin]: Loading plugin /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-phantomjs-launcher.
31 10 2016 22:03:31.333:DEBUG [plugin]: Loading plugin /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-typescript.
31 10 2016 22:03:31.496:INFO [preprocessor.karma-typescript]: Using Typescript 2.0.6
31 10 2016 22:03:31.504:DEBUG [web-server]: Instantiating middleware
31 10 2016 22:03:31.521:DEBUG [reporter]: Trying to load reporter: karma-typescript
31 10 2016 22:03:31.523:DEBUG [reporter]: Trying to load color-version of reporter: karma-typescript (karma-typescript_color)
31 10 2016 22:03:31.523:DEBUG [reporter]: Couldn't load color-version.
31 10 2016 22:03:31.539:WARN [watcher]: Pattern "/vagrant/node_modules/karma-typescript/example-project/srac/**/*.ts" does not match any file.
31 10 2016 22:03:31.549:DEBUG [preprocessor.commonjs]: Configured root path for modules "/vagrant/node_modules/karma-typescript/example-project/node_modules".
31 10 2016 22:03:31.549:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Processing style loader dummy /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-typescript/lib/style/loader.js
31 10 2016 22:03:31.562:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Adding dummy modules for /vagrant/node_modules/karma-typescript/example-project/coverage/PhantomJS 2.1.1 (Linux 0.0.0)/html/base.css
31 10 2016 22:03:31.563:DEBUG [preprocessor.commonjs]: Processing "/vagrant/node_modules/karma-typescript/example-project/coverage/PhantomJS 2.1.1 (Linux 0.0.0)/html/base.css".
31 10 2016 22:03:31.563:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Adding dummy modules for /vagrant/node_modules/karma-typescript/example-project/coverage/PhantomJS 2.1.1 (Linux 0.0.0)/html/prettify.css
31 10 2016 22:03:31.563:DEBUG [preprocessor.commonjs]: Processing "/vagrant/node_modules/karma-typescript/example-project/coverage/PhantomJS 2.1.1 (Linux 0.0.0)/html/prettify.css".
31 10 2016 22:03:31.564:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Adding dummy modules for /vagrant/node_modules/karma-typescript/example-project/src/style/css.css
31 10 2016 22:03:31.564:DEBUG [preprocessor.commonjs]: Processing "/vagrant/node_modules/karma-typescript/example-project/src/style/css.css".
31 10 2016 22:03:31.564:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Adding dummy modules for /vagrant/node_modules/karma-typescript/example-project/src/style/less.less
31 10 2016 22:03:31.564:DEBUG [preprocessor.commonjs]: Processing "/vagrant/node_modules/karma-typescript/example-project/src/style/less.less".
31 10 2016 22:03:31.565:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Adding dummy modules for /vagrant/node_modules/karma-typescript/example-project/src/style/sass.sass
31 10 2016 22:03:31.566:DEBUG [preprocessor.commonjs]: Processing "/vagrant/node_modules/karma-typescript/example-project/src/style/sass.sass".
31 10 2016 22:03:31.566:DEBUG [preprocessor.karma-typescript-style-preprocessor]: Adding dummy modules for /vagrant/node_modules/karma-typescript/example-project/src/style/scss.scss
31 10 2016 22:03:31.566:DEBUG [preprocessor.commonjs]: Processing "/vagrant/node_modules/karma-typescript/example-project/src/style/scss.scss".
31 10 2016 22:03:31.575:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
31 10 2016 22:03:31.576:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
31 10 2016 22:03:31.584:INFO [launcher]: Starting browser PhantomJS
31 10 2016 22:03:31.585:DEBUG [temp-dir]: Creating temp dir at /tmp/karma-58013638
31 10 2016 22:03:31.589:DEBUG [launcher]: /vagrant/node_modules/karma-typescript/example-project/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs /tmp/karma-58013638/capture.js
31 10 2016 22:03:31.663:DEBUG [web-server]: serving: /vagrant/node_modules/karma-typescript/example-project/node_modules/karma/static/client.html
31 10 2016 22:03:31.680:DEBUG [web-server]: serving: /vagrant/node_modules/karma-typescript/example-project/node_modules/karma/static/karma.js
31 10 2016 22:03:31.750:DEBUG [karma]: A browser has connected on socket /#bEt4NX6d5Wjo5le6AAAA
31 10 2016 22:03:31.756:DEBUG [web-server]: upgrade /socket.io/?EIO=3&transport=websocket&sid=bEt4NX6d5Wjo5le6AAAA
31 10 2016 22:03:31.810:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket /#bEt4NX6d5Wjo5le6AAAA with id 58013638
31 10 2016 22:03:31.811:DEBUG [launcher]: PhantomJS (id 58013638) captured in 0.234 secs
31 10 2016 22:03:31.820:DEBUG [phantomjs.launcher]: 

31 10 2016 22:03:31.821:DEBUG [middleware:karma]: custom files null null
31 10 2016 22:03:31.822:DEBUG [middleware:karma]: Serving static request /context.html
31 10 2016 22:03:31.823:DEBUG [web-server]: serving: /vagrant/node_modules/karma-typescript/example-project/node_modules/karma/static/context.html
31 10 2016 22:03:31.828:DEBUG [middleware:source-files]: Requesting /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?916005cc407925f4764668d61d04888d59258f5d /
31 10 2016 22:03:31.830:DEBUG [middleware:source-files]: Fetching /vagrant/node_modules/karma-typescript/example-project/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
31 10 2016 22:03:31.831:DEBUG [web-server]: serving (cached): /vagrant/node_modules/karma-typescript/example-project/node_modules/jasmine-core/lib/jasmine-core/jasmine.js
31 10 2016 22:03:31.833:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e /
31 10 2016 22:03:31.833:DEBUG [middleware:source-files]: Fetching /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-jasmine/lib/boot.js
31 10 2016 22:03:31.834:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-jasmine/lib/adapter.js?7975a273517f1eb29d7bd018790fd4c7b9a485d5 /
31 10 2016 22:03:31.834:DEBUG [middleware:source-files]: Fetching /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-jasmine/lib/adapter.js
31 10 2016 22:03:31.834:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-typescript/lib/style/loader.js?2b1c135b955e134de02687282f31d11b4fef26fa /
31 10 2016 22:03:31.835:DEBUG [middleware:source-files]: Fetching /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-typescript/lib/style/loader.js
31 10 2016 22:03:31.835:DEBUG [middleware:source-files]: Requesting /base/node_modules/karma-commonjs/client/commonjs_bridge.js?3ffaad19615c0ece301fbf07794b83488c0f7851 /
31 10 2016 22:03:31.835:DEBUG [middleware:source-files]: Fetching /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-commonjs/client/commonjs_bridge.js
31 10 2016 22:03:31.836:DEBUG [web-server]: serving (cached): /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-jasmine/lib/boot.js
31 10 2016 22:03:31.837:DEBUG [web-server]: serving (cached): /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-jasmine/lib/adapter.js
31 10 2016 22:03:31.838:DEBUG [web-server]: serving (cached): /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-typescript/lib/style/loader.js
31 10 2016 22:03:31.839:DEBUG [web-server]: serving (cached): /vagrant/node_modules/karma-typescript/example-project/node_modules/karma-commonjs/client/commonjs_bridge.js
31 10 2016 22:03:31.840:DEBUG [web-server]: serving: /vagrant/node_modules/karma-typescript/example-project/node_modules/karma/static/context.js
PhantomJS 2.1.1 (Linux 0.0.0): Executed 0 of 0 ERROR (0.033 secs / 0 secs)
31 10 2016 22:03:31.890:DEBUG [karma]: Run complete, exiting.
31 10 2016 22:03:31.892:DEBUG [launcher]: Disconnecting all browsers
31 10 2016 22:03:31.897:DEBUG [launcher]: Process PhantomJS exited with code 0
31 10 2016 22:03:31.897:DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-58013638
31 10 2016 22:03:31.902:DEBUG [launcher]: Finished all browsers
^C31 10 2016 22:03:46.495:DEBUG [launcher]: Disconnecting all browsers
^Z

Custom typescript compiler options - paths mapping

It may be hard - as it has to do more with commonjs - but it would be nice to be able to customize compiler options features - especially for paths mapping

{
  "baseUrl": "./app",
  "paths": {
    "@app/*": [
      "./*"
    ]
  }
}

karma-typescript/example-project/ Fails

log.txt

See the attached log file.
The cause is missing dependent modules, starting with 'browser-resolve'.
I was able to get it working by doing the following npm installs. It would be helpful to include these steps in the instructions.

$ npm install --save-dev browser-resolve
$ npm install --save-dev detective
$ npm install --save-dev buffer
$ npm install --save-dev process

Error : Cannot find module 'source-map/lib/source-map-consumer' ???

16 09 2016 21:32:55.789:DEBUG [plugin]: Loading karma-* from c:\angular2-odata\node_modules
16 09 2016 21:32:55.799:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-chrome-launcher.
16 09 2016 21:32:55.812:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-commonjs.
16 09 2016 21:32:55.814:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-coverage.
16 09 2016 21:32:56.186:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-electron-launcher.
16 09 2016 21:32:56.199:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-jasmine.
16 09 2016 21:32:56.202:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-mocha.
16 09 2016 21:32:56.211:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-mocha-reporter.
16 09 2016 21:32:56.227:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-sauce-launcher.
16 09 2016 21:32:56.630:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-sourcemap-loader.
16 09 2016 21:32:56.639:DEBUG [plugin]: Loading plugin c:\angular2-odata\node_modules/karma-typescript.
16 09 2016 21:32:56.830:ERROR [plugin]: Error during loading "c:\angular2-odata\node_modules/karma-typescript" plugin:
Cannot find module 'source-map/lib/source-map-consumer'
16 09 2016 21:32:56.834:DEBUG [karma]: Registered a load error of type plug_in with name c:\angular2-odata\node_modules/karma-typescript

`require`d JSON breaks test

Having a line like

const data = require('path/to/data.json');

will give an error during testing:

Chrome 55.0.2883 (Windows 10 0.0.0) ERROR
  Uncaught SyntaxError: Unexpected token m in JSON at position 2
  at http://localhost:9876/context.html:2

See test repo: https://github.com/vidartf/karma-ts-test/tree/json
Travis showing error: https://travis-ci.org/vidartf/karma-ts-test/jobs/182115047
Appveyor showing other error: https://ci.appveyor.com/project/vidartf/karma-ts-test/build/job/nbrb4s84k4ap2nta

browserify trying to include dev dependencies

As browserify and some other npm modules don't go along (looking at websocket 1.0.1) there needs to be a way of ignoring certain modules to not be required/bundled.

As it happens now, for some reason, karma-typescript is trying to require a devDependency from ws (which, it shouldn't to be fair, but it is).

People over at WS claim that bundlers should...

learn how to ignore optional dependencies instead of forcing packages to become compatible the build systems.

While a bit pricky, it does make some sense.
SocketIO-Client managed to "fix" this by saying to webpack/browserify "ignore ws" (more on this issue)
It would be nice if we could control that as well.

Logs:

19 12 2016 14:29:55.948:ERROR [karma]: Error: Cannot find module 'utf-8-validate' from 'c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\ws\lib'
    at Function.module.exports [as sync] (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\browser-resolve\node_modules\resolve\lib\sync.js:33:11)
    at Function.resolve.sync (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\browser-resolve\index.js:321:21)
    at resolve (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:226:50)
    at resolveModules (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:205:9)
    at c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:244:28
    at Array.forEach (native)
    at addDependencies (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:242:27)
    at resolveModules (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:217:9)
    at c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:244:28
    at Array.forEach (native)
    at addDependencies (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:242:27)
    at resolveModules (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:217:9)
    at c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:244:28
    at Array.forEach (native)
    at addDependencies (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:242:27)
    at resolveModules (c:\Users\Mosh Mage\WebstormProjects\rxjs-SocketIO-client\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:217:9)

utf-8-validate isn't installed in node_modules because itself is a binary DEV dependency of the ws module. Why we are trying to include it in our build is beyond me.

You can get a fresh look at it this branch via karma start

Running karma-typescript in Angular2 using TestBed throws "Platform with a different configuration has been created."

Tried this with the @latest integration example as can be found here:
https://github.com/monounity/karma-typescript/tree/master/integration-tests%40latest/src/angular2

Tried it in a semi clean "default" project (https://github.com/Bjeaurn/ng2-bootstrap/tree/karma-typescript-compat) with some adjustments in order to get karma-typescript working.

To reproduce:

The error I'm receiving is:
Chrome 54.0.2840 (Mac OS X 10.12.1) ERROR Uncaught Error: A platform with a different configuration has been created. Please destroy it first.

After some quick looking around, seems the TestBed configuration that Angular2 uses isn't compatible anymore with how karma-typescript handles the loading.

Istanbul cannot find file

Hello i get an error when i clone your repo:
Unable to find entry for [C:\Users\user\Downloads\karma-typescript\example-project\src\hello-service.interface.ts]]

Compiler do not compile files, but they are "processed" by preprocessor

Hi!
I have an issue. In general- typescript does not compile files, but they are found by preprocessor:


d
31 10 2016 15:03:00.763:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-firefox-launcher.                                                         
31 10 2016 15:03:00.767:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-jasmine.                                                                  
31 10 2016 15:03:00.770:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-junit-reporter.                                                           
31 10 2016 15:03:00.800:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-phantomjs-launcher.                                                       
31 10 2016 15:03:00.808:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-teamcity-reporter.                                                        
31 10 2016 15:03:00.810:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-threshold-reporter.                                                       
31 10 2016 15:03:00.943:DEBUG [plugin]: Loading plugin D:\Projects\TaiJi\Code\web-check-box\node_modules/karma-typescript.                                                               
31 10 2016 15:03:01.256:DEBUG [framework.karma-typescript]: Fallback to default compiler options:  { emitDecoratorMetadata: true,                                                        
  experimentalDecorators: true,                                                                                                                                                          
  jsx: 'react',                                                                                                                                                                          
  module: 'commonjs',                                                                                                                                                                    
  sourceMap: true,                                                                                                                                                                       
  target: 'ES5' }                                                                                                                                                                        
31 10 2016 15:03:01.261:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.6                                                                                       
31 10 2016 15:03:01.274:DEBUG [web-server]: Instantiating middleware                                                                                                                     
31 10 2016 15:03:01.286:DEBUG [reporter]: Trying to load reporter: karma-typescript                                                                                                      
31 10 2016 15:03:01.288:DEBUG [reporter]: Trying to load color-version of reporter: karma-typescript (karma-typescript_color)                                                            
31 10 2016 15:03:01.289:DEBUG [reporter]: Couldn't load color-version.                                                                                                                   
31 10 2016 15:03:01.310:DEBUG [preprocessor.karma-typescript]: Processing "D:/Projects/TaiJi/Code/web-check-box/src/check-box.module.ts".                                                
31 10 2016 15:03:01.312:DEBUG [preprocessor.karma-typescript]: Processing "D:/Projects/TaiJi/Code/web-check-box/src/check-box.component.ts".                                             
31 10 2016 15:03:01.312:DEBUG [preprocessor.karma-typescript]: Processing "D:/Projects/TaiJi/Code/web-check-box/src/check-box.controller.ts".                                            
31 10 2016 15:03:01.313:DEBUG [preprocessor.karma-typescript]: Processing "D:/Projects/TaiJi/Code/web-check-box/src/core.ts".                                                            
31 10 2016 15:03:01.315:DEBUG [preprocessor.karma-typescript]: Processing "D:/Projects/TaiJi/Code/web-check-box/src/test/core.spec.ts".                                                  
31 10 2016 15:03:01.823:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/angular/index.d.ts                                          
31 10 2016 15:03:01.829:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/jquery/index.d.ts                                           
31 10 2016 15:03:01.838:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/es6-shim/index.d.ts                                         
31 10 2016 15:03:01.840:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/jasmine/index.d.ts                                          
31 10 2016 15:03:01.843:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/node/index.d.ts                                             
31 10 2016 15:03:01.892:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/q/index.d.ts                                                
31 10 2016 15:03:01.894:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/@types/selenium-webdriver/index.d.ts                               
31 10 2016 15:03:01.908:DEBUG [compiler.karma-typescript]: Reading: D:/Projects/TaiJi/Code/web-check-box/node_modules/typescript/lib/lib.d.ts                                            
31 10 2016 15:03:02.992:INFO [compiler.karma-typescript]: Compiled 0 files in 1176 ms.                                                                                                   
[15:03:02] 'test' errored after 2.44 s                                                                                                                                                   
[15:03:02] Error: No source found for D:/Projects/TaiJi/Code/web-check-box/src/check-box.module.ts!                                                                                      
Is there a mismatch between the Typescript compiler options and the Karma config?                                                                                                        
    at D:\Projects\TaiJi\Code\web-check-box\node_modules\karma-typescript\lib\compiler.js:72:23                                                                                          
    at Array.forEach (native)                                                                                                                                                            
    at D:\Projects\TaiJi\Code\web-check-box\node_modules\karma-typescript\lib\compiler.js:66:19                  
                                                                                      

As i can understand, compiler do not perform compilation for files. There is my karma.conf.js

module.exports = function(config) {

    /*https://karma-runner.github.io/1.0/config/configuration-file.html*/

    var buildConfig = require('./build.config.js');

    config.set({
        basePath: buildConfig.component_dir,
        files: [
            'node_modules/angular/angular.js',
            'node_modules/angular-mocks/angular-mocks.js',
            'src/**/*.ts',
        ],
        logLevel: config.LOG_DEBUG,
        reporters: ['progress','karma-typescript'],
        frameworks: ['jasmine', 'karma-typescript'],
        preprocessors: {
            '**/*.ts' : ['karma-typescript'],
        },
        karmaTypescriptConfig: {
            reports: {
                'html' :'coverage',
                'text-summary': ''
            },
            compilerOptions: {
                emitDecoratorMetadata: true,
                experimentalDecorators: true,
                jsx: "react",
                noImplicitAny: true,
                module: "commonjs",
                sourceMap: true,
                target: "ES5",
            },
            excludeFromCoverage: /\.(d|spec|test)\.ts/
        },
              browserNoActivityTimeout: 40000,
        port: 9200,
        runnerPort: 9300,
        urlRoot: '/',
        singleRun: true,
        autoWatch: false,
        browsers: [
            'PhantomJS'
        ]
    });

};

I am totally lost, trying to investigate it. It looks like tsc host requires some options. I am using

 "karma-typescript": "git://github.com/monounity/karma-typescript.git#2.1"

in my devDependencies. What is going in a wrong way here?

plugin should follow karma-plugins installation example

There's a missing Karma dependency, both in package.json and in the documentation. It's just a minor thing, but it can put new devs behind.
Since the Karma Plugin way is of not depending on karma on package, text should be changed to npm install karma karma-typescript --save-dev

edit: There's also the missing karma-jasmine and jasmine-core. I'm thinking all these should be set as peerDependencies instead of dependencies as the user will be warned if they are missing

Use remap-istanbul from npm

Hi
Would you pls change this dependency to target npm :

// e.g
  "dependencies": {
    .... 
    "remap-istanbul": "^0.6.4",
   }

Somehow, i cannot resolve github dependencies from npm install through corporate proxy.
Thanks !

Exclude does not work

Config is like:

 `   preprocessors: {
        "src/**/*.ts": ["karma-typescript"]
    },

    karmaTypescriptConfig: {
        compilerOptions: {
            emitDecoratorMetadata: true,
            experimentalDecorators: true,
            module: "commonjs",
            sourceMap: true,
            target: "ES5"
        },
        include: ["src/app/**/*.ts"],
        exclude: ["node_modules"],
        reports:
            {
                "html": "coverage",
                "text-summary": ""
            }
    },`

When running:

`npm run test

node --max-old-space-size=4096 node_modules/karma/bin/karma start

18 11 2016 18:05:08.214:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.7
18 11 2016 18:05:10.196:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/node_modules/rxjs/add/observable/if.d.ts
18 11 2016 18:05:10.250:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/node_modules/rxjs/add/observable/throw.d.ts
18 11 2016 18:05:10.904:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/node_modules/common-map/node_modules/rxjs/add/observable/throw.d.ts
18 11 2016 18:05:14.102:ERROR [compiler.karma-typescript]: No source found for c:/Users/gwk736/Gitlab/pro/src/app/index.ts
18 11 2016 18:05:18.220:INFO [compiler.karma-typescript]: Compiled 252 files in 9329 ms.
18 11 2016 18:05:33.589:ERROR [karma]: RangeError: Maximum call stack size exceeded

error when using enzyme

Karma throws an error because enzyme requires 'react/addons'.

ERROR [karma]: [Error: Cannot find module 'react/addons' from '[path to project]\node_modules\enzyme\build']

Before i had my karma runner using webpack and i defined the react/addons as externals like so:

webpackConfig.externals = { // Configuration required by enzyme
	jsdom: 'window',
	cheerio: 'window',
	'react/lib/ExecutionEnvironment': true,
	'react/lib/ReactContext': 'window',
	'react/addons': true,
};

but as I'm no longer using webpack in karma, how can I define those externals so enzyme runs?

Every hint is much appreciated

Import of relative file above karma-conf fails

So I have the following project layout:

root:
  - src: 
    - tsconfig.json
    - folder1/mycode.ts
  - test:
    - karma.conf.js
    - src:
      - tsconfig.json
      - folder1/mycode.spec.ts

Then I have the following karma config:

module.exports = function (config) {
  config.set({
    basePath: '..',
    frameworks: ['mocha', 'karma-typescript'],
    files: [
      { pattern: "node_modules/expect.js/index.js" },
      { pattern: "test/src/**/*.ts" }
    ],
    port: 9876,
    colors: true,
    singleRun: true,
    logLevel: config.LOG_DEBUG,

    preprocessors: {
      '**/*.ts': ['karma-typescript']
    },

    reporters: ['mocha', 'karma-typescript'],

    karmaTypescriptConfig: {
      tsconfig: 'test/src/tsconfig.json'
    }
  });
};

Note particularly the basePath: '..' setting. Then in root/test/src/folder1/mycode.spec.ts, I have the following import:

import { foo } from '../../../src/folder1/mycode';

Trying to run this, I get the following errors (relevant bits extracted, can paste full log in pastebin if you want):

23 11 2016 18:37:59.138:DEBUG [preprocessor.karma-typescript]: Processing "root/test/src/folder1/mycode.spec.ts".
<snip>
23 11 2016 18:43:10.562:DEBUG [compiler.karma-typescript]: Reading: root/src/folder1/mycode.ts
<snip>
23 11 2016 18:43:18.946:DEBUG [web-server]: serving (cached): root/node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js
Firefox 50.0.0 (Windows 10 0.0.0) ERROR
  Error: Could not find module

  '../../../src/folder1/mycode' from

  'root/test/src/folder1/mycode.spec.js' using paths

  [../../../src/folder1/mycode]
  [root/src/folder1/mycode]
  [root/src/folder1/mycode.js]
  [root/src/folder1/mycodeindex.js]
  [root/src/folder1/mycode/index.js]

  at node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js:48

"Duplicate identifier..." when I'm using gulp-sequence with different typings

Hi again. You probably already hate me but I found another problem ;)
It is complicated situation and I'm not sure if you are able to do something with this - maybe I have to change structure of my project (what would be huuuuge challange because it is really large application).
In my project I have 4 angular applications and every one has own gulp tasks (build, tests etc.). In addition I have common task which run sub-tasks from all four applications by gulp-sequence. Ok - it is hard to understand I know :) I prepared simple project which (I hope) shows what I'm talking about.
Just download zip, run npm i and gulp init (gulp init will install typings).
OK - now you have 3 commands:

  • gulp karma:foo - fires tests for foo application
  • gulp karma:bar - fires tests for bar application
  • gulp karma:full - fires gulp karma:foo and gulp karma:bar in sequence.

First and second works fine but the last one fails with errors:

15 11 2016 23:23:29.161:ERROR [compiler.karma-typescript]: src/foo/typings/jasmine/jasmine.d.ts(80,9): error TS2375: Duplicate number index signature.
15 11 2016 23:23:29.161:ERROR [compiler.karma-typescript]: src/foo/typings/jasmine/jasmine.d.ts(134,9): error TS2374: Duplicate string index signature.

Note that typings for both modules are in different localizations (but jasmine.d.ts is in both). I think it is a key.
As I said I'm not sure if it is problem with your plugin itself but it looks like typescript compiler remember all compiled files - not only from one compile task but from all sequence. Maybe you can clear this after coverage is generated? Of course I'm totally noob in this topic so I may be totally wrong with my suspicions ;)

I know my descriptions may be a little crazy so here is example project:
foobar_KT.zip

My env

OS: Mint 18
NodeJS: v6.9.1
NPM: v3.10.8
Gulp: v3.9.1

TypeError: Data must be a string or a buffer

Hi again!
From version >= 2.1.0 when the karma is running there is the following error


21 11 2016 17:56:13.303:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.3
21 11 2016 17:56:15.674:INFO [compiler.karma-typescript]: Compiled 70 files in 1785 ms.
21 11 2016 17:56:16.115:ERROR [karma]: TypeError: Data must be a string or a buffer
    at TypeError (native)
    at Hash.update (crypto.js:74:16)
    at sha1 (projectpath\node_modules\karma\lib\preprocessor.js:11:8)
    at nextPreprocessor (projectpath\node_modules\karma\lib\preprocessor.js:32:18)
    at instrumentSource (projectpath\node_modules\karma-typescript\lib\preprocessor.js:100:13)
    at Object.callback (projectpath\node_modules\karma-typescript\lib\preprocessor.js:145:21)
    at projectpath\node_modules\karma-typescript\lib\compiler.js:74:20
    at Array.forEach (native)
    at projectpath\node_modules\karma-typescript\lib\compiler.js:64:19
    at invokeFunc (projectpath\node_modules\lodash.debounce\index.js:160:19)
    at trailingEdge (projectpath\node_modules\lodash.debounce\index.js:207:14)
    at Timeout.timerExpired [as _onTimeout] (projectpath\node_modules\lodash.debounce\index.js:195:14)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

karma.conf.js:

module.exports = function (config) {
    config.set({
        basePath: './',
        files: [
            './node_modules/angular/angular.min.js',
            './node_modules/angular-mocks/angular-mocks.js',
            './Scripts/**/**.ts',
            './Scripts/Messages/**.ts',
            './Scripts/UnitTests/Tests/Controllers/**.ts',
            './Scripts/UnitTests/Tests/Services/**.ts'
        ],
        exclude: [],
        frameworks: [
            "jasmine", "karma-typescript"
        ],
        reporters: ['progress', 'kjhtml', "karma-typescript"],
        karmaTypescriptConfig: {
            tsconfig: './tsconfig.json', // *obligatory
            compilerOptions: {
                sourceMap: true,
                inlineSourceMap: false
            },
            /* Report type options passed to remap-istanbul */
            reports:
            {
                "html": "coverage",
                "teamcity": "coverage",
            },
            /* Options passed to remap-istanbul */
            remapOptions:
            {
                // Regex or string for excluding files, the example below is default
                //exclude: /\.(spec|test)\.ts/,
                exclude: /(typings|UnitTests|Interfaces|Libs|Messages|Models|Filters|Enum|Directives|Repositories)/,
                // Function for warning messages, these warnings are silent by default
                warn: function (message) { }
            }
        },
        preprocessors: {
            "**/*.ts": ["karma-typescript"]
        },
        browsers: ['Chrome'],
        autoWatch: true,
        singleRun: false,
        colors: true,
    });
};

Error: Cannot find module 'buffer/' from '.'

When running npm test in example-project, I get:

30 11 2016 11:17:53.796:ERROR [karma]: [Error: Cannot find module 'buffer/' from '.']
Error: Cannot find module 'buffer/' from '.'
    at Function.module.exports [as sync] (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/node_modules/browser-resolve/node_modules/resolve/lib/sync.js:33:11)
    at Function.resolve.sync (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/node_modules/browser-resolve/index.js:321:21)
    at resolveModules (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:192:45)
    at appendGlobals (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:116:13)
    at /Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/lib/bundlers/builtin/bundler.js:75:9
    at invokeFunc (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/node_modules/lodash.debounce/index.js:160:19)
    at trailingEdge (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/node_modules/lodash.debounce/index.js:207:14)
    at timerExpired [as _onTimeout] (/Users/hadrienmilano/karma-typescript/example-project/node_modules/karma-typescript/node_modules/lodash.debounce/index.js:195:14)
    at Timer.listOnTimeout (timers.js:92:15)

npm version: 2.15.9
node version: v4.5.0

I fixed this by removing the node imports from the bundler in my fork.

This bug raises the following question: Why do you provide node emulation in the browser?
If I want to test a node-specific piece of code, I'll test it in node with jasmine-node or something like that. I'll use karma only for environment agnostic and browser code, not for node code.
Thus providing node emulation seems out of scope and carries a high risk of introducing bugs because that's what emulation is known for.

Cheers

Uncaught error in chrome? Could not find module './corejs' from node_modules/promise

16 12 2016 16:25:47.374:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.1.4
16 12 2016 16:25:50.431:INFO [compiler.karma-typescript]: Compiled 6 files in 2478 ms.
16 12 2016 16:25:58.189:INFO [builtin-bundler.karma-typescript]: Bundled imports for 4 file(s) in 7257 ms.
16 12 2016 16:25:58.347:WARN [karma]: No captured browser, open http://localhost:9876/
16 12 2016 16:25:58.360:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
16 12 2016 16:25:58.361:INFO [launcher]: Launching browser Chrome with unlimited concurrency
16 12 2016 16:25:58.446:INFO [launcher]: Starting browser Chrome
16 12 2016 16:26:12.696:INFO [Chrome 55.0.2883 (Windows 7 0.0.0)]: Connected on socket /#qu2m2-bCZDPe8uQeAAAA with id 47623928
Chrome 55.0.2883 (Windows 7 0.0.0) ERROR
  Uncaught Error: Could not find module

  './core.js' from

  'C:/Users/TimothyH/Documents/GitHub/relay-neo4j-crud/node_modules/promise/lib' using paths

  [./core.js]
  [C:/Users/TimothyH/Documents/GitHub/relay-neo4j-crud/node_modules/promise/core.js]
  [C:/Users/TimothyH/Documents/GitHub/relay-neo4j-crud/node_modules/promise/core.js.js]
  [C:/Users/TimothyH/Documents/GitHub/relay-neo4j-crud/node_modules/promise/core.jsindex.js]
  [C:/Users/TimothyH/Documents/GitHub/relay-neo4j-crud/node_modules/promise/core.js/index.js]

  at node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js:48

Getting the same error replicated across two machines one Windows 7 one MacOS Sierra.

Pretty new to typescript and karma so I'm flying a little blind here any help is much appreciated!

capture
The file is definitely there. And in the lib path as well.

UPDATE:
By manually requiring all the plugins in karma conf rather than implicitly and then including core.js manually in the files configuration option I've developed the error to:

Uncaught ReferenceError: require is not defined
at node_modules/promise/lib/core.js:3

So it looks like maybe common.js isn't properly bundling for the browser?

Angular 2 Component-Relative URL

Hello

Not working with Component-Relative URL in component decorators

import { Component } from "@angular/core";

@Component({
    moduleId: module.id,
    selector: "app-footer",
    templateUrl: "footer.html"
})
export class Footer
{
}
WARN [web-server]: 404: /footer.html

Ignore imports that don't have a source

I have a project that uses the 'estree' typings, there is no actual source for it, just typings.

But in my TS source I do:

import { ExpressionStatement, FunctionExpression } from 'estree';

But when I run the tests, I get:

Error: Cannot find module 'estree' from 'C:/Projects/jsWebDb/src'
at Function.module.exports [as sync] (C:\Projects\jsWebDb\node_modules\resolve\lib\sync.js:33:11)
at Function.resolve.sync (C:\Projects\jsWebDb\node_modules\browser-resolve\index.js:321:21)
at resolveModules (C:\Projects\jsWebDb\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:177:49)
at C:\Projects\jsWebDb\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:80:21
at Array.forEach (native)
at C:\Projects\jsWebDb\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:76:36
at Array.forEach (native)
at C:\Projects\jsWebDb\node_modules\karma-typescript\lib\bundlers\builtin\bundler.js:72:21
at invokeFunc (C:\Projects\jsWebDb\node_modules\lodash.debounce\index.js:160:19)
at trailingEdge (C:\Projects\jsWebDb\node_modules\lodash.debounce\index.js:207:14)
at timerExpired [as _onTimeout] (C:\Projects\jsWebDb\node_modules\lodash.debounce\index.js:195:14)
at Timer.listOnTimeout (timers.js:92:15)

Is there a way to ignore certain imports?

undefined is not an object (evaluating 'exports.formatters')

This is a two parter, though I think one is causing the other. Somehow, my @types/ are being ignored:

17 12 2016 19:58:36.061:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.1.4
17 12 2016 19:58:37.864:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(68,60): error TS2304: Cannot find name 'Promise'.

17 12 2016 19:58:37.865:ERROR [compiler.karma-typescript]: node_modules/rxjs/Observable.d.ts(68,70): error TS2304: Cannot find name 'Promise'.

17 12 2016 19:58:37.865:ERROR [compiler.karma-typescript]: src/subjects/socket-io.spec.ts(6,1): error TS2304: Cannot find name 'describe'.

17 12 2016 19:58:37.866:ERROR [compiler.karma-typescript]: src/subjects/socket-io.spec.ts(7,5): error TS2304: Cannot find name 'it'.

17 12 2016 19:58:37.866:ERROR [compiler.karma-typescript]: src/subjects/socket-io.spec.ts(8,9): error TS2304: Cannot find name 'expect'.

which then probably causes the

PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
  TypeError: undefined is not an object (evaluating 'exports.formatters')
  at C:/Users/MOSHMA~1/AppData/Local/Temp/karma-typescript-bundle-976yFHybkGsMnWw.js:3602

Now, my own compilation was throwing errors about the Observable ... Promise thingy, I fixed it by installing @types/es6-shim - but that doesn't seem to fix karma-ts compiler part so I'm guessing the typescript compiler in karma counterpart is ignore the installed @types?

you can check it out @ https://gitlab.com/moshmage/rxjs-socket.io/tree/karma-typescript (karma start karma.conf.js)


configs:
tsconfig, karma.conf.js, package.json

Uncaught TypeError: Cannot read property 'buffer/' of undefined

Hello! I am using the karma-typescript for another project which is written with namespaces and no modules at all.

When I run karma I get an error:

Uncaught TypeError: Cannot read property 'buffer/' of undefined
at C:/Users/AppData/Roaming/npm/node_modules/karma-typescript/lib/bundlers/builtin/commonjs.js:24

Does this happen because of no export classes, interfaces etc?

Here is my tsconfig:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "strictNullChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "target": "es5",
    "module": "none"
  },
  "compileOnSave": true,
  "exclude": [
    "node_modules",
    "bower_components",
    "Scripts/typings/lodash/lodash-3.10.d.ts"
  ]
}

How to use with mocha framework?

First of all, thanks for this project, it was really needed.

I've just started trying out to use this for testing my typescript code, but since I use the mocha framework for testing, I get stuck at compilation:

> karma start --browsers=Chrome test/karma.conf.js

23 11 2016 13:39:58.565:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.0.10

START:
23 11 2016 13:40:01.423:ERROR [compiler.karma-typescript]: test/src/common/collapsiblepanel.spec.ts(14,1): error TS2304: Cannot find name 'describe'.
23 11 2016 13:40:01.424:ERROR [compiler.karma-typescript]: test/src/common/collapsiblepanel.spec.ts(16,3): error TS2304: Cannot find name 'describe'.
23 11 2016 13:40:01.425:ERROR [compiler.karma-typescript]: test/src/common/collapsiblepanel.spec.ts(18,5): error TS2304: Cannot find name 'it'.

And so on... Any suggestions for how to get it working?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.