From ed8fef9720d06bc64a80bf71795d49de5b9a7d6b Mon Sep 17 00:00:00 2001 From: Qiang Han Date: Wed, 22 Jul 2015 16:18:24 -0700 Subject: [PATCH] fix toImage bug and split tests based on browser requirement --- dist/caman.full.js | 2 +- karma.conf.js | 2 +- package.json | 4 +++- test/unit/browser/io.coffee | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/unit/browser/io.coffee diff --git a/dist/caman.full.js b/dist/caman.full.js index 772007ff..d85bb84f 100644 --- a/dist/caman.full.js +++ b/dist/caman.full.js @@ -1562,7 +1562,7 @@ Caman.prototype.toImage = function(type) { var img; - img = new Image(); + img = new window.Image(); img.src = this.toBase64(type); img.width = this.dimensions.width; img.height = this.dimensions.height; diff --git a/karma.conf.js b/karma.conf.js index 3a89078c..68939d7a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,7 +18,7 @@ module.exports = function(config) { 'test/ext/test-loader.js', 'test/ext/grey.js', 'dist/caman.full.js', - 'test/unit/*.coffee', + 'test/unit/**/*.coffee', {pattern: 'test/ext/grey.png', watched: false, included: false} ], diff --git a/package.json b/package.json index 62506b18..e3bd7f98 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,9 @@ "karma-mocha": "*" }, "scripts": { - "test": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script --reporter spec --globals Caman ./test/unit/*.coffee && ./node_modules/.bin/karma start --single-run --browsers Firefox", + "test": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --reporter spec --globals Caman ./test/unit/*.coffee && ./node_modules/.bin/karma start --single-run --browsers Firefox", + "test-local": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --reporter spec --globals Caman ./test/unit/*.coffee", + "test-browser": "./node_modules/.bin/karma start --single-run --browsers Firefox", "examples": "./node_modules/servedir/bin/servedir", "docs": "codo", "docs-server": "codo --server" diff --git a/test/unit/browser/io.coffee b/test/unit/browser/io.coffee new file mode 100644 index 00000000..7d96f12c --- /dev/null +++ b/test/unit/browser/io.coffee @@ -0,0 +1,17 @@ +if exports? + {Caman} = require "../../dist/caman.full" + {assert} = require 'chai' + {greyImage, greyPath, rgbData} = require '../ext/grey' + +describe "io", -> + it "should generate image tag", (done) -> + Caman greyImage, -> + img = @toImage() + assert img.src && img.src.match(/^data:image\/png;base64/) + done() + + it "should generate base64 data url", (done) -> + Caman greyImage, -> + dataURL = @toBase64() + assert dataURL.match(/^data:image\/png;base64/) + done()