Karma not seeing test files in nested folders

20 views
Skip to first unread message

Caleb Rogers

unread,
Jun 6, 2018, 2:47:54 PM6/6/18
to karma-users
Hello,

I delve into this issue on stackoverflow, so if you want free karma there feel free to post an answer there!

I have made karma run successfully with jasmin and karma-webpack, but only on files within `test/`. It will not run tests found in, for example, `test/models/`. 

**karma.conf.js**

    var webpackConfig = require('./config/webpack/webpack.test.conf.js');
     
   
module.exports = function(config) {
      config
.set({
        basePath
: '',
        frameworks
: ['jasmine'],
         
{ pattern: 'test/**/*.spec.js', watched: true },
         
{ pattern: 'test/models/*.spec.js', watched: true }
       
],
        exclude
: [
       
],
        preprocessors
: {
           
'test/**/*.spec.js': ['webpack'],
           
'test/models/*.spec.js': ['webpack']
       
},
        webpack
: webpackConfig,
        webpackMiddleware
: {
            stats
: 'errors-only'
       
},
        reporters
: ['progress'],
        port
: 9876,
        colors
: true,    
        logLevel
: config.LOG_INFO,          
        autoWatch
: true,      
        browsers
: ['Chrome'],        
        singleRun
: false,
        concurrency
: Infinity
     
})
   
}


**test/test.spec.js** This file is seen

    describe("A suite", function () {
        it
("contains spec with an expectation", function () {
            expect
(true).toBe(true);
       
});
   
});
    describe
("Another suite", function () {
        it
("contains another spec with an expectation", function () {
            expect
(true).toBe(false);
       
});
   
});


**test/models/devicegroup.spec.js** This file is not seen

    import backbone from 'backbone';
   
    describe
("backbone", function () {
        it
("containsasdfasdfasdfasdfspec with an expectation", function () {
            expect
(true).toBe(false);
       
});
   
});





My folder structure is:

    - karma.conf.js
   
- test/
   
- - test.spec.js
   
- - models/
   
- - - devicegroup.spec.js
   
- public/
   
- - js/
   
- - - app.js


I have also tried an explicit glob pattern, which did not work

    files: [
     
{ pattern: 'test/**/*.spec.js', watched: true },
     
{ pattern: 'test/*.spec.js', watched: true },
     
{ pattern: 'test/models/devicegroup.spec.js', watched: true }
   
],


    preprocessors
: {
       
'test/**/*.spec.js': ['webpack'],
       
'test/*.spec.js': ['webpack'],
       
'test/models/devicegroup.spec.js': ['webpack']
   
},




How can I make karma see nested test folders? 

Caleb Rogers

unread,
Jun 6, 2018, 3:01:06 PM6/6/18
to karma-users

I didn't copy my karma.conf over here properly, below is how it actually looks

var webpackConfig = require('./config/webpack/webpack.test.conf.js');

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],

    files: [

      { pattern: 'test/**/*.spec.js', watched: true },
      { pattern: 'test/*.spec.js', watched: true }
    ],

    exclude: [

Caleb Rogers

unread,
Jun 6, 2018, 3:26:16 PM6/6/18
to karma-users
Please see the stack overflow question for significant updates: https://stackoverflow.com/questions/50709191/karma-not-running-tests-that-have-import-statements-in-karma-webpack

It seems that the problem wasn't nested folders, it was the existence of an `import` statement. Having an `import` statement causes karma to ignore that entire test file. 
Reply all
Reply to author
Forward
0 new messages