This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.config.js
108 lines (92 loc) · 2.98 KB
/
karma.config.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
/**
* Copyright 2017 aixigo AG
* Released under the MIT license.
* http://laxarjs.org/license
*/
/* eslint-env node */
module.exports = function( config ) {
config.set( karmaConfig() );
};
const karma = require( 'karma' );
const path = require( 'path' );
const resolve = p => path.resolve( __dirname, p );
const polyfillsPath = resolve( 'node_modules/laxar/dist/polyfills.js' );
const specsPattern = resolve( './application/widgets/**/spec/*.spec.js' );
const assetsPatterns = [
resolve( './application/widgets/**/*.css' ),
resolve( './application/widgets/**/*.scss' ),
resolve( './node_modules/laxar-uikit/themes/default.theme/{css,fonts}/*.*' )
];
if( require.main === module ) {
const configs = require( 'glob' ).sync( specsPattern ).map( karmaConfigForWidget );
run( configs );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function karmaConfig() {
const browsers = [
'PhantomJS'
];
return {
frameworks: [ 'jasmine' ],
files: files( specsPattern, [ polyfillsPath ], assetsPatterns ),
preprocessors: {
[ specsPattern ]: [ 'webpack', 'sourcemap' ]
},
proxies: {
'/widgets': '/base/widgets',
'/lib': '/base/lib'
},
webpack: webpackConfig(),
webpackMiddleware: {
noInfo: true,
quiet: true
},
reporters: [ 'progress' ],
port: 9876,
browsers,
customLaunchers: {
ChromeTravisCi: {
base: 'Chrome',
flags: [ '--no-sandbox' ]
}
},
browserNoActivityTimeout: 100000,
singleRun: true,
autoWatch: false
};
}
function karmaConfigForWidget( specPath ) {
return Object.assign( karmaConfig(), {
name: path.basename( specPath ),
files: files( specPath, [ polyfillsPath ], assetsPatterns )
} );
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function webpackConfig() {
const config = require('./webpack.config' )();
delete config.entry;
config.devtool = 'inline-source-map';
return config;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function run( configs, lastExitCode ) {
if( !configs.length || lastExitCode ) {
process.exit( lastExitCode );
}
const config = configs.shift();
const specFile = config.files[ 1 ];
process.stdout.write( `Karma: launching ${specFile}\n` );
const server = new karma.Server( config, exitCode => {
process.stdout.write( `Karma: exited with ${exitCode}\n` );
run( configs, exitCode );
} );
server.start();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function files( specPath, dependencyPatterns, assetsPatterns ) {
return [
...dependencyPatterns,
specPath,
...assetsPatterns.map( pattern => ( { pattern, included: false } ) )
];
}