Skip to content

Commit 7570df9

Browse files
refactor: tests
1 parent aa3918a commit 7570df9

File tree

6 files changed

+1079
-616
lines changed

6 files changed

+1079
-616
lines changed

lib/loader.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ module.exports = function(content, map) {
1616
const cb = this.async();
1717
const sourceMap = options.sourceMap;
1818

19-
var parserOptions = {
20-
url: options.url !== false,
21-
import: options.import !== false
22-
};
23-
2419
if (sourceMap && map) {
2520
if (typeof map === "string") {
2621
map = JSON.parse(map);
@@ -47,7 +42,12 @@ module.exports = function(content, map) {
4742
.split("!")
4843
.pop();
4944

50-
postcss([plugin(parserOptions)])
45+
postcss([
46+
plugin({
47+
url: options.url !== false,
48+
import: options.import !== false
49+
})
50+
])
5151
.process(content, {
5252
from,
5353
to,

test/cssBaseTest.js

Lines changed: 80 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,88 @@
33
var runtime = require("../lib/runtime");
44

55
describe("runtime", function() {
6-
before(function() {
7-
global.btoa = function btoa(str) {
8-
var buffer = null;
6+
before(function() {
7+
global.btoa = function btoa(str) {
8+
var buffer = null;
99

10-
if (str instanceof Buffer) {
11-
buffer = str;
12-
} else {
13-
buffer = new Buffer(str.toString(), 'binary');
14-
}
10+
if (str instanceof Buffer) {
11+
buffer = str;
12+
} else {
13+
buffer = new Buffer(str.toString(), "binary");
14+
}
1515

16-
return buffer.toString('base64');
17-
}
18-
})
16+
return buffer.toString("base64");
17+
};
18+
});
1919

20-
after(function () {
21-
global.btoa = null;
22-
})
20+
after(function() {
21+
global.btoa = null;
22+
});
2323

24-
it("should toString a single module", function() {
25-
var m = runtime();
26-
m.push([1, "body { a: 1; }", ""]);
27-
m.toString().should.be.eql("body { a: 1; }");
28-
});
29-
it("should toString multiple modules", function() {
30-
var m = runtime();
31-
m.push([2, "body { b: 2; }", ""]);
32-
m.push([1, "body { a: 1; }", ""]);
33-
m.toString().should.be.eql("body { b: 2; }body { a: 1; }");
34-
});
35-
it("should toString with media query", function() {
36-
var m = runtime();
37-
m.push([1, "body { a: 1; }", "screen"]);
38-
m.toString().should.be.eql("@media screen{body { a: 1; }}");
39-
});
40-
it("should import modules", function() {
41-
var m = runtime();
42-
var m1 = [1, "body { a: 1; }", "screen"];
43-
var m2 = [2, "body { b: 2; }", ""];
44-
var m3 = [3, "body { c: 3; }", ""];
45-
var m4 = [4, "body { d: 4; }", ""];
46-
m.i([m2, m3], "");
47-
m.i([m2], "");
48-
m.i([m2, m4], "print");
49-
m.push(m1);
50-
m.toString().should.be.eql("body { b: 2; }" +
51-
"body { c: 3; }" +
52-
"@media print{body { d: 4; }}" +
53-
"@media screen{body { a: 1; }}");
54-
});
55-
it("should toString with source mapping", function() {
56-
var m = runtime(true);
57-
m.push([1, "body { a: 1; }", "", {
58-
file: "test.scss",
59-
sources: [
60-
'./path/to/test.scss'
61-
],
62-
mappings: "AAAA;",
63-
sourceRoot: "webpack://"
64-
}]);
65-
m.toString().should.be.eql("body { a: 1; }\n/*# sourceURL=webpack://./path/to/test.scss */\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsiLCJzb3VyY2VSb290Ijoid2VicGFjazovLyJ9 */");
66-
});
67-
it("should toString without source mapping if btoa not avalibale", function() {
68-
global.btoa = null;
69-
var m = runtime(true);
70-
m.push([1, "body { a: 1; }", "", {
71-
file: "test.scss",
72-
sources: [
73-
'./path/to/test.scss'
74-
],
75-
mappings: "AAAA;",
76-
sourceRoot: "webpack://"
77-
}]);
78-
m.toString().should.be.eql("body { a: 1; }");
79-
});
24+
it("should toString a single module", function() {
25+
var m = runtime();
26+
m.push([1, "body { a: 1; }", ""]);
27+
m.toString().should.be.eql("body { a: 1; }");
28+
});
29+
it("should toString multiple modules", function() {
30+
var m = runtime();
31+
m.push([2, "body { b: 2; }", ""]);
32+
m.push([1, "body { a: 1; }", ""]);
33+
m.toString().should.be.eql("body { b: 2; }body { a: 1; }");
34+
});
35+
it("should toString with media query", function() {
36+
var m = runtime();
37+
m.push([1, "body { a: 1; }", "screen"]);
38+
m.toString().should.be.eql("@media screen{body { a: 1; }}");
39+
});
40+
it("should import modules", function() {
41+
var m = runtime();
42+
var m1 = [1, "body { a: 1; }", "screen"];
43+
var m2 = [2, "body { b: 2; }", ""];
44+
var m3 = [3, "body { c: 3; }", ""];
45+
var m4 = [4, "body { d: 4; }", ""];
46+
m.i([m2, m3], "");
47+
m.i([m2], "");
48+
m.i([m2, m4], "print");
49+
m.push(m1);
50+
m.toString().should.be.eql(
51+
"body { b: 2; }" +
52+
"body { c: 3; }" +
53+
"@media print{body { d: 4; }}" +
54+
"@media screen{body { a: 1; }}"
55+
);
56+
});
57+
it("should toString with source mapping", function() {
58+
var m = runtime(true);
59+
m.push([
60+
1,
61+
"body { a: 1; }",
62+
"",
63+
{
64+
file: "test.scss",
65+
sources: ["./path/to/test.scss"],
66+
mappings: "AAAA;",
67+
sourceRoot: "webpack://"
68+
}
69+
]);
70+
m.toString().should.be.eql(
71+
"body { a: 1; }\n/*# sourceURL=webpack://./path/to/test.scss */\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsiLCJzb3VyY2VSb290Ijoid2VicGFjazovLyJ9 */"
72+
);
73+
});
74+
it("should toString without source mapping if btoa not avalibale", function() {
75+
global.btoa = null;
76+
var m = runtime(true);
77+
m.push([
78+
1,
79+
"body { a: 1; }",
80+
"",
81+
{
82+
file: "test.scss",
83+
sources: ["./path/to/test.scss"],
84+
mappings: "AAAA;",
85+
sourceRoot: "webpack://"
86+
}
87+
]);
88+
m.toString().should.be.eql("body { a: 1; }");
89+
});
8090
});

0 commit comments

Comments
 (0)