Jim
Jim

Reputation: 16022

karma not finding any spec files after webpack build

I am using the below karma.config.js to test an angular 5 application:
The output shows that the spec files are being built by webpack. But they are not being executed.

Executed 0 of 0 ERROR (0.014 secs / 0 secs)

Built at: 2018-4-6 11:41:27
                                                Asset      Size                                                 Chunks             Chunk Names
wwwroot/ts/app/modules/party/ContactComponent.spec.ts  2.36 MiB  wwwroot/ts/app/modules/party/ContactComponent.spec.ts  [emitted]  wwwroot/ts/app/modules/party/ContactComponent.spec.ts
                            wwwroot/ts/sanity.spec.ts   841 KiB                              wwwroot/ts/sanity.spec.ts  [emitted]  wwwroot/ts/sanity.spec.ts
Entrypoint wwwroot/ts/app/modules/party/ContactComponent.spec.ts = wwwroot/ts/app/modules/party/ContactComponent.spec.ts
Entrypoint wwwroot/ts/sanity.spec.ts = wwwroot/ts/sanity.spec.ts
[./node_modules/@angular/core/esm5/core.js] 613 KiB {wwwroot/ts/sanity.spec.ts} {wwwroot/ts/app/modules/party/ContactComponent.spec.ts} [built] [2 warnings]
[./node_modules/@angular/core/esm5/testing.js] 48.6 KiB {wwwroot/ts/sanity.spec.ts} {wwwroot/ts/app/modules/party/ContactComponent.spec.ts}

So it seems that all (of 2) spec files are being built, but they don't appear to loading into karma.

06 04 2018 11:41:28.195:INFO [launcher]: Starting browser Chrome
06 04 2018 11:41:31.277:INFO [Chrome 65.0.3325 (Windows 10.0.0)]: Connected on socket hJfXueGxaOTtJn4SAAAA with id 21418556    
Chrome 65.0.3325 (Windows 10.0.0): Executed 0 of 0 ERROR (0.014 secs / 0 secs)

for reference my karma.config.js is as follows.

module.exports = function (config) {
    config.set({
        basePath: "",
        frameworks: ["jasmine"],
        plugins: [
            require("karma-jasmine"),
            require("karma-chrome-launcher"),
            require("karma-jasmine-html-reporter"),
            require("karma-spec-reporter"),
            require("karma-webpack")
        ],
        files: [
    "./base.spec.ts",
    "./wwwroot/**/*.spec.*"
        ],
        webpack: {
            mode: "development",
            module: {
                rules: [
                    {
                        test: /\.ts$/,
                        use: ["ts-loader"],
                        exclude: /(node_modules)/
                    },
                    {
                        test: require.resolve("jquery"),
                        use: [
                           { loader: "expose-loader", options: "jQuery" },
                           { loader: "expose-loader", options: "$" }
                        ]
                    }
                ]
            },
            resolve:
                {
                    extensions: [".ts", ".js", ".json"],
                    alias: {
                        typeahead: "typeahead.js"
                    }
                },
        },
        preprocessors: {
            "./base.spec.ts": ["webpack"],
            "./wwwroot/**/*.spec.*": ["webpack"]
        },
        reporters: ["kjhtml", "spec"],
        port: 9876,
        colors: true,
        autoWatch: true,
        browsers: ["Chrome"],
        singleRun: false
    });
};

Upvotes: 1

Views: 952

Answers (1)

scipper
scipper

Reputation: 3153

Setting the mime type in your karma config will make your tests run.

mime: {
  "text/x-typescript": ["ts"]
},

Upvotes: 2

Related Questions