Search code examples
angulartypescriptkarma-runner

Karma is not finding my spec.ts file tests


I have the following karma.config.js that is based on this

module.exports = function (config) {
  config.set({
    basePath: '',
    files: ['**/*spec.ts'],
    frameworks: ['jasmine'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

I can not understand why that the report says that there was execute 0 tests. I'm sure that I have some files in my src folder that has the spec.ts extension.

Chrome 68.0.3440 (Windows 10.0.0): Executed 0 of 0 ERROR (0.079 secs / 0 secs)

Any one has any idea what may be the issue?


Solution

  • In the context of this answer I realise that I didn't the follwoing files in my project:

    1. test.ts
    2. polyfills.ts
    3. angular.json

    I haven't realize early because this is a project that is install on another project. This means that I never had the need of running this project as a stand alone application.

    To solve this issue, what I did was:

    1. Create a new angular project by running the command ng new my-app
    2. Check for configuration files that did not exists on my project (comparing with this new project created)
    3. Import this files to the same relative path that the files of the new project created has.
    4. Run the project and check for new errors that could appear.