|
1 | | -var should = require("should"); |
2 | | -var path = require("path"); |
| 1 | +/*globals describe it */ |
| 2 | + |
| 3 | +require("should"); |
3 | 4 | var cssLoader = require("../index.js"); |
4 | 5 | var vm = require("vm"); |
5 | 6 |
|
| 7 | +function assetEvaluated(output, result, modules) { |
| 8 | + try { |
| 9 | + var fn = vm.runInThisContext("(function(module, exports, require) {" + output + "})", "testcase.js"); |
| 10 | + var m = { exports: {}, id: 1 }; |
| 11 | + fn(m, m.exports, function(module) { |
| 12 | + if(module === "./lib/css-base.js") |
| 13 | + return require("../lib/css-base"); |
| 14 | + if(module.indexOf("-!loader!") === 0) |
| 15 | + module = module.substr(9); |
| 16 | + if(modules && modules[module]) |
| 17 | + return modules[module]; |
| 18 | + return "{" + module + "}"; |
| 19 | + }); |
| 20 | + } catch(e) { |
| 21 | + console.error(output); |
| 22 | + throw e; |
| 23 | + } |
| 24 | + delete m.exports.toString; |
| 25 | + delete m.exports.i; |
| 26 | + m.exports.should.be.eql(result); |
| 27 | + |
| 28 | +} |
| 29 | + |
6 | 30 | function test(name, input, result, query, modules) { |
7 | 31 | it(name, function() { |
8 | 32 | var output = cssLoader.call({ |
@@ -38,29 +62,6 @@ function testMinimize(name, input, result, query, modules) { |
38 | 62 | }); |
39 | 63 | } |
40 | 64 |
|
41 | | -function assetEvaluated(output, result, modules) { |
42 | | - try { |
43 | | - var fn = vm.runInThisContext("(function(module, exports, require) {" + output + "})", "testcase.js"); |
44 | | - var m = { exports: {}, id: 1 }; |
45 | | - fn(m, m.exports, function(module) { |
46 | | - if(module === "./lib/css-base.js") |
47 | | - return require("../lib/css-base"); |
48 | | - if(module.indexOf("-!loader!") === 0) |
49 | | - module = module.substr(9); |
50 | | - if(modules && modules[module]) |
51 | | - return modules[module]; |
52 | | - return "{" + module + "}"; |
53 | | - }); |
54 | | - } catch(e) { |
55 | | - console.error(output); |
56 | | - throw e; |
57 | | - } |
58 | | - delete m.exports.toString; |
59 | | - delete m.exports.i; |
60 | | - m.exports.should.be.eql(result); |
61 | | - |
62 | | -} |
63 | | - |
64 | 65 | describe("url", function() { |
65 | 66 | test("empty", "", [ |
66 | 67 | [1, "", ""] |
@@ -142,18 +143,27 @@ describe("url", function() { |
142 | 143 | test("media query", "@media (min-width: 500px) { body { background: url(image.png); } }", [ |
143 | 144 | [1, "@media (min-width: 500px) { body { background: url({./image.png}); } }", ""] |
144 | 145 | ]); |
145 | | - test("placeholder", ".[className] { background: red; }\n#[someId] { background: green; }\n" + |
146 | | - ".[className] .[subClass] { color: green; }\n#[someId] .[subClass] { color: blue; }", function() { var r = [ |
147 | | - [1, ".z857c3103f06630f914262cbc4bce752f { background: red; }\n#z5a79ec8f696debd47ffff36ec4ae1eb8 { background: green; }\n" + |
148 | | - ".z857c3103f06630f914262cbc4bce752f .zaf1bf69321affd3c299f08aee1373fba { color: green; }\n#z5a79ec8f696debd47ffff36ec4ae1eb8 .zaf1bf69321affd3c299f08aee1373fba { color: blue; }", ""] |
| 146 | + test("locals", ".local[className] { background: red; }\n#local[someId] { background: green; }\n" + |
| 147 | + ".local[className] .local[subClass] { color: green; }\n#local[someId] .local[subClass] { color: blue; }", function() { var r = [ |
| 148 | + [1, "._23_aKvs-b8bW2Vg3fwHozO { background: red; }\n#_1j3LM6lKkKzRIt19ImYVnD { background: green; }\n" + |
| 149 | + "._23_aKvs-b8bW2Vg3fwHozO ._13LGdX8RMStbBE9w-t0gZ1 { color: green; }\n#_1j3LM6lKkKzRIt19ImYVnD ._13LGdX8RMStbBE9w-t0gZ1 { color: blue; }", ""] |
149 | 150 | ]; |
150 | | - r.placeholders = { |
151 | | - className: "z857c3103f06630f914262cbc4bce752f", |
152 | | - someId: "z5a79ec8f696debd47ffff36ec4ae1eb8", |
153 | | - subClass: "zaf1bf69321affd3c299f08aee1373fba" |
| 151 | + r.locals = { |
| 152 | + className: "_23_aKvs-b8bW2Vg3fwHozO", |
| 153 | + someId: "_1j3LM6lKkKzRIt19ImYVnD", |
| 154 | + subClass: "_13LGdX8RMStbBE9w-t0gZ1" |
154 | 155 | }; |
155 | 156 | return r; |
156 | 157 | }()); |
| 158 | + test("locals-format", ".local[test] { background: red; }", |
| 159 | + function() { var r = [ |
| 160 | + [1, ".test-3tNsp { background: red; }", ""] |
| 161 | + ]; |
| 162 | + r.locals = { |
| 163 | + test: "test-3tNsp" |
| 164 | + }; |
| 165 | + return r; |
| 166 | + }(), "?localIdentName=[local]-[hash:base64:5]"); |
157 | 167 | testMinimize("minimized simple", ".class { a: b c d; }", [ |
158 | 168 | [1, ".class{a:b c d}", ""] |
159 | 169 | ]); |
|
0 commit comments