forked from naver/billboard.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.cjs
139 lines (122 loc) · 3.21 KB
/
karma.conf.cjs
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
/* eslint-disable */
// @ts-nocheck
// import {webpack} from "webpack";
// import {platform} from "os";
const webpack = require("webpack");
const isWin = require("os").platform() === "win32";
// file extension to be tested
const fileExtensions = /(\.[jt]s)$/;
module.exports = function(config) {
const {TEST_TYPE: type = false} = process.env;
const isCoverage = type === "coverage";
const isChrome = type === "chrome";
const karmaConfig = {
frameworks: ["mocha", "chai", "sinon", "webpack"],
files: [
"./node_modules/lite-fixture/index.js",
"./node_modules/hammer-simulator/index.js",
"./test/assets/hammer-simulator.run.js",
"./src/scss/billboard.scss",
"./test/assets/common.css",
"./test/**/*-spec.ts",
{
pattern: "./test/assets/data/*",
watched: false,
included: false,
served: true
}
],
client: {
mocha: {
opts: "./mocha.opts"
}
},
webpack: {
devtool: "cheap-module-source-map",
mode: "development",
stats: "none",
resolve: {
extensions: [".ts", ".js"]
},
target: ["web", "es5"],
module: {
rules: [
{
test: /(\.[jt]s)$/,
loader: "babel-loader",
exclude: {
and: [/node_modules/],
not: [/(d3\-.*)$/]
}
}
]
},
optimization: {
usedExports: true
},
plugins: isWin ? [
new webpack.NormalModuleReplacementPlugin(
/module\/util/i, function(resource) {
resource.request = resource.request.replace("module/util", "../test/assets/module/util");
}
),
new webpack.NormalModuleReplacementPlugin(
/fake/i, function(resource) {
if (/test\\assets\\module/i.test(resource.context)) {
resource.request = "../../../src/module/util";
}
}
)
] : [
new webpack.NormalModuleReplacementPlugin(
/module\/util\.ts/i, "../../test/assets/module/util.ts"
),
new webpack.NormalModuleReplacementPlugin(
/fake\.ts/i, "../../../src/module/util.ts"
)
]
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"./src/scss/billboard.scss": ["scss"],
"./test/**/*-spec.ts": isCoverage ? ["webpack"] : ["webpack", "sourcemap"],
},
scssPreprocessor: {
options: {
sourceMap: true,
outputStyle: "expanded",
}
},
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [],
reporters: ["mocha"],
colors: true,
webpackMiddleware: {
logLevel: "error"
},
// https://github.com/karma-runner/karma/blob/master/docs/config/01-configuration-file.md#browsernoactivitytimeout
browserNoActivityTimeout: 50000
};
karmaConfig.browsers.push(isChrome ? "Chrome" : "ChromeHeadless");
if (isCoverage) {
karmaConfig.reporters.push("coverage-istanbul");
karmaConfig.coverageIstanbulReporter = {
reports: ["text-summary", "html", "lcovonly"],
dir: "./coverage"
};
karmaConfig.webpack.module.rules.unshift({
test: fileExtensions,
exclude: /(node_modules|test)/,
use: {
loader: "istanbul-instrumenter-loader",
options: {
esModules: true
}
}
});
karmaConfig.singleRun = true;
}
config.set(karmaConfig);
};