Node canvas (#4497)

* readded

* paused

* test

* try jsdom

* restore node methods

* restored

* restored

* fix tests
This commit is contained in:
Andrea Bogazzi 2017-11-24 19:00:47 +01:00 committed by GitHub
parent a9eacc4d74
commit 71b36f6228
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View file

@ -18,6 +18,7 @@ else {
FetchExternalResources: ['img']
}
});
fabric.jsdomImplForWrapper = require('jsdom/lib/jsdom/living/generated/utils').implForWrapper;
fabric.window = fabric.document.defaultView;
DOMParser = require('xmldom').DOMParser;
}

View file

@ -1759,4 +1759,14 @@
*/
fabric.StaticCanvas.prototype.toJSON = fabric.StaticCanvas.prototype.toObject;
if (fabric.isLikelyNode) {
fabric.StaticCanvas.prototype.createPNGStream = function() {
var impl = fabric.jsdomImplForWrapper(this.lowerCanvasEl);
return impl && impl.createPNGStream();
};
fabric.StaticCanvas.prototype.createJPEGStream = function(opts) {
var impl = fabric.jsdomImplForWrapper(this.lowerCanvasEl);
return impl && impl.createJPEGStream(opts);
};
}
})();

View file

@ -1572,6 +1572,24 @@
});
});
QUnit.test('createPNGStream', function(assert) {
if (!fabric.isLikelyNode) {
assert.ok(true, 'not supposed to run outside node');
}
else {
assert.ok(typeof canvas.createPNGStream === 'function', 'there is a createPNGStream method');
}
});
QUnit.test('createJPEGStream', function(assert) {
if (!fabric.isLikelyNode) {
assert.ok(true, 'not supposed to run outside node');
}
else {
assert.ok(typeof canvas.createJPEGStream === 'function', 'there is a createJPEGStream method');
}
});
// QUnit.test('backgroundImage', function(assert) {
// var done = assert.async();
// assert.deepEqual('', canvas.backgroundImage);