-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.ts
85 lines (79 loc) · 2.13 KB
/
karma.conf.ts
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
import * as karma from "karma";
import * as path from "path";
import * as webpack from "webpack";
export interface IKarmaConfig extends karma.Config, IKarmaConfigOptions {
transpileOnly?: boolean;
noInfo?: boolean;
coverage?: boolean;
tsconfig?: string;
set(config: IKarmaConfigOptions): void;
}
export interface IKarmaConfigOptions extends karma.ConfigOptions {
webpack: webpack.Configuration;
coverageIstanbulReporter?: any;
webpackServer: any;
customLaunchers: any;
}
export default (config: IKarmaConfig): void => {
const rules: webpack.Rule[] = [];
const options: IKarmaConfigOptions = {
basePath: config.basePath || "./",
frameworks: ["jasmine"],
files: ["test/setup.ts"],
preprocessors: {
"test/setup.ts": ["webpack", "sourcemap"]
},
webpack: {
mode: "development",
resolve: {
extensions: [".ts", ".js"],
modules: ["src", "node_modules"],
alias: {
src: path.resolve(__dirname, "src")
}
},
devtool: "cheap-module-eval-source-map",
module: {
rules: [
{
test: /\.ts$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
configFile: config.tsconfig,
transpileOnly: config.transpileOnly
}
}
]
}
},
mime: {
"text/x-typescript": ["ts"]
},
reporters: ["mocha", "progress"],
webpackServer: { noInfo: config.noInfo },
browsers: config.browsers || ["Chrome"],
customLaunchers: {
ChromeDebugging: {
base: "Chrome",
flags: ["--remote-debugging-port=9333"],
debug: true
}
}
};
if (config.coverage) {
options.webpack.module.rules.push({
enforce: "post",
exclude: /(node_modules|\.spec\.ts$)/,
loader: "istanbul-instrumenter-loader",
options: { esModules: true },
test: /src[\/\\].+\.ts$/
});
options.reporters.push("coverage-istanbul");
options.coverageIstanbulReporter = {
reports: ["html", "lcovonly", "text-summary"],
fixWebpackSourcePaths: true
};
}
config.set(options);
};