简体   繁体   中英

ERROR in Entry module not found: Error: Can't resolve /src/test.ts

I'am trying to run the unit test for my Angular 2 App via: ng test , but I keep getting the following error:

ERROR in Entry module not found: Error: Can't resolve 

'/Users/username/Dev/dashboard/src/test.ts' in '/Users/username/Dev/dashboard/node_modules/@angular/cli/models/webpack-configs'
28 07 2017 15:18:35.337:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
28 07 2017 15:18:35.441:INFO [launcher]: Trying to start Chrome again (1/2).
28 07 2017 15:19:35.447:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
28 07 2017 15:19:35.587:INFO [launcher]: Trying to start Chrome again (2/2).

The Angular CLI version (after npm update): @angular/cli: 1.2.6 and the Node version is: node: 8.0.0

The other commands: ng build -prod and: ng serve work fine without errors and I can access the app on the browser.

One thing I have to mention is that a couple of days ago, I did remove all the .spec.ts files from the folders as all methods:

describe(), beforeEach(), it()

couldn't be found. After searching, I found that the app wouldn't break when removing them, but today I did create them once again to run the unit test for the app.

Any idea please?

I had the same your problem, what let's me think your test.ts file is missing, here is its content:

// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare const __karma__: any;
declare const require: any;

// Prevent Karma from running prematurely.
// tslint:disable-next-line:only-arrow-functions
__karma__.loaded = function () {};

// 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);
// Finally, start Karma to run the tests.
__karma__.start();

Just save it in app/src/test.ts and rerun ng test .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM