Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data.files is replaced #236

Closed
bkrrrr opened this issue Apr 2, 2017 · 1 comment
Closed

data.files is replaced #236

bkrrrr opened this issue Apr 2, 2017 · 1 comment
Assignees

Comments

@bkrrrr
Copy link

bkrrrr commented Apr 2, 2017

It seems like its not possible right now to use files in options and another target. Or at least the output is not as expected.

What is the idea behind that block (grunt-karma.js:74)?

    if (data.files || options.files) {
      data.files = [].concat.apply(options.files || [], this.files.map(function (file) {
        return file.src.map(function (src) {
          var obj = {
            pattern: src
          }
          var opts = ['watched', 'served', 'included']
          opts.forEach(function (opt) {
            if (opt in file) {
              obj[opt] = file[opt]
            }
          })
          return obj
        })
      }))
      data.files = _.flattenDeep(data.files)
    }

by replacing this with:

if (data.files || options.files) {   
      data.files = data.files || [];
      if(options.files){
        data.files = data.files.concat(options.files)
      }
 }

files is usable as expected

@Krinkle Krinkle changed the title Question to implementation data.files is replaced Aug 27, 2018
@Krinkle Krinkle self-assigned this Aug 27, 2018
@Krinkle
Copy link
Collaborator

Krinkle commented Aug 27, 2018

@bkrrrr I investigated the issue and I understand the code now. However, just as you, I also thought it was a mistake.

The code looks like it is forgetting to add the contents of data.files. But, I understand it now.

The data.files key of the task data, cannot be used directly. It must be processed and expanded by Grunt internally. The processed version is available to the Grunt plugin as this.files. As such, no information is lost. It is working as expected.

Krinkle added a commit that referenced this issue Aug 27, 2018
- This feature was added in pull #150 without a test.
  It now has a test.

- The code was applying the flatten operation to all input,
  but should really only be applied to `options.files`, not to
  this.files from Grunt, which is already processed.

- The code was checking `data.files` but using `this.files`.
  This is working correctly, but looks confusing to a reader.
  `data.files` is the raw input, and `this.files` is the version
  of that input after processing by Grunt.
  To improve readability, use that same reference for the check
  as well. In order to keep behaviour identical, use the array's
  length property to determine whether it was set. The files
  array is always available from Grunt, and can be safely accessed
  without additional check. This is covered by the karma:config
  test case, which specifies neither options.files nor data.files.

Ref #150.
Closes #236.
Krinkle added a commit that referenced this issue Aug 27, 2018
- This feature was added in pull #150 without a test.
  It now has a test.

- The code was applying the flatten operation to all input,
  but should really only be applied to `options.files`, not to
  this.files from Grunt, which is already processed.

- The code was checking `data.files` but using `this.files`.
  This is working correctly, but looks confusing to a reader.
  `data.files` is the raw input, and `this.files` is the version
  of that input after processing by Grunt.
  To improve readability, use that same reference for the check
  as well. In order to keep behaviour identical, use the array's
  length property to determine whether it was set. The files
  array is always available from Grunt, and can be safely accessed
  without additional check. This is covered by the karma:config
  test case, which specifies neither options.files nor data.files.

Ref #150.
Closes #236.
Krinkle added a commit that referenced this issue Aug 28, 2018
- This feature was added in pull #150 without a test.
  It now has a test.

- The code was applying the flatten operation to all input,
  but should really only be applied to `options.files`, not to
  this.files from Grunt, which is already processed.

- The code was checking `data.files` but using `this.files`.
  This is working correctly, but looks confusing to a reader.
  `data.files` is the raw input, and `this.files` is the version
  of that input after processing by Grunt.
  To improve readability, use that same reference for the check
  as well. In order to keep behaviour identical, use the array's
  length property to determine whether it was set. The files
  array is always available from Grunt, and can be safely accessed
  without additional check. This is covered by the karma:config
  test case, which specifies neither options.files nor data.files.

Ref #150.
Closes #236.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants