Ricardo Rocha
Ricardo Rocha

Reputation: 16266

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?

Upvotes: 5

Views: 11305

Answers (4)

Manish Kumar
Manish Kumar

Reputation: 119

That happens with my unit-tests , actually one of the unit tests I had

import { NO_ERRORS_SCHEMA } from '@angular/compiler/src/core';

which I replaced with

import { NO_ERRORS_SCHEMA } from '@angular/core';

Upvotes: 0

Ricardo Rocha
Ricardo Rocha

Reputation: 16266

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.

Upvotes: 3

Suresh Kumar Ariya
Suresh Kumar Ariya

Reputation: 9774

You need to check the path in src/test.ts. Here is my code.

// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();

Upvotes: 2

BlackICE
BlackICE

Reputation: 8936

If you're sure that you have spec.ts files in your path, this is the only difference I see between your karma.config and mine:

frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
  require('karma-jasmine'),
  require('karma-chrome-launcher'),
  require('karma-jasmine-html-reporter'),
  require('karma-coverage-istanbul-reporter'),
  require('@angular-devkit/build-angular/plugins/karma')
],

Mine didn't have the files: at all before I looked at this question though, so you could also try just removing it.

Upvotes: 2

Related Questions