diff --git a/README.md b/README.md index 61496412..24b26e6c 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ Styles are not added on `import/require()`, but instead on call to `use`/`ref`. |:--:|:--:|:-----:|:----------| |**`hmr`**|`{Boolean}`|`true`|Enable/disable Hot Module Replacement (HMR), if disabled no HMR Code will be added (good for non local development/production)| |**`base`** |`{Number}`|`true`|Set module ID base (DLLPlugin)| -|**`attrs`**|`{Object}`|`{}`|Add custom attrs to ``| +|**`attrs`**|`{Object}`|`{}`|Add custom attrs to ``, `[name]` `[version]` Can be replaced automatically| |**`transform`** |`{Function}`|`false`|Transform/Conditionally load CSS by passing a transform/condition function| |**`insertAt`**|`{String\|Object}`|`bottom`|Inserts `` at the given position| |**`insertInto`**|`{String\|Function}`|``|Inserts `` into the given position| @@ -199,6 +199,7 @@ This setting is primarily used as a workaround for [css clashes](https://github. ### `attrs` If defined, style-loader will attach given attributes with their values on `` + `` ].join("\n"); - runCompilerTest(expected, done); }); // it attrs diff --git a/test/utils.test.js b/test/utils.test.js new file mode 100644 index 00000000..51bae06c --- /dev/null +++ b/test/utils.test.js @@ -0,0 +1,51 @@ +var assert = require("assert"); +var fs = require("fs"); +var path = require("path"); +var jsdom = require('jsdom'); +var utils = require("../lib/utils"); + +var exists = utils.exists; +var findPackage = utils.findPackage; +var addAttrs = utils.addAttrs; + +describe('Utils Test', () => { + it("exist", function(done) { + assert.equal(exists(fs, path.join(__dirname, 'basic.test.js')), true); + done(); + }); + + it('not exist', function(done) { + assert.equal(exists(fs, path.join(__dirname, 'xx.js')), false); + done(); + }); + + it('findPackage', function(done) { + assert.equal(findPackage(fs, __dirname).name, 'style-loader'); + done(); + }); + + it('findPackage null', function(done) { + assert.equal(findPackage(fs, '/'), null); + done(); + }); + + it('addAttrs', function(done) { + jsdom.env( + '

', + [], + function (err, window) { + var doc = window.document; + var ele = doc.createElement('div'); + var attrs = { + id: 'div', + width: '100px' + }; + addAttrs(ele, attrs); + assert.equal(ele.id, 'div'); + assert.equal(ele.getAttribute('width'), '100px'); + window.close(); + done(); + } + ); + }); +});