Blame view

karma.conf.js 5.43 KB
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
1
/* global process, */
33ee6d0a   Victor Costa   Initial commit
2
3
4
5
6
'use strict';

var path = require('path');
var conf = require('./gulp/conf');

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
7
8
var argv = require("yargs").argv;

babe9d57   ABNER SILVA DE OLIVEIRA   testing scripts a...
9
var singleRun = (argv.singleRun !== undefined && argv.singleRun);
78b1f609   Ábner Oliveira   changes to make c...
10
11
var coverage = (argv.coverage === undefined || argv.coverage);

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
12
13
14
15
16
17
18

if (argv.singleRun) {
    singleRun = true;
}

var projectFiles = [
    './src/commons.js',
78b1f609   Ábner Oliveira   changes to make c...
19
    './src/vendor.bundle.js',
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
20
21
22
23
24
25
26
27
28
29
30
31
    './src/noosfero.js',
    './src/noosfero-specs.js'
];

var karmaPlugins = [
    'karma-chrome-launcher',
    'karma-phantomjs-launcher',
    'karma-angular-filesort',
    'karma-phantomjs-shim',
    'karma-jasmine',
    'karma-spec-reporter',
    'karma-ng-html2js-preprocessor',
78b1f609   Ábner Oliveira   changes to make c...
32
33
    'karma-sourcemap-loader',
    'karma-coverage'
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
34
35
36
];


78b1f609   Ábner Oliveira   changes to make c...
37
var karmaReporters = ['spec', 'coverage'];
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
38

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
39

babe9d57   ABNER SILVA DE OLIVEIRA   testing scripts a...
40

78b1f609   Ábner Oliveira   changes to make c...
41
42
43
44
// if (coverage) {
//     karmaPlugins.push('karma-coverage');
//     karmaReporters.push('coverage');
// }
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
45

4dc814d9   Ábner Oliveira   ajustes nos testes
46

babe9d57   ABNER SILVA DE OLIVEIRA   testing scripts a...
47

33ee6d0a   Victor Costa   Initial commit
48
49
50
51
var _ = require('lodash');
var wiredep = require('wiredep');

var pathSrcHtml = [
7b6978a6   Victor Costa   Fix html path in ...
52
    path.join('./src/**/*.html')
33ee6d0a   Victor Costa   Initial commit
53
54
];

69b2897c   ABNER SILVA DE OLIVEIRA   npm test now run ...
55
var glob = require("glob");
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
56
//var testFiles = glob.sync("./src/**/*.[sS]pec.ts");
69b2897c   ABNER SILVA DE OLIVEIRA   npm test now run ...
57

33ee6d0a   Victor Costa   Initial commit
58
function listFiles() {
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
59
60
61
62
63
    var wiredepOptions = _.extend({}, conf.wiredep, {
        dependencies: true,
        devDependencies: true
    });

4dc814d9   Ábner Oliveira   ajustes nos testes
64
    var patterns = [].concat(wiredep(wiredepOptions).js)
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
65
        .concat(projectFiles)
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
66
67
68
69
70
71
72
73
74
75
76
77
78
        .concat(pathSrcHtml);

    var files = patterns.map(function (pattern) {
        return {
            pattern: pattern
        };
    });
    files.push({
        pattern: path.join(conf.paths.src, '/assets/**/*'),
        included: false,
        served: true,
        watched: false
    });
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
79
80
81
82
83
    // files.push({
    //     pattern: path.join(conf.paths.src, '/test.js.map'),
    //     included: false,
    //     served: true
    // });
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
84
    return files;
33ee6d0a   Victor Costa   Initial commit
85
86
}

79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
87
88
89
90
91
var webpackConfig = require("./webpack.config.js");

