monounity / karma-typescript

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

coverage folder is not getting generated #203

Closed asif-khan17 closed 7 years ago

asif-khan17 commented 7 years ago

module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', 'karma-typescript'],

    plugins: [
        require('karma-jasmine'),
        require('karma-chrome-launcher'),
        require('karma-typescript'),
        require('karma-coverage'),
        require('karma-jasmine-html-reporter')
    ],
    files: [

        'node_modules/systemjs/dist/system.src.js',
        //// Polyfills
        'node_modules/core-js/client/shim.js',
        'node_modules/reflect-metadata/Reflect.js',

        // zone.js
        'node_modules/zone.js/dist/zone.js',
        'node_modules/zone.js/dist/long-stack-trace-zone.js',
        'node_modules/zone.js/dist/proxy.js',
        'node_modules/zone.js/dist/sync-test.js',
        'node_modules/zone.js/dist/jasmine-patch.js',
        'node_modules/zone.js/dist/async-test.js',
        'node_modules/zone.js/dist/fake-async-test.js',

        { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },

        'karma-test-shim.js',
        { pattern: 'node_modules/@angular/**/*.js', included: false, watched: false },
        { pattern: 'wwwroot/app/**/!(*.aot)*.js', included: false, watched: true },
        { pattern: 'wwwroot/app/**/!(*.aot)*.ts', included: false, watched: true },
        { pattern: 'wwwroot/app/**/*.js.map', included: false, watched: true },
        { pattern: 'wwwroot/app/**/*.html', included: false, watched: true },
        { pattern: 'wwwroot/**/*.css', included: false, watched: true },
        { pattern: 'node_modules/md2/bundles/md2.umd.js', included: false, watched: false },
        { pattern: 'node_modules/ngx-popover/**/*.js', included: false, watched: false },
        { pattern: 'node_modules/ngx-clipboard/**/*.js', included: false, watched: false },
        { pattern: 'node_modules/clipboard/dist/clipboard.js', included: false, watched: false },
        { pattern: 'node_modules/angular2-infinite-scroll/**/*.js', included: false, watched: false },
        { pattern: 'node_modules/tinymce/**/*.js', included: false, watched: false },
        { pattern: 'node_modules/angular2-tinymce/dist/**.js', included: false, watched: false },

    ],

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

    proxies: {
        "/app/": "/base/wwwroot/app/"
    },

    preprocessors: {
        // source files, that you wanna generate coverage for 
        // do not include tests or libraries 
        // (these files will be instrumented by Istanbul) 
        'wwwroot/app/**/!(*.spec).ts': ["karma-typescript"]

    },

    karmaTypescriptConfig: {
        bundlerOptions: {
            transforms: [
                require("karma-typescript-es6-transform")()
            ],
            entrypoints: /\.spec\.(ts)$/,
            addNodeGlobals: true
        },
        compilerOptions: {
            target: "es5",
            module: "commonjs",
            moduleResolution: "node",
            sourceMap: true,
            emitDecoratorMetadata: true,
            experimentalDecorators: true,
            lib: ["es2015", "dom"],
            noImplicitAny: false,
            suppressImplicitAnyIndexErrors: true

        },
        exclude: ['wwwroot/app/main.aot.ts', 'wwwroot/app/main.conduct.aot.ts', 'wwwroot/app/main.setup.aot.ts', "node_modules"],
        reports: {
            "html": "coverage",
            "text-summary": ""
        }
    },

    client: {
        clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    reporters: ["progress", "karma-typescript", "kjhtml"],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
});

};

this is my config file , all the tests are running well but coverage folder is not getting generated p why?

erikbarke commented 7 years ago

Does this really work, 'wwwroot/app/**/!(*.spec).ts': ["karma-typescript"]? All ".spec.ts" files are excluded from instrumentation by default (see karmaTypescriptConfig.coverageOptions.exclude) so you shouldn't need to exclude them. Does the coverage folder get generated if you include also the spec files in the preprocessor setting, ie 'wwwroot/app/**/*.ts': ["karma-typescript"]?

asif-khan17 commented 7 years ago

No.. After changing preprocessor settings to 'wwwroot/app/*/.ts': ["karma-typescript"] .. it still not generates coverage folder

erikbarke commented 7 years ago

Ok, you're also adding all of your project files with included: false which means you have to load them manually in the browser with Require.js or similar, is that what "karma-test-shim.js" does? It looks like you're mixing frameworks here, which I'm guessing you really don't need since karma-typescript uses CommonJS internally and does all the bundling and module loading automatically for you.