0
votes

Here is my root directory
src/tsfolders/.ts files public/src/jsfolders/.js files.

And Karma config

module.exports = function(config) {

config.set({ basePath: '.', frameworks: ['jasmine'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-htmlfile-reporter') ],

customLaunchers: {
  // From the CLI. Not used here but interesting
  // chrome setup for travis CI using chromium
  Chrome_travis_ci: {
    base: 'Chrome',
    flags: ['--no-sandbox']
  }
},
files: [
  // System.js for module loading
  'node_modules/systemjs/dist/system-polyfills.js',
  'node_modules/systemjs/dist/system.src.js',

  // Polyfills
  'node_modules/es6-shim/es6-shim.js',

  // Reflect and Zone.js
  'node_modules/reflect-metadata/Reflect.js',
  'node_modules/zone.js/dist/zone.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',

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

  // Angular 2 itself and the testing library
  {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
  {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},

  'karma-test-shim.js',

   {pattern: 'public/src/**/*.js', included: false, watched: true},

          // paths to support debugging with source maps in dev tools
    {pattern: 'src/**/*.ts', included: false, watched: false},
    {pattern: 'src/**/*.js.map', included: false, watched: false}
],

// proxied base paths for loading assets
proxies: {
  // required for component assets fetched by Angular's compiler
  '/src/': '/base/src/'

},

exclude: [],
preprocessors: {},
reporters: ['progress', 'html'],

// HtmlReporter configuration
htmlReporter: {
  // Open this file to see results in browser
  outputFile: '_test-output/tests.html',

  // Optional
  pageTitle: 'Unit Tests',
  subPageTitle: __dirname
},

port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false

}) }

Can someone explain how to configure Karma paths, cause now it doesn't see any of my tests and return error "Executed 0 of 0 ERROR"

1
is your test cases available in src folder itself or outside it? Secondly please check your 'test.ts' file as well for the path included to see the test files.Naveen Yadav

1 Answers

0
votes

Karma will look for your files relative you where your Karma.conf.js file is.

So if your Karma.conf.js file is at C:\YourName\MyApp\Karma.conf.js

Then putting

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

will get Karma to look at

C:/YourName/MyApp/node_modules/rxjs/        and beyond