From 892cba5ad5d654e1db027b96f82caf683cbd29bb Mon Sep 17 00:00:00 2001 From: Benjamin Amelot Date: Tue, 17 Apr 2018 11:48:49 +0200 Subject: [PATCH] feat: enable tag type configuration (#316) * feat: enable tag type configuration * feat: enable tag type configuration -- added tests --- lib/addStyles.js | 8 ++++++-- test/basic.test.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/addStyles.js b/lib/addStyles.js index b7b07749..c0767b01 100644 --- a/lib/addStyles.js +++ b/lib/addStyles.js @@ -201,7 +201,9 @@ function removeStyleElement (style) { function createStyleElement (options) { var style = document.createElement("style"); - options.attrs.type = "text/css"; + if(options.attrs.type === undefined) { + options.attrs.type = "text/css"; + } addAttrs(style, options.attrs); insertStyleElement(options, style); @@ -212,7 +214,9 @@ function createStyleElement (options) { function createLinkElement (options) { var link = document.createElement("link"); - options.attrs.type = "text/css"; + if(options.attrs.type === undefined) { + options.attrs.type = "text/css"; + } options.attrs.rel = "stylesheet"; addAttrs(link, options.attrs); diff --git a/test/basic.test.js b/test/basic.test.js index 54c2bce9..3725e962 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -220,6 +220,26 @@ describe("basic tests", function() { runCompilerTest(expected, done); }); // it attrs + it("type attribute", function(done) { + // Setup + styleLoaderOptions.attrs = {type: 'text/less'}; + + fs.writeFileSync( + rootDir + "main.js", + [ + "var a = require('./style.css');" + ].join("\n") + ); + + // Run + let expected = [ + existingStyle, + `` + ].join("\n"); + + runCompilerTest(expected, done); + }); // it type attribute + it("url", function(done) { cssRule.use = [ { @@ -261,6 +281,28 @@ describe("basic tests", function() { runCompilerTest(expected, done); }); // it url with attrs + it("url with type attribute", function (done) { + cssRule.use = [ + { + loader: "style-loader/url", + options: { + attrs: { + type: 'text/less' + } + } + }, + "file-loader" + ]; + + // Run + let expected = [ + existingStyle, + '' + ].join("\n"); + + runCompilerTest(expected, done); + }); // it url with type attribute + it("useable", function(done) { cssRule.use = [ {