klei/gulp-inject

Broken inject function with tags(starttag, endtag)

docech opened this issue · 3 comments

Hello I would like to report broken inject function with starttag, endtag options. Inject function always inject only one file.

This behavior is most probably because of latest dependency group-array: 0.3.4. It seems to me that group-array does not group tags properly.

With group-array: 0.3.3 everything works fine.

> mocha -R spec src/**/*_test.js

  gulp-inject
    ✓ should throw an error when the old api with target as string is used
    ✓ should throw an error if sources stream is undefined
    ✓ should throw an error if `templateString` option is specified
    ✓ should throw an error if `sort` option is specified
[14:41:25] gulp-inject 5 files into template.html.
    ✓ should inject stylesheets, scripts, images, jsx and html components into desired file
[14:41:25] gulp-inject 5 files into template.html.
[14:41:25] gulp-inject 1 file into template2.html.
    ✓ should inject sources into multiple targets
[14:41:25] gulp-inject 5 files into template.html.
    ✓ should inject stylesheets, scripts and html components with `ignorePath` removed from file path
[14:41:25] gulp-inject 5 files into template.html.
    ✓ should inject stylesheets, scripts and html components with relative paths to target file if `relative` is truthy
[14:41:25] gulp-inject 5 files into template.html.
    ✓ should inject stylesheets, scripts and html components with `addPrefix` added to file path
[14:41:25] gulp-inject 5 files into template.html.
    ✓ should inject stylesheets, scripts and html components with `addSuffix` added to file path
[14:41:25] gulp-inject 2 files into template.html.
    ✓ should inject stylesheets and html components with self closing tags if `selfClosingTag` is truthy
[14:41:25] gulp-inject 4 files into template.html.
    ✓ should inject stylesheets, scripts and html components without root slash if `addRootSlash` is `false`
[14:41:25] gulp-inject 4 files into template.html.
    ✓ should inject stylesheets, scripts and html components without root slash if `addRootSlash` is `false` and `ignorePath` is set
[14:41:25] gulp-inject 3 files into templateCustomTags.html.
    ✓ should use starttag and endtag if specified
[14:41:25] gulp-inject 2 files into templateCustomName.html.
    ✓ should use starttag and endtag with specified name if specified
[14:41:25] gulp-inject 2 files into templateTagsWithExt.html.
    ✓ should replace {{ext}} in starttag and endtag with current file extension if specified
[14:41:25] gulp-inject 1 file into templateTagsWithPath.html.
    ✓ should replace {{path}} in starttag and endtag with current file path if specified
[14:41:25] gulp-inject 2 files into templateWithExistingData.html.
    ✓ should replace existing data within start and end tag
[14:41:25] gulp-inject 1 file into template.json.
    1) should use custom transform function for each file if specified
[14:41:25] gulp-inject 3 files into template.jsx.
    ✓ should use special default tags when injecting into jsx files
[14:41:25] gulp-inject 3 files into template.jade.
    ✓ should use special default tags when injecting into jade files
[14:41:25] gulp-inject 3 files into template.pug.
    ✓ should use special default tags when injecting into pug files
[14:41:25] gulp-inject 2 files into issue144.jade.
    ✓ should be able to inject jsx into jade files (Issue #144)
[14:41:25] gulp-inject 2 files into issue144.pug.
    ✓ should be able to inject jsx into pug files (Issue #144)
[14:41:25] gulp-inject 3 files into template.slm.
    ✓ should use special default tags when injecting into slm files
[14:41:25] gulp-inject 3 files into template.slim.
    ✓ should use special default tags when injecting into slim files
[14:41:25] gulp-inject 3 files into template.haml.
    ✓ should use special default tags when injecting into haml files
[14:41:25] gulp-inject 2 files into template.less.
    2) should use special default tags when injecting into less files
[14:41:25] gulp-inject 3 files into template.sass.
    3) should use special default tags when injecting into sass files
[14:41:25] gulp-inject 3 files into template.scss.
    4) should use special default tags when injecting into scss files
