dimanche 7 mai 2017

Karma can't find my tests in my angular-cli app

I have an Angular 4 project generated with CLI and I'm trying to make test work. I have Karma.conf in the root of my project:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', 'angular-cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-remap-istanbul'),
      require('angular-cli/plugins/karma')
    ],
    files: [
      { pattern: './src/test.ts', watched: false }
    ],
    preprocessors: {
      './src/test.ts': ['angular-cli']
    },
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    remapIstanbulReporter: {
      reports: {
        html: 'coverage',
        lcovonly: './coverage/coverage.lcov'
      }
    },
    angularCli: {
      config: './angular-cli.json',
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage
              ? ['progress', 'karma-remap-istanbul']
              : ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

And here is my test.ts located in my src folder:

declare var __karma__: any;
declare var require: any;

__karma__.loaded = function () {};

getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
const context = require.context('./', true, /\.spec\.ts$/);
context.keys().map(context);
__karma__.start();

My folder structure is:

    +---app
|   +---class
|   +---components
|   +---services
|   \---templates
+---assets
|   \---images
\---environments

So, inside my components, I have created a test called feeds.component.spec.ts that is associated to a component called feeds.component.ts.

The output of my windows console is the following:

Unable to find "@angular/cli" in devDependencies.

The package "angular-cli" has been deprecated and renamed to "@angular/cli".

Please take the following steps to avoid issues:
"npm uninstall --save-dev angular-cli"
"npm install --save-dev @angular/cli@latest"

08 05 2017 08:33:12.674:WARN [karma]: No captured browser, open http://localhost
:9876/
08 05 2017 08:33:12.687:INFO [karma]: Karma v1.2.0 server started at http://loca
lhost:9876/
08 05 2017 08:33:12.688:INFO [launcher]: Launching browser Chrome with unlimited
 concurrency
08 05 2017 08:33:12.897:INFO [launcher]: Starting browser Chrome
08 05 2017 08:33:17.033:INFO [Chrome 58.0.3029 (Windows 10 0.0.0)]: Connected on
 socket /#tif1xw_35N5kuco6ACBA with id 3123123

And karma debug console just outputs Skipped 0 tests so no test is being launched.

The strange thing is that I can launch default tests that are located in my template folder: app.component.spec.ts:

Chrome 58.0.3029 (Windows 10 0.0.0): Executed 3 of 3 (3 FAILED) (0 secs / 0.159
Chrome 58.0.3029 (Windows 10 0.0.0): Executed 3 of 3 (3 FAILED) ERROR (0.536 sec
s / 0.159 secs)

Why aren't my components test not being launched?

Aucun commentaire:

Enregistrer un commentaire