-
Notifications
You must be signed in to change notification settings - Fork 60
/
karma.conf.ts
139 lines (129 loc) · 3.49 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
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
import * as karma from 'karma';
import * as webpack from 'webpack';
import getCustomLaunchers from './getCustomLaunchers';
// tslint:disable-next-line no-var-requires
require('dotenv').config();
const isCI = !!process.env.CI;
const isLocal = !!process.env.KARMA_LOCAL;
if (
isCI &&
process.env.TRAVIS_PULL_REQUEST !== 'false' &&
process.env.TRAVIS_SECURE_ENV_VARS !== 'true'
) {
console.info('Karma tests do not run for external pull requests');
process.exit(0);
}
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.error('SAUCE_USERNAME and SAUCE_ACCESS_KEY must both be set');
process.exit(1);
}
export type KarmaConfigOptions = karma.ConfigOptions & {
customLaunchers?: { [key: string]: any };
sauceLabs?: any;
webpack?: webpack.Configuration;
webpackServer?: any;
};
export interface KarmaConfig extends karma.Config {
set: (config: KarmaConfigOptions) => void;
}
export default (config: KarmaConfig) => {
if (isLocal) {
config.set({
browsers: ['ChromeHeadless'],
concurrency: 1,
reporters: ['progress'],
});
} else {
const customLaunchers = getCustomLaunchers();
config.set({
browsers: Object.keys(customLaunchers),
concurrency: 5,
customLaunchers,
reporters: ['progress', 'saucelabs'],
});
}
let tunnelIdentifier;
if (isCI) {
tunnelIdentifier = process.env.TRAVIS_JOB_NUMBER;
}
// tslint:disable object-literal-sort-keys
const webpackConfig: webpack.Configuration = {
devtool: 'inline-source-map',
mode: 'development',
resolve: {
alias: {
jsxstyle: require.resolve('../packages/jsxstyle'),
'jsxstyle-utils': require.resolve('../packages/jsxstyle-utils'),
react: require.resolve('react'),
'react-dom': require.resolve('react-dom'),
},
extensions: ['.ts', '.tsx', '.js', '.json'],
},
performance: { hints: false },
module: {
rules: [
{
test: /\.(js|tsx?)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: { browsers: ['last 2 versions'] },
},
],
'@babel/preset-react',
],
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-object-assign',
],
},
},
{
test: /\.tsx?/,
loader: require.resolve('ts-loader'),
},
],
},
};
// tslint:enable object-literal-sort-keys
config.set({
autoWatch: false,
// 30 seconds
browserNoActivityTimeout: 30000,
// three minutes
captureTimeout: 180000,
colors: true,
files: ['**/*.karma.tsx'],
frameworks: ['jasmine'],
// LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
logLevel: config.LOG_INFO,
port: 9876,
preprocessors: {
'**/*.karma.tsx': ['webpack', 'sourcemap'],
},
sauceLabs: {
connectOptions: {
connectRetries: 2,
logfile: 'sauce_connect.log',
},
recordScreenshots: true,
recordVideo: true,
startConnect: !isCI,
tags: isCI
? ['ci', 'travis:' + process.env.TRAVIS_EVENT_TYPE]
: ['local'],
tunnelIdentifier,
},
singleRun: true,
webpack: webpackConfig,
webpackServer: {
noInfo: true,
},
});
};