-1

When I run ng test. Karma finds all spec files except files in folders with _ (example: _sidebar)

Here is the karma.conf.js file:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    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')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../../../coverage/themes'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true
  });
};

And here is test.ts file context filter:

const context = require.context('./', true, /\.spec\.ts$/);

1 Answers1

2

Check tsconfig.spec.json and pay attention to the files, include, and exclude array and make sure those folders are not being excluded.

In test.ts, there is a context property, maybe it is ignoring the folders that start with _ with the './'.

AliF50
  • 16,947
  • 1
  • 21
  • 37
  • Here is my context filter: const context = require.context('./', true, /\.spec\.ts$/); How can I fix it? – Orkhan Ismayilov Sep 09 '20 at 06:11
  • 1
    Try `const context = require.context('./_', true, /\.spec\.ts$/)` and see if the unit tests in folders with _ run only. If yes, then I guess that's it. But I would just remove the _ in the folders if possible and if they are not needed. https://stackoverflow.com/questions/47364840/angular-cli-how-to-pick-up-spec-ts-files-outside-of-the-src-folder – AliF50 Sep 09 '20 at 12:48