-
-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use btoa
instead Buffer
#501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
/*globals describe it*/ | ||
/*eslint-env mocha*/ | ||
|
||
var base = require("../lib/css-base"); | ||
|
||
describe("css-base", function() { | ||
before(function() { | ||
global.btoa = function btoa(str) { | ||
var buffer = null; | ||
|
||
if (str instanceof Buffer) { | ||
buffer = str; | ||
} else { | ||
buffer = new Buffer(str.toString(), 'binary'); | ||
} | ||
|
||
return buffer.toString('base64'); | ||
} | ||
}) | ||
|
||
after(function () { | ||
global.btoa = null; | ||
}) | ||
|
||
it("should toString a single module", function() { | ||
var m = base(); | ||
m.push([1, "body { a: 1; }", ""]); | ||
|
@@ -46,4 +64,17 @@ describe("css-base", function() { | |
}]); | ||
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 */"); | ||
}); | ||
it("should toString without source mapping if btoa not avalibale", function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why CSS should be extracted without source mapping if btoa not avalibale? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I understand. P.S: I use the css-loader runtime in a webpack plugin to generate inline source-map. In node 16 it works, but not in older node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it was not design for this, you can send a PR and improve it |
||
global.btoa = null; | ||
var m = base(true); | ||
m.push([1, "body { a: 1; }", "", { | ||
file: "test.scss", | ||
sources: [ | ||
'./path/to/test.scss' | ||
], | ||
mappings: "AAAA;", | ||
sourceRoot: "webpack://" | ||
}]); | ||
m.toString().should.be.eql("body { a: 1; }"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use
Buffer.from
in browserThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code for browser