Skip to content

Commit

Permalink
Enable support for the canvas-prebuilt package
Browse files Browse the repository at this point in the history
This provides an easier alternative to the canvas package.
  • Loading branch information
asturur authored and domenic committed Mar 12, 2017
1 parent ccbab03 commit 0454f04
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ addons:

matrix:
include:
- node_js: 4
env: TEST_SUITE=node-canvas-prebuilt
script: "export CXX=g++-4.8 && npm i canvas-prebuilt && npm test"
addons:
hosts:
- web-platform.test
- www.web-platform.test
- www1.web-platform.test
- www2.web-platform.test
- xn--n8j6ds53lwwkrqhv28a.web-platform.test
- xn--lve-6lad.web-platform.test
- node_js: 4
env: TEST_SUITE=node-canvas
script: "export CXX=g++-4.8 && npm i canvas && npm test"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ jsdom.env({

## Canvas

jsdom includes support for using the [canvas](https://npmjs.org/package/canvas) package to extend any `<canvas>` elements with the canvas API. To make this work, you need to include canvas as a dependency in your project, as a peer of jsdom. If jsdom can find the canvas package, it will use it, but if it's not present, then `<canvas>` elements will behave like `<div>`s.
jsdom includes support for using the [canvas](https://npmjs.org/package/canvas) or [canvas-prebuilt](https://npmjs.org/package/canvas-prebuilt) package to extend any `<canvas>` elements with the canvas API. To make this work, you need to include canvas as a dependency in your project, as a peer of jsdom. If jsdom can find the canvas package, it will use it, but if it's not present, then `<canvas>` elements will behave like `<div>`s.

## More Examples

Expand Down
17 changes: 10 additions & 7 deletions lib/jsdom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,15 @@ exports.parseDataUrl = function parseDataUrl(url) {
/* eslint-disable global-require */

exports.Canvas = null;
try {
exports.Canvas = require("canvas");
if (typeof exports.Canvas !== "function") {
// In browserify, the require will succeed but return an empty object
["canvas", "canvas-prebuilt"].some(moduleName => {
try {
exports.Canvas = require(moduleName);
if (typeof exports.Canvas !== "function") {
// In browserify, the require will succeed but return an empty object
exports.Canvas = null;
}
} catch (e) {
exports.Canvas = null;
}
} catch (e) {
exports.Canvas = null;
}
return exports.Canvas !== null;
});

0 comments on commit 0454f04

Please sign in to comment.