我目前正在构建一个 Angular 库,我希望能够运行一些测试。遵循这些说明后,我设法正确设置了所有内容,并且实际上能够运行我的测试。
主要问题
尽管一切运行正常,但还是会发生一些尴尬的事情。当我在每个文件npm test
旁边运行时,会生成一个文件。通常,所有和一个大文件都放在使用库使用的项目的文件夹中。那么有没有人知道这些 javascript 文件是从哪里生成的,以及是否确实需要它们,因为可以说所有这些代码已经存在于 dist 文件夹中。.ts
.js
d.ts
.js
dist
奖金问题
不像上面那么重要,所有的测试结果都显示在终端中,而浏览器只显示:
Karma v1.4.1 - 连接的 Chrome 61.0.3163 (Mac OS X 10.12.6) 空闲
那么有没有一个很好的解决方法来显示我的测试和angular-cli
开箱即用的效果一样好?
注意,做完功课后在网上没有找到相关的东西,也不想上传一堆难看的json。如果有人对问题的方向有想法,我很乐意提供代码。
我的库的基本结构是由此生成的
编辑:
karma.config.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'karma-typescript'],
files: [
'init-test-bed.spec.ts',
'src/**/*.ts'
],
exclude: [
],
preprocessors: {
'**/*.ts': ['karma-typescript']
},
karmaTypescriptConfig: {
bundlerOptions: {
entrypoints: /\.spec\.ts$/,
transforms: [
require('karma-typescript-angular2-transform')
]
},
compilerOptions: {
lib: ['ES2015', 'DOM']
}
},
reporters: ['progress', 'karma-typescript'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
tsconfig.json
{
"compilerOptions": {
"baseUrl": "./src",
"experimentalDecorators": true,
"moduleResolution": "node",
"rootDir": "./src",
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2015",
"dom"
],
"skipLibCheck": true,
"types": [
"jasmine",
"node"
]
}
}
最后test
运行这个脚本
"test": "tsc && karma start"