cropduster
Advanced tools
Comparing version 3.4.2 to 4.0.0
@@ -1,7 +0,3 @@ | ||
// Karma configuration | ||
// Generated on Sun Apr 05 2015 17:41:09 GMT-0400 (EDT) | ||
module.exports = function(config) { | ||
config.set({ | ||
// base path that will be used to resolve all patterns (eg. files, exclude) | ||
@@ -11,3 +7,2 @@ basePath: '', | ||
// frameworks to use | ||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter | ||
frameworks: ['qunit'], | ||
@@ -17,22 +12,39 @@ | ||
files: [ | ||
'bower_components/jquery/dist/jquery.min.js', | ||
// Adding qunit here conflicts with the framework | ||
'bower_components/sinon/index.js', | ||
'bower_components/sinon-qunit/lib/sinon-qunit.js', | ||
'lib/*.js', | ||
'tests/*.js' | ||
'src/**/*.js', | ||
'tests/**/*.js' | ||
], | ||
plugins: ['karma-qunit', 'karma-phantomjs-launcher'], | ||
// preprocess matching files before serving them to the browser | ||
preprocessors: { | ||
'src/*.js': ['webpack'], | ||
'tests/*.js': ['webpack', 'sourcemap'] | ||
}, | ||
webpack: { | ||
devtool: 'inline-source-map', | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: ['env'] | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
webpackMiddleware: { | ||
noInfo: true | ||
}, | ||
// list of files to exclude | ||
exclude: [], | ||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: {}, | ||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
@@ -39,0 +51,0 @@ |
{ | ||
"name": "cropduster", | ||
"version": "3.4.2", | ||
"version": "4.0.0", | ||
"description": "Library for building web pages for use with Movable Ink Web Crops", | ||
"main": "index.js", | ||
"main": "src/cropduster.js", | ||
"directories": { | ||
@@ -11,13 +11,21 @@ "test": "tests" | ||
"devDependencies": { | ||
"bower": "^1.4.1", | ||
"karma": "^1.3.0", | ||
"karma-chrome-launcher": "^2.0.0", | ||
"karma-phantomjs-launcher": "^1.0.2", | ||
"babel-core": "^6.26.0", | ||
"babel-loader": "^7.1.2", | ||
"babel-preset-env": "^1.6.1", | ||
"jquery": "^3.2.1", | ||
"karma": "^1.7.1", | ||
"karma-babel-preprocessor": "^7.0.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-phantomjs-launcher": "^1.0.4", | ||
"karma-qunit": "^1.2.1", | ||
"karma-sinon": "^1.0.5", | ||
"qunitjs": "^1.18.0", | ||
"sinon": "^1.17.6" | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^2.0.5", | ||
"qunitjs": "^2.4.1", | ||
"sinon": "^4.1.1", | ||
"webpack": "^3.8.1" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/karma/bin/karma start" | ||
"test": "node_modules/karma/bin/karma start", | ||
"build": "sed 's/export default CD;//' src/cropduster.js | sed 's/const CD/window.CD/' > dist/cropduster.es5.js" | ||
}, | ||
@@ -24,0 +32,0 @@ "repository": { |
@@ -10,16 +10,22 @@ # Cropduster | ||
Cropduster is on bower. Install it with: | ||
Cropduster is on npm. Install it with: | ||
```bash | ||
npm install -g bower # if bower is not installed yet | ||
bower init | ||
bower install --save cropduster | ||
npm install --save-dev cropduster | ||
``` | ||
The use it by referencing it from your HTML page: | ||
The use it by importing it from your es6-enabled javascript file: | ||
```html | ||
<script src="bower_components/cropduster/lib/cropduster.js"></script> | ||
```javascript | ||
import CD from 'cropduster'; | ||
``` | ||
## Legacy Installation | ||
If you are unable to use es6, you can find an es5 version at | ||
http://projects.movableink.com/production/libs/cropduster.[version].js | ||
Where you replace `[version]` with the version you want to use. | ||
## API | ||
@@ -154,7 +160,2 @@ | ||
bower install | ||
open tests/index.html | ||
Alternatively, for command-line tests: | ||
brew install phantomjs | ||
@@ -166,2 +167,5 @@ npm install | ||
### 4.0.0 | ||
* Switch from bower to npm; CD is now exported as es6 module. See the new installation instructions above. | ||
### 3.4.2 | ||
@@ -168,0 +172,0 @@ * Remove `bower` from npm postinstall, for npm usage. |
@@ -1,3 +0,7 @@ | ||
var container = $("<div style='position: absolute; left: -5000px;'></div>").appendTo('body'); | ||
import CD from '../src/cropduster'; | ||
import jQuery from 'jquery'; | ||
import sinon from 'sinon'; | ||
const container = jQuery("<div style='position: absolute; left: -5000px;'></div>").appendTo('body'); | ||
// Disable debugging output | ||
@@ -25,20 +29,20 @@ CD.log = function() {}; | ||
QUnit.test("CD.$", function() { | ||
equal(CD.$('body')[0], document.body, "finds elements" ); | ||
QUnit.test("CD.$", function(assert) { | ||
assert.equal(CD.$('body')[0], document.body, "finds elements" ); | ||
}); | ||
QUnit.test("CD.param when parameter not found", function() { | ||
equal(CD.param('not_found'), null, "returns null"); | ||
QUnit.test("CD.param when parameter not found", function(assert) { | ||
assert.equal(CD.param('not_found'), null, "returns null"); | ||
}); | ||
QUnit.test("CD.param when parameter is found", function() { | ||
equal(CD.param('foo'), 'bar', "returns value"); | ||
QUnit.test("CD.param when parameter is found", function(assert) { | ||
assert.equal(CD.param('foo'), 'bar', "returns value"); | ||
}); | ||
QUnit.test("CD.params returns all query params", function() { | ||
deepEqual(CD.params(), {'baz test': 'quux value', foo: 'bar'}, "returns the url params"); | ||
QUnit.test("CD.params returns all query params", function(assert) { | ||
assert.deepEqual(CD.params(), {'baz test': 'quux value', foo: 'bar'}, "returns the url params"); | ||
}); | ||
QUnit.test("CD.params with argument returns that query param", function() { | ||
equal(CD.params('baz test'), 'quux value', "returns the url param"); | ||
QUnit.test("CD.params with argument returns that query param", function(assert) { | ||
assert.equal(CD.params('baz test'), 'quux value', "returns the url param"); | ||
}); | ||
@@ -48,41 +52,41 @@ | ||
QUnit.test("CD.autofill", function() { | ||
QUnit.test("CD.autofill", function(assert) { | ||
container.html(''); | ||
var el = $("<div id='autofill_foo'></div>"); | ||
var el = jQuery("<div id='autofill_foo'></div>"); | ||
container.append(el); | ||
CD.autofill(); | ||
equal(el.html(), 'bar', "auto-fills the query param into the element"); | ||
assert.equal(el.html(), 'bar', "auto-fills the query param into the element"); | ||
}); | ||
QUnit.test("CD.setImageRedirect", function() { | ||
QUnit.test("CD.setImageRedirect", function(assert) { | ||
CD.setImageRedirect("http://example.com/foo.png"); | ||
equal($("#mi-redirect-image").attr('href'), "http://example.com/foo.png", | ||
assert.equal(jQuery("#mi-redirect-image").attr('href'), "http://example.com/foo.png", | ||
"sets the image redirect"); | ||
}); | ||
QUnit.test("CD.setImageRedirect multiple times", function() { | ||
QUnit.test("CD.setImageRedirect multiple times", function(assert) { | ||
CD.setImageRedirect("http://example.com/foo.png"); | ||
CD.setImageRedirect("http://example.com/bar.png"); | ||
equal($("#mi-redirect-image").attr('href'), "http://example.com/bar.png", | ||
assert.equal(jQuery("#mi-redirect-image").attr('href'), "http://example.com/bar.png", | ||
"uses the last setImageRedirect url"); | ||
}); | ||
QUnit.test("CD.setClickthrough", function() { | ||
QUnit.test("CD.setClickthrough", function(assert) { | ||
CD.setClickthrough("http://example.com/"); | ||
equal($("#mi_dynamic_link").attr('href'), "http://example.com/", | ||
assert.equal(jQuery("#mi_dynamic_link").attr('href'), "http://example.com/", | ||
"sets the dynamic link"); | ||
}); | ||
QUnit.test("CD.setExtraData with no existing data", function() { | ||
QUnit.test("CD.setExtraData with no existing data", function(assert) { | ||
CD.setExtraData({foo: 'bar'}); | ||
equal($("#mi-data").attr('data-mi-data'), '{"foo":"bar"}', | ||
assert.equal(jQuery("#mi-data").attr('data-mi-data'), '{"foo":"bar"}', | ||
"sets the data in json"); | ||
}); | ||
QUnit.test("CD.setExtraData with existing data", function() { | ||
QUnit.test("CD.setExtraData with existing data", function(assert) { | ||
CD.setExtraData({foo: 'bar'}); | ||
@@ -92,31 +96,31 @@ CD.setExtraData({foo: 'baz'}); | ||
equal($("#mi-data").attr('data-mi-data'), '{"foo":"baz","my":"data"}', | ||
assert.equal(jQuery("#mi-data").attr('data-mi-data'), '{"foo":"baz","my":"data"}', | ||
"sets the data in json"); | ||
}); | ||
QUnit.test("CD.proxyUrl with http url", function() { | ||
QUnit.test("CD.proxyUrl with http url", function(assert) { | ||
var url = "http://google.com"; | ||
equal(CD.proxyUrl(url), "http://cors.movableink.com/google.com/", "returns CORS url"); | ||
assert.equal(CD.proxyUrl(url), "http://cors.movableink.com/google.com/", "returns CORS url"); | ||
}); | ||
QUnit.test("CD.proxyUrl with https url", function() { | ||
QUnit.test("CD.proxyUrl with https url", function(assert) { | ||
var url = "https://google.com"; | ||
equal(CD.proxyUrl(url), "http://cors.movableink.com/google.com:443/", "returns CORS url"); | ||
assert.equal(CD.proxyUrl(url), "http://cors.movableink.com/google.com:443/", "returns CORS url"); | ||
}); | ||
QUnit.test("CD.proxyUrl with port", function() { | ||
QUnit.test("CD.proxyUrl with port", function(assert) { | ||
var url = "http://google.com:8080"; | ||
equal(CD.proxyUrl(url), "http://cors.movableink.com/google.com:8080/", "returns CORS url"); | ||
assert.equal(CD.proxyUrl(url), "http://cors.movableink.com/google.com:8080/", "returns CORS url"); | ||
}); | ||
test("CD.suspend", function() { | ||
QUnit.test("CD.suspend", function(assert) { | ||
CD._reset(); // clean out previous test | ||
CD.suspend(); | ||
equal(CD._readyToCapture, false, "sets readyToCapture"); | ||
assert.equal(CD._readyToCapture, false, "sets readyToCapture"); | ||
}); | ||
test("CD.capture", function() { | ||
QUnit.test("CD.capture", function(assert) { | ||
CD._reset(); // clean out previous test | ||
CD.capture(); | ||
equal(CD._readyToCapture, true, "sets readyToCapture"); | ||
assert.equal(CD._readyToCapture, true, "sets readyToCapture"); | ||
}); | ||
@@ -129,3 +133,3 @@ | ||
CD.getImage(src, function(img) { | ||
equal(img.src, src, "called with src"); | ||
assert.equal(img.src, src, "called with src"); | ||
done(); | ||
@@ -140,3 +144,3 @@ }); | ||
CD.getImage(src, function(img) { | ||
equal(img, null, "called with null"); | ||
assert.equal(img, null, "called with null"); | ||
done(); | ||
@@ -147,3 +151,4 @@ }); | ||
QUnit.test("CD.getImages without callback", function(assert) { | ||
expect(0); | ||
assert.expect(0); | ||
window.Image = imageSuccessStub; | ||
@@ -164,4 +169,4 @@ var srcA = "http://example.com/foo.png"; | ||
setTimeout(function() { | ||
ok(cb.calledOnce); | ||
equal(cb.firstCall.args[0].length, 2); | ||
assert.ok(cb.calledOnce); | ||
assert.equal(cb.firstCall.args[0].length, 2); | ||
done(); | ||
@@ -172,3 +177,3 @@ }, 10); | ||
QUnit.test("CD.waitForAsset", function(assert) { | ||
equal(CD.waitForAsset('http://example.com/foo.png'), undefined); | ||
assert.equal(CD.waitForAsset('http://example.com/foo.png'), undefined); | ||
}); | ||
@@ -186,8 +191,8 @@ | ||
setTimeout(function() { | ||
ok(cb.calledOnce, "callback is called only once"); | ||
equal(cb.firstCall.args[0].length, 2, "called with both images"); | ||
assert.ok(cb.calledOnce, "callback is called only once"); | ||
assert.equal(cb.firstCall.args[0].length, 2, "called with both images"); | ||
ok(singleCb.calledTwice, "single image callback is called for each image"); | ||
equal(singleCb.firstCall.args[0].src, srcA, "first image called first"); | ||
equal(singleCb.secondCall.args[0].src, srcB, "last image called last"); | ||
assert.ok(singleCb.calledTwice, "single image callback is called for each image"); | ||
assert.equal(singleCb.firstCall.args[0].src, srcA, "first image called first"); | ||
assert.equal(singleCb.secondCall.args[0].src, srcB, "last image called last"); | ||
@@ -213,3 +218,3 @@ done(); | ||
ok(spy.calledWith('response'), 'calls the callback with a response'); | ||
assert.ok(spy.calledWith('response'), 'calls the callback with a response'); | ||
@@ -231,4 +236,5 @@ server.restore(); | ||
server.requests[0].abort(); | ||
server.requests[0].onerror(); | ||
ok(spy.calledWith(null), 'calls the callback with a response'); | ||
assert.ok(spy.calledWith(null), 'calls the callback with a response'); | ||
@@ -255,8 +261,8 @@ server.restore(); | ||
equal(requests.length, 1); | ||
equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], null); // not automatically added | ||
equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
equal(requests[0].method, 'GET'); | ||
equal(requests[0].async, true); | ||
equal(requests[0].url, "http://google.com"); | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], null); // not automatically added | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].method, 'GET'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].url, "http://google.com"); | ||
@@ -282,9 +288,9 @@ xhr.restore(); | ||
equal(requests.length, 1); | ||
equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 5); | ||
equal(requests[0].requestHeaders['x-mi-cbe'], '-2134781906'); | ||
equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
equal(requests[0].method, 'GET'); | ||
equal(requests[0].async, true); | ||
equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 5); | ||
assert.equal(requests[0].requestHeaders['x-mi-cbe'], '-2134781906'); | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].method, 'GET'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
@@ -305,6 +311,6 @@ xhr.restore(); | ||
equal(requests.length, 1); | ||
equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 10); | ||
equal(requests[0].requestHeaders['x-mi-cbe'], '2084411041'); | ||
equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 10); | ||
assert.equal(requests[0].requestHeaders['x-mi-cbe'], '2084411041'); | ||
assert.equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
@@ -332,10 +338,10 @@ xhr.restore(); | ||
equal(requests.length, 1); | ||
equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 5); | ||
equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
equal(requests[0].requestHeaders['x-mi-cbe'], '-1217831332'); | ||
equal(requests[0].method, 'POST'); | ||
equal(requests[0].async, true); | ||
equal(requests[0].requestBody, 'foobar'); | ||
equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
assert.equal(requests.length, 1); | ||
assert.equal(requests[0].requestHeaders['x-reverse-proxy-ttl'], 5); | ||
assert.equal(requests[0].requestHeaders['Accept'], 'application/json'); | ||
assert.equal(requests[0].requestHeaders['x-mi-cbe'], '-1217831332'); | ||
assert.equal(requests[0].method, 'POST'); | ||
assert.equal(requests[0].async, true); | ||
assert.equal(requests[0].requestBody, 'foobar'); | ||
assert.equal(requests[0].url, "http://cors.movableink.com/google.com/"); | ||
@@ -354,8 +360,8 @@ xhr.restore(); | ||
CD.capture(); // 1 open call | ||
equal(CD._readyToCapture, false, "waits for open calls to get to zero"); | ||
equal(CD._openCalls, 1, "one open call"); | ||
assert.equal(CD._readyToCapture, false, "waits for open calls to get to zero"); | ||
assert.equal(CD._openCalls, 1, "one open call"); | ||
CD.capture(); // 0 open calls | ||
equal(CD._readyToCapture, true, "sets readyToCapture"); | ||
equal(CD._openCalls, 0, "zero open calls"); | ||
assert.equal(CD._readyToCapture, true, "sets readyToCapture"); | ||
assert.equal(CD._openCalls, 0, "zero open calls"); | ||
}); | ||
@@ -366,9 +372,9 @@ | ||
var hash = CD._hashForRequest("http://www.google.com", {"foo": "bar"}); | ||
equal(hash, "387990350"); | ||
assert.equal(hash, "387990350"); | ||
hash = CD._hashForRequest("http://www.google.com", {"foo": "bar"}); | ||
equal(hash, "387990350"); | ||
assert.equal(hash, "387990350"); | ||
var different = CD._hashForRequest("http://www.google.com", {"foo": "baz"}); | ||
equal(different, "387998038"); | ||
assert.equal(different, "387998038"); | ||
var another = CD._hashForRequest("http://www.example.com", {"foo": "baz"}); | ||
equal(another, "-164085129"); | ||
assert.equal(another, "-164085129"); | ||
}); | ||
@@ -380,3 +386,3 @@ | ||
CD.cancelRequest(); | ||
ok(callback.calledOnce); | ||
assert.ok(callback.calledOnce); | ||
}); | ||
@@ -388,3 +394,3 @@ | ||
CD.throwError(); | ||
ok(callback.calledOnce); | ||
assert.ok(callback.calledOnce); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
158265
253
15
7
627
1