module.exports = function (config) {

    var configuration = {
2e2ffa6a   Michel Felipe   change karma base...
92
        basePath: './',
78b1f609   Ábner Oliveira   changes to make c...
93

79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
94
95
        files: listFiles(),

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
96
        singleRun: singleRun,
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
97
98
99
100
101
102
103
104

        autoWatch: true,
        colors: true,

        logLevel: config.LOG_INFO,

        ngHtml2JsPreprocessor: {
            stripPrefix: conf.paths.src + '/',
8edc8a6f   ABNER SILVA DE OLIVEIRA   article directive...
105
            moduleName: 'templates'
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
106
107
108
        },


4dc814d9   Ábner Oliveira   ajustes nos testes
109
        frameworks: ['jasmine', 'phantomjs-shim'],//, 'angular-filesort'],
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
110
111
112
113
114

        angularFilesort: {
            whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
        },

4dc814d9   Ábner Oliveira   ajustes nos testes
115
116
        browsers: ['PhantomJS'],

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
117
118
119
120
121
        plugins: karmaPlugins,



        reporters: karmaReporters,
79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
122
123
124
125
126

        proxies: {
            '/assets/': path.join('/base/', conf.paths.src, '/assets/')
        }
    };
33ee6d0a   Victor Costa   Initial commit
127

d2590816   ABNER SILVA DE OLIVEIRA   added coverage task
128

076a7f18   Victor Costa   Accept grep param...
129
130
131
132
    if(config.grep) {
      configuration.client = { args: ['--grep', config.grep] };
    }

babe9d57   ABNER SILVA DE OLIVEIRA   testing scripts a...
133
    if (coverage) {
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

        /*configuration.webpack = {
            module: {
                loaders: [
                    {
                        test: /\.tsx?$/,
                        loader: 'ts-loader'
                    }
                ]
            },
            resolve: {
                extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js'],
                modulesDirectories: ['node_modules'],
                root: path.resolve(__dirname)
            }
        };*/
        /*configuration.webpack = _.merge({
2e2ffa6a   Michel Felipe   change karma base...
151

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
152
153
154
155
156
157
         }, webpackConfig, {
             devtool: 'source-map'
         }),
         configuration.webpackServer = {
             quite: true
         };*/
2e2ffa6a   Michel Felipe   change karma base...
158

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
159
160
161
162
163
        // This is the default preprocessors configuration for a usage with Karma cli
        // The coverage preprocessor is added in gulp/unit-test.js only for single tests
        // It was not possible to do it there because karma doesn't let us now if we are
        // running a single test or not
        configuration.preprocessors = {
78b1f609   Ábner Oliveira   changes to make c...
164
165
166
            'src/noosfero.js': ['sourcemap', 'coverage'],
            'src/**/*.ts': ['sourcemap']

6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
167
168
169
170
171
        };

        configuration.coverageReporter = {
            dir: 'coverage/',
            reporters: [
78b1f609   Ábner Oliveira   changes to make c...
172
                { type: 'html' },
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
173
174
175
176
177
178
179
180
181
182
                { type: 'json', file: 'coverage-final.json' },
                { type: 'text-summary' }
            ]
        };
    } else {
        // This is the default preprocessors configuration for a usage with Karma cli
        // The coverage preprocessor is added in gulp/unit-test.js only for single tests
        // It was not possible to do it there because karma doesn't let us now if we are
        // running a single test or not
        configuration.preprocessors = {
78b1f609   Ábner Oliveira   changes to make c...
183
            'src/noosfero': ['coverage', 'sourcemap'],
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
184
185
            'src/**/*.ts': ['sourcemap']
        };
78b1f609   Ábner Oliveira   changes to make c...
186
187
188
189
190
191
192
193
194

        configuration.coverageReporter = {
            dir: 'coverage/',
            reporters: [
                { type: 'html' },
                { type: 'json', file: 'coverage-final.json' },
                { type: 'text-summary' }
            ]
        };
6f744e76   ABNER SILVA DE OLIVEIRA   added coverage
195
    }
78b1f609   Ábner Oliveira   changes to make c...
196
197


79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
    pathSrcHtml.forEach(function (path) {
        configuration.preprocessors[path] = ['ng-html2js'];
    });

    // This block is needed to execute Chrome on Travis
    // If you ever plan to use Chrome and Travis, you can keep it
    // If not, you can safely remove it
    // https://github.com/karma-runner/karma/issues/1144#issuecomment-53633076
    if (configuration.browsers[0] === 'Chrome' && process.env.TRAVIS) {
        configuration.customLaunchers = {
            'chrome-travis-ci': {
                base: 'Chrome',
                flags: ['--no-sandbox']
            }
        };
        configuration.browsers = ['chrome-travis-ci'];
33ee6d0a   Victor Costa   Initial commit
214
    }
33ee6d0a   Victor Costa   Initial commit
215

79e99040   ABNER SILVA DE OLIVEIRA   versão inicial co...
216
    config.set(configuration);
33ee6d0a   Victor Costa   Initial commit
217
};