[英]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:我正在尝试通过
ng test
为我的 Angular 2 应用程序运行单元测试,但我不断收到以下错误:
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
Angular CLI 版本(npm 更新后):
@angular/cli: 1.2.6
和 Node 版本是: 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.其他命令:
ng build -prod
和: ng serve
工作正常,没有错误,我可以在浏览器上访问该应用程序。
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:我必须提到的一件事是,几天前,我确实从所有方法中删除了文件夹中的所有
.spec.ts
文件:
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:我和你有同样的问题,我认为你的
test.ts
文件丢失了,这是它的内容:
// 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
.只需将其保存在
app/src/test.ts
并重新运行ng test
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.