monounity / karma-typescript

Simplifying running unit tests with coverage for Typescript projects.
313 stars 109 forks source link

Compiles but doesn't run any tests #269

Closed amilbeck closed 6 years ago

amilbeck commented 6 years ago

I'm having some trouble getting my tests to run. They compile fine but no tests are running. In fact, chrome isn't even launching which I find strange because it was launching fine and then failing when I had some compiler errors.

I've just joined a new project and the task I'm working on is migrating all the current unit and e2e tests to Jasmine. Previously the project was using mocha, sinon, chai, and mocha-webpack to run them. I've removed all of those dependencies and added the usual suspects as far as jasmine and karma-typescript are concerned. I setup my karma config based on the angular 2 example you have.

Here is a snippet of the logs from before I fixed the compiler error:

START:
31 05 2018 12:42:58.544:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.2.2
31 05 2018 12:43:08.642:ERROR [compiler.karma-typescript]: src/app/projects/projects.component.ts(90,5): error TS2322: Type '(number | (() => string) | { <U>(this: [ProjectModel, ProjectModel, ProjectModel, ProjectModel, P...' is not assignable to type 'ProjectModel[]'.
  Type 'number | (() => string) | { <U>(this: [ProjectModel, ProjectModel, ProjectModel, ProjectModel, Pr...' is not assignable to type 'ProjectModel'.
    Type 'number' is not assignable to type 'ProjectModel'.

31 05 2018 12:43:11.034:INFO [compiler.karma-typescript]: Compiled 218 files in 12099 ms.
31 05 2018 12:43:11.185:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
31 05 2018 12:43:11.188:INFO [launcher]: Launching browser Chrome with unlimited concurrency
31 05 2018 12:43:11.199:INFO [launcher]: Starting browser Chrome
31 05 2018 12:43:13.363:INFO [Chrome 66.0.3359 (Windows 10 0.0.0)]: Connected on socket ieJckVPHmzu_nN9fAAAA with id 12059711
Chrome 66.0.3359 (Windows 10 0.0.0) ERROR
  {
    "message": "You need to include some adapter that implements __karma__.start method!",
    "str": "You need to include some adapter that implements __karma__.start method!"
  }

Finished in 0.181 secs / 0 secs @ 12:43:13 GMT-0400 (Eastern Daylight Time)

You can see that the launcher was working. However, now that I've fixed the compiler error all I'm getting is the project compiles and then karma exits.

Here is the logs from after the error was fixed:

START:
31 05 2018 15:57:54.525:INFO [compiler.karma-typescript]: Compiling project using Typescript 2.2.2
31 05 2018 15:58:03.495:INFO [compiler.karma-typescript]: Compiled 218 files in 8658 ms.

That's all I get. Have you ever seen this before? Know what the problem might be?

Here is my config for reference:

module.exports = function(config) {
    config.set({
        singleRun: true,
        frameworks: ["jasmine", "karma-typescript"],
        files: [
            { pattern: "src/**/*.+(ts|html)" }
        ],
        preprocessors: {
            "**/*.ts": ["karma-typescript"]
        },
        reporters: ["mocha", "karma-typescript"],
        browsers: ["Chrome"],
        karmaTypescriptConfig: {
            bundlerOptions: {
                entrypoints: /\.spec\.ts$/,
                transforms: [
                    require("karma-typescript-es6-transform")
                ]
            },
            compilerOptions: {
                target: "es5",
                module: "commonjs",
                moduleResolution: "node",
                sourceMap: true,
                emitDecoratorMetadata: true,
                experimentalDecorators: true,
                lib: ["es2015", "dom"],
                types: ["jasmine"],
                noImplicitAny: true,
                suppressImplicitAnyIndexErrors: true
              },
            exclude: [
                "node_modules",
                "e2e"
            ]
        }
    });
};

I'm really stumped. I don't understand why it at least attempted to run when there was an error but not at all once it was fixed. Any ideas would be greatly appreciated.

amilbeck commented 6 years ago

Ok, to add to my confusion, I added basePath: './src' and now it is launching the browser but still not running any of my tests. In fact, it doesn't look like any of my source files are even being loaded.

START:
31 05 2018 17:00:13.401:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/
31 05 2018 17:00:13.404:INFO [launcher]: Launching browser Chrome with unlimited concurrency
31 05 2018 17:00:13.411:INFO [launcher]: Starting browser Chrome
31 05 2018 17:00:15.489:INFO [Chrome 66.0.3359 (Windows 10 0.0.0)]: Connected on socket Gi9WcZfJWi3Zr5-lAAAA with id 93351701

Finished in 0.048 secs / 0 secs @ 17:00:15 GMT-0400 (Eastern Daylight Time)

SUMMARY:
√ 0 tests completed
npm ERR! Test failed.  See above for more details.

image

The karma-typescript-bundle.js file is completely empty for some reason

amilbeck commented 6 years ago

I ended up going a different route. Not sure what I was doing wrong here but I just couldn't get it to load any files no matter what I tried.