-
Notifications
You must be signed in to change notification settings - Fork 139
/
karma.conf.js
223 lines (209 loc) · 7.84 KB
/
karma.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* karma: 测试管理工具
* phantomjs: 模拟的浏览器环境
*
*/
const webpack = require('webpack');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { version } = require('./package.json');
module.exports = function (config) {
// karma config: http://karma-runner.github.io/1.0/config/configuration-file.html
// karma-coverage: https://www.npmjs.com/package/karma-coverage
// Travis CI: http://www.ruanyifeng.com/blog/2017/12/travis_ci_tutorial.html
config.set({
// 将用于解决所有的模式基本路径(例如,文件,排除)
basePath: '',
// 使用框架
// 可用的框架:https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine-ajax', 'jasmine', 'webpack'],
// 需要测试的文件列表
files: [
{ pattern: 'test/**/*_test.js' }
],
// 使用端口
port: 9876,
// 是否在输出日志中使用颜色
colors: true,
// 持续集成模式: 配置为true 将会持续运行测试, 直致完成返回0(成功)或1(失败). 示例: Done. Your build exited with 0.
singleRun: true,
// 日志级别
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// 是否监听文件变化
autoWatch: false,
// 配置启动单元测试的环境
browsers: ['ChromeHeadless'],
// 捕获浏览器的超时时间
captureTimeout: 60000,
// coverage reporter generates the coverage
reporters: ['progress', 'coverage'],
// 预处理
preprocessors: {
'src/**/*.js': ['coverage', 'webpack', 'sourcemap'],
'test/**/*_test.js': ['webpack']
},
// optionally, configure the reporter
coverageReporter: {
reporters: [
// generates ./coverage/chart/*.html
{ type: 'html', subdir: 'chart' },
// generates ./coverage/lcov.info
{type: 'lcovonly', subdir: '.'},
// generates ./coverage/coverage-final.json
{type: 'json', subdir: '.'}
]
},
// webpack config: https://github.com/webpack-contrib/karma-webpack
webpack: {
mode: 'development',
optimization: {
runtimeChunk: false,
splitChunks: false
},
// 入口文件配置
resolve: {
extensions: ['.js', '.ts'], // 当requrie的模块找不到时,添加这些后缀
alias: {
'@common': path.join(__dirname, './src/common'),
'@jTool': path.join(__dirname, './src/jTool'),
'@module': path.join(__dirname, './src/module'),
'@test': path.join(__dirname, './test'),
'@package.json': path.join(__dirname, './package.json')
}
},
// output: {
// filename: '[name].js',
// path: path.join(__dirname, '_karma_webpack_') + Math.floor(Math.random() * 1000000),
// },
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.join(__dirname, './coverage')]
}),
new webpack.ProvidePlugin({
'Promise': 'es6-promise'
}),
new webpack.DefinePlugin({
'process.env': {
VERSION: JSON.stringify(version)
}
})
],
module: {
rules: [
{
test: /_test.js?$/,
use: [{
loader: path.join(__dirname, './webpack-loaders/karma-log-loader.js')
}]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader'
},
{
loader: 'ts-loader'
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.less/,
include: [path.join(__dirname, 'src')],
use: [
{
loader: 'css-loader',
options: {
url: true, // 启用/禁用 url() 处理
sourceMap: false // 启用/禁用 Sourcemaps
}
},
{
loader: 'resolve-url-loader'
},
{
loader: 'less-loader',
options: {
sourceMap: false // 启用/禁用 Sourcemaps
}
}
]
}, {
test: /\.html$/,
use: [path.join(__dirname, './webpack-loaders/html-clear-loader.js'), 'html-loader'],
include: [path.join(__dirname, 'src'), path.join(__dirname, 'test')],
exclude: /(node_modules|bower_components)/
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: 'file-loader?name=[path][name]-[hash:5].[ext]'
}
]
}, {
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
}
]
}, {
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/octet-stream'
}
}
]
}, {
test: /\.otf(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-otf'
}
}
]
}, {
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader'
}
]
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name]-[hash:8].[ext]'
}
}
]
}
]
}
},
// webpackMiddleware: {noInfo: false}, // no webpack output
// Karma有多少个浏览器并行启动
concurrency: Infinity,
processKillTimeout: 1000
});
};