我有一个使用CLI生成的Angular 4项目,我试图使测试工作。我有Karma.conf在我的项目的根目录:Karma无法在我的angular-cli应用程序中找到我的测试
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
});
};
,这里是位于我src文件夹我的test.ts:
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();
我的文件夹结构是:
+---app
| +---class
| +---components
| +---services
| \---templates
+---assets
| \---images
\---environments
因此,在我的组件中,我创建了一个名为feeds.component.spec.ts
的测试,它与一个名为feeds.component.ts
的组件相关联。
我的Windows控制台输出如下:
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/[email protected]"
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
和因果报应调试控制台只是输出Skipped 0 tests
所以没有测试正在启动。
奇怪的是,我可以启动那些位于我template
文件夹的默认测试:通过注释test.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)
在我karma.conf.js
我还试图“逼迫”测试:app.component.spec.ts
图案和硬编码我的组件:
files: [
//{ pattern: './src/test.ts', watched: false },
{ pattern: 'app/components/feeds.component.spec.ts', included: true, watched:false }
],
但这输出以下:
Uncaught SyntaxError: Unexpected token import
at src/app/components/feeds.component.spec.ts:1
为什么我的components
测试未启动?
同样的问题在这里,任何解决方案? –