[14:41:25] gulp-inject 2 files into issue39.html.
[14:41:25] gulp-inject 2 files into issue39.html.
    ✓ should be able to chain inject calls with different names without overrides (Issue #39)
[14:41:25] gulp-inject 2 files into issue71.html.
    ✓ should be able to inject hashed files (Issue #71)
[14:41:25] gulp-inject 1 file into issue56.html.
    ✓ should be able to inject when tags are missing whitespace (Issue #56)
[14:41:25] gulp-inject Nothing to inject into issue74.html.
    ✓ should not crash when transform function returns undefined (Issue #74)
[14:41:25] gulp-inject 5 files into template.html.
    ✓ should be able to remove tags if removeTags option is set
[14:41:25] gulp-inject 7 files into template.html.
    ✓ should be able to remove tags without removing whitespace (issue #177)
    ✓ should not produce log output if quiet option is set
    ✓ should produce log output if quiet option is not set
    ✓ should produce log output only for files actually injected (issue #184)
    ✓ should produce log output for multiple files actually injected (issue #192)
[14:41:25] gulp-inject 1 file into issue107.html.
    ✓ should be able to modify only the filepath (Issue #107)
[14:41:25] gulp-inject 2 files into issue176.html.
    ✓ should be able to inject source maps (Issue #176)
[14:41:25] gulp-inject 1 file into templateWithExistingData2.html.
    ✓ should be able to empty tags when there are no files for that tag and empty option is set
[14:41:25] gulp-inject 1 file into templateWithExistingData2.html.
    ✓ should be able both leave and replace tag contents when there are no files for some tags and empty option is not set
[14:41:25] gulp-inject Nothing to inject into templateWithExistingData2.html.
    ✓ should be able to empty all tags when there are no files at all and empty option is set
[14:41:25] gulp-inject Nothing to inject into templateWithExistingData2.html.
    ✓ should leave all tags when there are no files at all and empty option is not set
[14:41:25] gulp-inject 1 file into templateWithExistingData2.html.
    ✓ should be able to remove and empty tags when there are no files for that tag and empty and removeTags option is set
[14:41:25] gulp-inject Nothing to inject into templateWithExistingData3.html.
    ✓ should be able to empty custom tags when there are no files at all and empty option is set

  getFilepath
    (relative=false)
      ✓ returns the path relative to the source file's cwd
      ✓ returns the unixified path relative to the source file's cwd
    (relative=true)
      ✓ returns the path relative to the target file's directory
      ✓ returns the unixified path relative to the source file's cwd
    (ignorePath)
      ✓ removes the provided `ignorePath` from the beginning of the path
      ✓ removes the provided `ignorePath` even if it both begins and ends in a `/` from the beginning of the path
      ✓ removes the provided `ignorePath`s from the beginning of the path
      ✓ removes the provided `ignorePath` unixified from the beginning of the path
      ✓ removes the provided `ignorePath` unixified from the beginning of a unixified path
      ✓ removes the provided `ignorePath` from the beginning of a unixified path
    (addRootSlash=true)
      ✓ prepends the path with a `/`
    (addPrefix)
      ✓ prepends the prefix and a `/` to the path
      ✓ keeps any leading `/` from the prefix
    (addSuffix)
      ✓ appends the suffix to the path

  tags
    ✓ should not crash when required
    start()
      with no default
        ✓ should return html comment tag for html target files
        ✓ should return jsx comments for jsx target files
        ✓ should return jade comments for jade target files
        ✓ should return pug comments for pug target files
        ✓ should return slm comments for slm target files
        ✓ should return haml comment tag for haml files
        ✓ should return less comment tag for less files
        ✓ should return sass comment tag for sass files
        ✓ should return sass comment tag for sass files
        ✓ should return html comment tag for other target files
      given a string as default
        ✓ should return the string
      given a function as default
        ✓ should receive target file and source file extensions as parameters
        ✓ should return result of function untouched
    end()
      with no default
        ✓ should return html comment tag for html target files
        ✓ should return jsx comments for jsx target files
        ✓ should return jade comments for jade target files
        ✓ should return pug comments for pug target files
        ✓ should return slm comments for slm target files
        ✓ should return haml comments for haml target files
        ✓ should return haml comments for haml target files
        ✓ should return sass comments for sass target files
        ✓ should return scss comments for scss target files
        ✓ should return html comment tag for other target files
      given a string as default
        ✓ should return the string
      given a function as default
        ✓ should receive target file and source file extensions as parameters
        ✓ should return result of function untouched

  transform
    ✓ should not crash when required
    ✓ should be a function
    ✓ should pick the correct target transformer for html targets
    ✓ should pick the correct target transformer for jsx targets
    ✓ should pick the correct target transformer for jade targets
    ✓ should pick the correct target transformer for pug targets
    ✓ should pick the correct target transformer for slm targets
    ✓ should pick the correct target transformer for haml targets
    ✓ should pick the correct target transformer for less targets
    ✓ should pick the correct target transformer for sass targets
    ✓ should pick the correct target transformer for scss targets
    ✓ should default to the html target transformer for other files
    ✓ should default to the html target transformer for unknown files
    targets
      ✓ should have a transform function for html target files
      ✓ should have a transform function for react javascript (jsx) target files
      ✓ should have a transform function for jade target files
      ✓ should have a transform function for pug target files
      ✓ should have a transform function for slm target files
      ✓ should have a transform function for haml target files
      ✓ should have a transform function for less target files
      ✓ should have a transform function for sass target files
      ✓ should have a transform function for scss target files
    html as target
      ✓ should transform css to a link tag
      ✓ should transform html to a link tag
      ✓ should transform javascript to a script tag
      ✓ should transform jsx to a script tag
      ✓ should transform coffeescript to a script tag
      ✓ should transform an image to an img tag
      ✓ should use the css transformer for css files automatically
      ✓ should use the html transformer for html files automatically
      ✓ should use the js transformer for js files automatically
      ✓ should use the coffee transformer for coffee files automatically
      ✓ should use the image transformer for png, gif, jpg and jpeg files automatically
      selfClosingTag option is true
        ✓ should make link tags self closing
        ✓ should make img tags self closing
    jsx as target
      ✓ should transform css to a self closing link tag
      ✓ should transform html to a self closing link tag
      ✓ should transform javascript to a script tag
      ✓ should transform coffeescript to a script tag
      ✓ should transform an image to a self closing img tag
      ✓ should use the css transformer for css files automatically
      ✓ should use the html transformer for html files automatically
      ✓ should use the js transformer for js files automatically
      ✓ should use the coffee transformer for coffee files automatically
      ✓ should use the image transformer for png, gif, jpg and jpeg files automatically
    jade as target
      ✓ should transform css to a jade link tag
      ✓ should transform jade to a jade include tag
      ✓ should transform html to a self closing link tag
      ✓ should transform javascript to a script tag
      ✓ should transform coffeescript to a script tag
      ✓ should transform an image to a self closing img tag
      ✓ should use the css transformer for css files automatically
      ✓ should use the jade transformer for jade files automatically
      ✓ should use the html transformer for html files automatically
      ✓ should use the js transformer for js files automatically
      ✓ should use the coffee transformer for coffee files automatically
      ✓ should use the image transformer for png, gif, jpg and jpeg files automatically
    pug as target
      ✓ should transform css to a pug link tag
      ✓ should transform pug to a pug include tag
      ✓ should transform html to a self closing link tag
      ✓ should transform javascript to a script tag
      ✓ should transform coffeescript to a script tag
      ✓ should transform an image to a self closing img tag
      ✓ should use the css transformer for css files automatically
      ✓ should use the pug transformer for pug files automatically
      ✓ should use the html transformer for html files automatically
      ✓ should use the js transformer for js files automatically
      ✓ should use the coffee transformer for coffee files automatically
      ✓ should use the image transformer for png, gif, jpg and jpeg files automatically
    slm as target
      ✓ should transform css to a slm link tag
      ✓ should transform html to a self closing link tag
      ✓ should transform javascript to a script tag
      ✓ should transform coffeescript to a script tag
      ✓ should transform an image to a self closing img tag
      ✓ should use the css transformer for css files automatically
      ✓ should use the html transformer for html files automatically
      ✓ should use the js transformer for js files automatically
      ✓ should use the coffee transformer for coffee files automatically
      ✓ should use the image transformer for png, gif, jpg and jpeg files automatically
    haml as target
      ✓ should transform css to a haml link tag
      ✓ should transform html to a self closing link tag
      ✓ should transform javascript to a script tag
      ✓ should transform coffeescript to a script tag
      ✓ should transform an image to a self closing img tag
      ✓ should use the css transformer for css files automatically
      ✓ should use the html transformer for html files automatically
      ✓ should use the js transformer for js files automatically
      ✓ should use the coffee transformer for coffee files automatically
      ✓ should use the image transformer for png, gif, jpg and jpeg files automatically
    less as target
      ✓ should transform less to a import tag
      ✓ should transform css to a import tag
      ✓ should use the less transformer for less files automatically
      ✓ should use the css transformer for css files automatically
    sass as target
      ✓ should transform sass to a import tag
      ✓ should transform scss to a import tag
      ✓ should transform css to a import tag
      ✓ should use the sass transformer for sass files automatically
      ✓ should use the sass transformer for scss files automatically
      ✓ should use the sass transformer for css files automatically
    scss as target
      ✓ should transform sass to a import tag
      ✓ should transform scss to a import tag
      ✓ should transform css to a import tag
      ✓ should use the scss transformer for sass files automatically
      ✓ should use the scss transformer for scss files automatically
      ✓ should use the scss transformer for css files automatically


  190 passing (136ms)
  4 failing

  1) gulp-inject
       should use custom transform function for each file if specified:

      AssertionError: expected '{\n  "js": [\n    "/lib2.js"\n  ]\n}\n' to be '{\n  "js": [\n    "/lib.js",\n    "/lib2.js"\n  ]\n}\n'
      + expected - actual

       {
         "js": [
      +    "/lib.js",
           "/lib2.js"
         ]
       }
      
      at Assertion.fail (node_modules/should/cjs/should.js:275:17)
      at Assertion.value (node_modules/should/cjs/should.js:356:19)
      at DestroyableTransform.<anonymous> (src/inject/inject_test.js:731:39)
      at addChunk (node_modules/readable-stream/lib/_stream_readable.js:297:12)
      at readableAddChunk (node_modules/readable-stream/lib/_stream_readable.js:279:11)
      at DestroyableTransform.Readable.push (node_modules/readable-stream/lib/_stream_readable.js:240:10)
      at DestroyableTransform.Transform.push (node_modules/readable-stream/lib/_stream_transform.js:139:32)
      at DestroyableTransform.<anonymous> (src/inject/index.js:89:12)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  2) gulp-inject
       should use special default tags when injecting into less files:

      AssertionError: expected '/* inject:css */\n@import "/fixtures/lib.css";\n/* endinject */\n/* inject:less */\n@import "/fixtures/styles.less";\n/* endinject */\n' to be '/* inject:css */\n@import "/fixtures/lib.css";\n/* endinject */\n/* inject:less */\n@import "/fixtures/component.less";\n@import "/fixtures/styles.less";\n/* endinject */\n'
      + expected - actual

       /* inject:css */
       @import "/fixtures/lib.css";
       /* endinject */
       /* inject:less */
      +@import "/fixtures/component.less";
       @import "/fixtures/styles.less";
       /* endinject */
      
      at Assertion.fail (node_modules/should/cjs/should.js:275:17)
      at Assertion.value (node_modules/should/cjs/should.js:356:19)
      at DestroyableTransform.<anonymous> (src/inject/inject_test.js:731:39)
      at addChunk (node_modules/readable-stream/lib/_stream_readable.js:297:12)
      at readableAddChunk (node_modules/readable-stream/lib/_stream_readable.js:279:11)
      at DestroyableTransform.Readable.push (node_modules/readable-stream/lib/_stream_readable.js:240:10)
      at DestroyableTransform.Transform.push (node_modules/readable-stream/lib/_stream_transform.js:139:32)
      at DestroyableTransform.<anonymous> (src/inject/index.js:89:12)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  3) gulp-inject
       should use special default tags when injecting into sass files:

      AssertionError: expected '/* inject:css */\n@import "/fixtures/lib.css"\n/* endinject */\n/* inject:sass */\n@import "/fixtures/styles.sass"\n/* endinject */\n/* inject:scss */\n@import "/fixtures/styles.scss"\n/* endinject */\n' to be '/* inject:css */\n@import "/fixtures/lib.css"\n/* endinject */\n/* inject:sass */\n@import "/fixtures/component.sass"\n@import "/fixtures/styles.sass"\n/* endinject */\n/* inject:scss */\n@import "/fixtures/component.scss"\n@import "/fixtures/styles.scss"\n/* endinject */\n'
      + expected - actual

       /* inject:css */
       @import "/fixtures/lib.css"
       /* endinject */
       /* inject:sass */
      +@import "/fixtures/component.sass"
       @import "/fixtures/styles.sass"
       /* endinject */
       /* inject:scss */
      +@import "/fixtures/component.scss"
       @import "/fixtures/styles.scss"
       /* endinject */
      
      at Assertion.fail (node_modules/should/cjs/should.js:275:17)
      at Assertion.value (node_modules/should/cjs/should.js:356:19)
      at DestroyableTransform.<anonymous> (src/inject/inject_test.js:731:39)
      at addChunk (node_modules/readable-stream/lib/_stream_readable.js:297:12)
      at readableAddChunk (node_modules/readable-stream/lib/_stream_readable.js:279:11)
      at DestroyableTransform.Readable.push (node_modules/readable-stream/lib/_stream_readable.js:240:10)
      at DestroyableTransform.Transform.push (node_modules/readable-stream/lib/_stream_transform.js:139:32)
      at DestroyableTransform.<anonymous> (src/inject/index.js:89:12)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

  4) gulp-inject
       should use special default tags when injecting into scss files:

      AssertionError: expected '/* inject:css */\n@import "/fixtures/lib.css";\n/* endinject */\n/* inject:sass */\n@import "/fixtures/styles.sass";\n/* endinject */\n/* inject:scss */\n@import "/fixtures/styles.scss";\n/* endinject */\n' to be '/* inject:css */\n@import "/fixtures/lib.css";\n/* endinject */\n/* inject:sass */\n@import "/fixtures/component.sass";\n@import "/fixtures/styles.sass";\n/* endinject */\n/* inject:scss */\n@import "/fixtures/component.scss";\n@import "/fixtures/styles.scss";\n/* endinject */\n'
      + expected - actual

       /* inject:css */
       @import "/fixtures/lib.css";
       /* endinject */
       /* inject:sass */
      +@import "/fixtures/component.sass";
       @import "/fixtures/styles.sass";
       /* endinject */
       /* inject:scss */
      +@import "/fixtures/component.scss";
       @import "/fixtures/styles.scss";
       /* endinject */
      
      at Assertion.fail (node_modules/should/cjs/should.js:275:17)
      at Assertion.value (node_modules/should/cjs/should.js:356:19)
      at DestroyableTransform.<anonymous> (src/inject/inject_test.js:731:39)
      at addChunk (node_modules/readable-stream/lib/_stream_readable.js:297:12)
      at readableAddChunk (node_modules/readable-stream/lib/_stream_readable.js:279:11)
      at DestroyableTransform.Readable.push (node_modules/readable-stream/lib/_stream_readable.js:240:10)
      at DestroyableTransform.Transform.push (node_modules/readable-stream/lib/_stream_transform.js:139:32)
      at DestroyableTransform.<anonymous> (src/inject/index.js:89:12)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

I was also able to reproduce this issue, and reverting group-array to 0.3.3 fixes the issue

We had the same issue and also traced it back to the new verison of group-array, currently testing a version pin in our project.

🎉 This issue has been resolved in version 5.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