karma-runner / grunt-karma

Grunt plugin for Karma.
MIT License
468 stars 116 forks source link

Change the way to load files? #136

Closed lautarobock closed 6 years ago

lautarobock commented 9 years ago

It there any change of the way to load files in karma.options.files property from version 0.9.x to 0.10.x?

in 0.9.x I have this code and works fine

prj: {
    src: 'src',
    test: 'test',
    jsPattern: '**/*.js',
    files: {
        src: ['<%= prj.src %>/<%= prj.jsPattern %>'],
        srcTest: ['<%= prj.test %>/<%= prj.jsPattern %>']
    }
},
karma: {
    options: {
        files: [
            '<%= prj.files.src %>',
            '<%= prj.files.srcTest %>'
        ]
    }
}

but in 0.10.1 give me this error

WARN [config]: Invalid pattern bower_components/angular-mocks/angular-mocks.js!
Object is missing "pattern" property.

For fixing I have to change

prj: {
    src: 'src',
    test: 'test',
    jsPattern: '**/*.js',
    files: {
        src: '<%= prj.src %>/<%= prj.jsPattern %>',
        srcTest: '<%= prj.test %>/<%= prj.jsPattern %>'
    }
},
karma: {
    options: {
        files: [
            '<%= prj.files.src %>',
            '<%= prj.files.srcTest %>'
        ]
    }
}

And it works! but, How can include in karma.options.files an array of patterns like in first example?

Lalem001 commented 9 years ago

I have run into a similar issue. It is broken because grunt-karma no longer flattens the data.files property.

Re-inserting the flatten resolves the issue, but I do not know the circumstances behind why it was removed.

Care to weigh in @jpommerening , @Dignifiedquire?

jpommerening commented 9 years ago

Hey there, thanks for the @mention, I'm always happy to clean up the mess I cause, haha.

The idea was for grunt-karma to behave a little more like (most) other Grunt plugins, not to break existing functionality. There were however sooo many possible configs, some possibly broke. @Dignifiedquire already fixed some them (#134, #135, sorry for causing this!), but probably missed this one.

Let me explain:

Karma is a "multi-task". As such its configuration is split into multiple targets. For example karma.unit and karma.e2e. Each target can have its own .options. All these options inherit from karma.options, kind of like "global" options. To make matters worse, Grunt usually expects files besides the options, not inside.

So, to keep it short, there's a hell of a lot places you can place files here, some of them work, some don't. Try this:

karma: {
  /* call karma:myTaskTarget, or use something else */
  myTaskTarget: {
    files: {
      src: [
        '<%= prj.files.src %>',
        '<%= prj.files.srcTest %>'
      ]
    }
  }
}
lautarobock commented 9 years ago

Thanks @jpommerening !! but is not working

WARN [config]: Invalid pattern [object Object]! 
Object is missing "pattern" property.

I've create a repo with bug reproduction. please try to reproduce it, will take a few minutes Repo: https://github.com/lautarobock/bug-grunt-karma In README.md define steps for reproduction

Thanks!

Lalem001 commented 9 years ago

Hey @lautarobock, based on the feedback from @jpommerening, I was able to resolve my issue.

Based on your github repo example, I suspect the following would resolve your issue:

karma: {
    options: {
        frameworks: ['jasmine'],
        browsers: ['PhantomJS'],
        plugins: [
            'karma-jasmine',
            'karma-phantomjs-launcher'
        ],
        singleRun: true
    },
    build: {
        files: {
            src: [
                '<%= prj.dependencies %>',
                '<%= prj.devDependencies %>',
                '<%= prj.files.src %>',
                '<%= prj.files.srcTest %>'
            ]
        }
    }
}
lautarobock commented 9 years ago

mmm.... yes, it work, but I need to put files inside of karma.options for sharing between different subtask.

in my real scenario I have 2 different which share same files

karma: {
    options: {
        files: [
            '<%= prj.files.src %>',
            '<%= prj.files.srcTest %>'
        ]
    },
    build {
        //config for build
    },
    release: {
        //other config for release
    }
}
Lalem001 commented 9 years ago

I have the same setup actually. I did something like this:

karma: {
    options: {
        frameworks: ['jasmine'],
        browsers: ['PhantomJS'],
        plugins: [
            'karma-jasmine',
            'karma-phantomjs-launcher'
        ],
        singleRun: true
    },
    build: {
        files: {
            src: [
                '<%= prj.dependencies %>',
                '<%= prj.devDependencies %>',
                '<%= prj.files.src %>',
                '<%= prj.files.srcTest %>'
            ]
        }
    },
    release: {
        files: '<%= karma.build.files %>'
    }
}
lautarobock commented 9 years ago

Great! thanks!

Krinkle commented 6 years ago

(Triaging issues with more than a year of inactivity)

The flattening of files was fixed in https://github.com/karma-runner/grunt-karma/pull/150 and furher tested and improved with https://github.com/karma-runner/grunt-karma/pull/262 andd https://github.com/karma-runner/grunt-karma/pull/263.

If you experience a problem with the current version, please report it as a new issue.