UNPKG

4.08 kBJavaScriptView Raw
1// Karma configuration
2var config =
3module.exports = function(config) {
4
5 config.set({
6
7 // base path that will be used to resolve all patterns (eg. files, exclude)
8 basePath: './',
9
10
11 // frameworks to use
12 // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13 frameworks: ['jasmine'],
14
15
16 // list of files / patterns to load in the browser
17 files: [
18 'node_modules/jquery/dist/jquery.js',
19 'node_modules/bootstrap/dist/js/bootstrap.js',
20 'node_modules/patternfly-bootstrap-combobox/js/bootstrap-combobox.js',
21 'node_modules/bootstrap-datepicker/dist/js/bootstrap-datepicker.js',
22 'node_modules/bootstrap-select/dist/js/bootstrap-select.js',
23 'node_modules/datatables.net/js/jquery.dataTables.js',
24 'node_modules/datatables.net-select/js/dataTables.select.js',
25 'node_modules/bootstrap-switch/dist/js/bootstrap-switch.js',
26 'node_modules/patternfly-bootstrap-treeview/src/js/bootstrap-treeview.js',
27 'node_modules/c3/c3.js',
28 'node_modules/d3/d3.js',
29 'node_modules/jasmine-jquery/lib/jasmine-jquery.js',
30 {pattern: 'dist/img/**/*', watched: true, included: false, served: true},
31 {pattern: 'dist/fonts/**/*', watched: true, included: false, served: true},
32 {pattern: 'dist/css/*.map', watched: true, included: false, served: true},
33 'dist/css/*.css',
34 'dist/js/patternfly.js',
35 'dist/js/patternfly.min.js',
36 {pattern: 'dist/tests/**/*', watched: true, included: false, served: true},
37
38 //tests
39 'tests/unit/globals.js',
40 'tests/unit/*.spec.js'
41 ],
42
43
44 // list of files to exclude
45 exclude: [
46 ],
47
48
49 // preprocess matching files before serving them to the browser
50 // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
51 preprocessors: {
52 },
53
54
55 // test results reporter to use
56 // possible values: 'dots', 'progress'
57 // available reporters: https://npmjs.org/browse/keyword/karma-reporter
58 reporters: ['progress'],
59
60
61 // web server port
62 port: 9876,
63
64
65 // enable / disable colors in the output (reporters and logs)
66 colors: true,
67
68
69 // level of logging
70 // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
71 logLevel: config.LOG_INFO,
72
73
74 // enable / disable watching file and executing tests whenever any file changes
75 autoWatch: true,
76
77
78 // start these browsers
79 // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
80 browsers: ['PhantomJS'],
81
82 //custom middleware intercepts
83 middleware: ['custom'],
84
85 //Plugins
86 plugins: [
87 'karma-jasmine',
88 'karma-chrome-launcher',
89 'karma-firefox-launcher',
90 'karma-phantomjs-launcher',
91 {'middleware:custom': ['factory', CustomMiddlewareFactory]}
92 ],
93
94 // Continuous Integration mode
95 // if true, Karma captures browsers, runs the tests and exits
96 singleRun: true,
97
98 //Browser inactivity timeout 100s
99 browserNoActivityTimeout: 100000
100 });
101};
102
103//Custom Middleware for handling relative file path references inside test fixtures
104var fs = require('fs');
105
106var CustomMiddlewareFactory = function (config) {
107 return function (request, response) {
108 //maps "../dist" requests in test fixtures to "dist" on the local file system
109 if(/^\/dist*/.test(request.url)){
110 var newPath = request._parsedUrl.pathname.substring(1);
111 var file = fs.readFileSync(newPath, "utf8");
112
113 if(config.logLevel === config.LOG_DEBUG){
114 console.log('Intercepted:' + request.url + ' Serving: ' + newPath);
115 }
116
117 if(request.url.indexOf('.svg') > 0) {
118 response.writeHeader(200, {'Content-Type': 'image/svg+xml'});
119 } else if (request.url.indexOf('.js') > 0) {
120 response.writeHeader(200, {'Content-Type': 'application/javascript'});
121 } else if (request.url.indexOf('.css') > 0) {
122 response.writeHeader(200, {'Content-Type': 'text/css'});
123 }
124
125 response.write(file);
126 }
127 return response.end();
128 }
129};