karma-runner / karma-commonjs

A Karma plugin. Test CommonJS modules.
MIT License
73 stars 30 forks source link

Could not find any modules. Did you remember to set 'preprocessors' in your Karma config? #51

Open hrietman opened 8 years ago

hrietman commented 8 years ago

Followed the configuration in the read me but I am getting the following error:

Error: Could not find any modules. Did you remember to set 'preprocessors' in your Karma config?
  at /Development/codecentric/angular2-hamis-seed/node_modules/karma-commonjs/client/commonjs_bridge.js:5
basePath: '',

        frameworks: ['jasmine', 'commonjs'],
        browsers: ['PhantomJS'],
        reporters: ['progress', 'coverage'],

        preprocessors: {
            'app/**/!(*.spec)+(.js)': ['coverage'],
            'app/**/*.js': ['sourcemap'],
            'app/**/*.js': ['commonjs']
        },

        commonjsPreprocessor: {
            modulesRoot: 'node_modules'
        },

I also tried setting the commonjs Preprocessor option but did not help.

Part of the config:

Any idea's?

jamesshore commented 8 years ago

Did you set the files option?

hrietman commented 8 years ago

Yes I did,

files: [
            // paths loaded by Karma
            {pattern: 'node_modules/es6-shim/es6-shim.min.js', included: true, watched: true},
            {pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true},

            {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true},
            {pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true},
            {pattern: 'node_modules/reflect-metadata/temp/Reflect.js', included: true, watched: true},
            {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true},
            {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true},
            {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true},
            {pattern: 'karma-test-shim.js', included: true, watched: true},
           // {pattern: 'src/test/matchers.js', included: true, watched: true},

            // paths loaded via module imports
            {pattern: 'src/**/*.js', included: false, watched: true},

            // paths loaded via Angular's component compiler
            // (these paths need to be rewritten, see proxies section)
            {pattern: 'src/**/*.html', included: false, watched: true},
            {pattern: 'src/**/*.css', included: false, watched: true},

            // paths to support debugging with source maps in dev tools
            {pattern: 'src/**/*.ts', included: false, watched: false},
            {pattern: 'src/**/*.js.map', included: false, watched: false},

            {pattern: 'test/karma/specs/**/*.js', included: false, watched: false},

        ],

Reading up on the other issues, it seems it has to do with dependencies on modules in the node_modules folder.

brandonros commented 7 years ago

Any updates @hrietman ?

hrietman commented 7 years ago

@brandonros This is almost a year ago; I since moved on with Angular-cli to setup projects; however here is my current karma configuration, maybe it helps you further:

`

module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', 'angular-cli'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-phantomjs-launcher'), require('karma-remap-istanbul'), require('angular-cli/plugins/karma'), require("karma-spec-reporter") ], files: [ {pattern: './src/test.ts', watched: false} ], preprocessors: { './src/test.ts': ['angular-cli'] }, mime: { 'text/x-typescript': ['ts', 'tsx'] }, remapIstanbulReporter: { reports: { html: 'coverage', lcovonly: './coverage/coverage.lcov' } }, angularCli: { config: './angular-cli.json', environment: 'dev' }, specReporter: { maxLogLines: 5, // limit number of lines logged per test suppressErrorSummary: true, // do not print error summary suppressFailed: false, // do not print information about failed tests suppressPassed: false, // do not print information about passed tests suppressSkipped: true, // do not print information about skipped tests showSpecTiming: false // print the time elapsed for each spec }, reporters: config.angularCli && config.angularCli.codeCoverage ? ['spec', 'karma-remap-istanbul'] : ['spec'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: false, browsers: ['PhantomJS'], singleRun: true, browserNoActivityTimeout: 60000 }); }; `