forked from ZeeCoder/use-resize-observer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.conf.js
173 lines (165 loc) · 4.41 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
// @see https://www.browserstack.com/automate/capabilities
const customLaunchers = {
modern: {
bs_chrome_latest: {
base: "BrowserStack",
os: "Windows",
os_version: "10",
browser: "Chrome",
browser_version: "latest",
},
bs_firefox_latest: {
base: "BrowserStack",
os: "Windows",
os_version: "10",
browser: "Firefox",
browser_version: "latest",
},
bs_edge_latest: {
base: "BrowserStack",
os: "Windows",
os_version: "10",
browser: "Edge",
browser_version: "latest",
},
bs_opera_latest: {
base: "BrowserStack",
os: "Windows",
os_version: "10",
browser: "Opera",
browser_version: "latest",
},
// Safari 13 is very important to be listed here, as while it does have an RO implementation,
// it does not support different box sizes, only content-box.
bs_safari_13: {
base: "BrowserStack",
os: "OS X",
os_version: "Catalina",
browser: "Safari",
browser_version: "13.0",
},
bs_ios_14: {
base: "BrowserStack",
device: "iPhone 11",
os: "ios",
os_version: "14",
},
bs_samsung: {
base: "BrowserStack",
device: "Samsung Galaxy Note 10",
os: "Android",
os_version: "9.0",
},
},
legacy: {
bs_ios_11: {
base: "BrowserStack",
device: "iPhone X",
os: "ios",
os_version: "11",
},
bs_ie_11: {
base: "BrowserStack",
os: "Windows",
os_version: "10",
browser: "IE",
browser_version: "11.0",
},
},
};
module.exports = function (karmaConfig) {
const { BS_USERNAME, BS_ACCESS_KEY, KARMA_BROWSERS } = process.env;
const browsers =
KARMA_BROWSERS === "modern"
? Object.keys(customLaunchers.modern)
: KARMA_BROWSERS === "legacy"
? Object.keys(customLaunchers.legacy)
: KARMA_BROWSERS
? KARMA_BROWSERS.split(",").map((val) => val.trim())
: ["ChromeHeadless"];
const useBrowserStack = browsers[0].startsWith("bs_");
const polyfilledRun = browsers.reduce(
(carry, browser) =>
carry || Object.keys(customLaunchers.legacy).includes(browser),
false
);
let testFilePattern = "tests/*.tsx";
// let testFilePattern = "tests/ssr.test.tsx";
// let testFilePattern = "tests/basic.tsx";
// let testFilePattern = "tests/testing-lib.tsx";
let transpileExcludePattern = /node_modules/;
let presetEndModules = false;
let transformRuntimeUseESModules = true;
if (polyfilledRun) {
// IE runs a special set of (polyfilled) tests
testFilePattern = "tests/ie/*.tsx";
// Processing everything (including node_modules) for IE11 to make sure 3rd
// party deps can run during the tests.
transpileExcludePattern = /^$/;
presetEndModules = "commonjs";
transformRuntimeUseESModules = false;
}
const config = {
basePath: ".",
frameworks: ["jasmine", "webpack"],
files: [
{
pattern: testFilePattern,
watched: !useBrowserStack,
},
],
reporters: ["spec"],
preprocessors: {
[testFilePattern]: ["webpack", "sourcemap"],
},
...(useBrowserStack && {
browserStack: {
username: BS_USERNAME,
accessKey: BS_ACCESS_KEY,
project: "use-resize-observer",
},
}),
// @see https://karma-runner.github.io/5.2/config/files.html
autoWatch: !useBrowserStack,
browsers,
customLaunchers: {
...customLaunchers.modern,
...customLaunchers.legacy,
},
webpack: {
mode: "development",
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: transpileExcludePattern,
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{ loose: true, modules: presetEndModules },
],
"@babel/preset-react",
"@babel/preset-typescript",
],
plugins: [
[
"@babel/transform-runtime",
{ useESModules: transformRuntimeUseESModules },
],
],
},
},
},
],
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
},
},
};
karmaConfig.set(config);
};