lundi 1 juin 2020

karma doesn't see tests after ng test (Executed 0 of 0 SUCCESS)

I've got a problem with running tests. After running ng test command, the command line shows

Chrome 83.0.4103 (Windows 7.0.0): Executed 0 of 0 SUCCESS (0.007 secs / 0 secs)
TOTAL: 0 SUCCESS
TOTAL: 0 SUCCESS

In my browser I see the karma tab with information: 0 specs, 0 failures and in the console I've got an error Failed to load resource: the server responded with a status of 404 (Not Found)

Tests run on other laptop.

My karma.conf.js

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    files: [   
      'src/app/**/*.js'
    ],
    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'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

Package.json

{
  "name": "angular-i-spy",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "api": "json-server server/db.json --watch"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/build-angular": "^0.900.3",
    "@angular/animations": "^9.0.2",
    "@angular/common": "^9.0.2",
    "@angular/compiler": "^9.0.2",
    "@angular/core": "^9.0.2",
    "@angular/forms": "^9.0.2",
    "@angular/http": "^7.2.16",
    "@angular/localize": "^9.1.9",
    "@angular/platform-browser": "^9.0.2",
    "@angular/platform-browser-dynamic": "^9.0.2",
    "@angular/router": "^9.0.2",
    "@ng-bootstrap/ng-bootstrap": "^5.3.0",
    "bootstrap": "^4.4.1",
    "core-js": "^2.6.11",
    "json-server": "^0.16.1",
    "rxjs": "~6.5.4",
    "ts-md5": "^1.2.7",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular/cli": "^9.0.3",
    "@angular/compiler-cli": "^9.0.2",
    "@angular/language-service": "^9.0.2",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.6",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.3",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "^3.7.5"
  }
}

Test example:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { InitialPageComponent } from './initial-page.component';

describe('InitialPageComponent', () => {
  let component: InitialPageComponent;
  let fixture: ComponentFixture<InitialPageComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ InitialPageComponent ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(InitialPageComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

Test.ts

import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

Thank you very much for any help.

Aucun commentaire:

Enregistrer un commentaire