mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Add setStubs/unsetStubs to domstubs to support testing
Do not directly export to global. Instead, export all stubs in domstubs.js and add a method setStubs to assign all exported stubs to a namespace. Then replace the import domstubs with an explicit call to this setStubs method. Also added unsetStubs for undoing the changes. This is done to allow unit testing of the SVG backend without namespace pollution.
This commit is contained in:
parent
94f1dde07d
commit
9caaaf3a91
2 changed files with 22 additions and 5 deletions
|
@ -41,7 +41,7 @@ function xmlEncode(s){
|
|||
return buf;
|
||||
}
|
||||
|
||||
global.btoa = function btoa(chars) {
|
||||
function btoa(chars) {
|
||||
var digits =
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||
var buffer = '';
|
||||
|
@ -57,7 +57,7 @@ global.btoa = function btoa(chars) {
|
|||
digits.charAt(d3) + digits.charAt(d4));
|
||||
}
|
||||
return buffer;
|
||||
};
|
||||
}
|
||||
|
||||
function DOMElement(name) {
|
||||
this.nodeName = name;
|
||||
|
@ -127,7 +127,7 @@ DOMElement.prototype = {
|
|||
},
|
||||
}
|
||||
|
||||
global.document = {
|
||||
const document = {
|
||||
childNodes : [],
|
||||
|
||||
get currentScript() {
|
||||
|
@ -171,4 +171,21 @@ Image.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
global.Image = Image;
|
||||
exports.btoa = btoa;
|
||||
exports.document = document;
|
||||
exports.Image = Image;
|
||||
|
||||
var exported_symbols = Object.keys(exports);
|
||||
|
||||
exports.setStubs = function(namespace) {
|
||||
exported_symbols.forEach(function(key) {
|
||||
console.assert(!(key in namespace), 'property should not be set: ' + key);
|
||||
namespace[key] = exports[key];
|
||||
});
|
||||
};
|
||||
exports.unsetStubs = function(namespace) {
|
||||
exported_symbols.forEach(function(key) {
|
||||
console.assert(key in namespace, 'property should be set: ' + key);
|
||||
delete namespace[key];
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue