Navigation Menu

Skip to content

Commit

Permalink
Change tests to run on command line using mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
burt202 committed Nov 18, 2015
1 parent cb1ec3e commit 2b9e5bf
Show file tree
Hide file tree
Showing 15 changed files with 647 additions and 3,761 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
coverage/
node_modules/
40 changes: 23 additions & 17 deletions jquery.liteuploader.js
Expand Up @@ -11,11 +11,7 @@ $.fn.liteUploader = function (options) {
headers: {},
changeHandler: true,
clickElement: null,
// By default file selections are uploaded in one request each.
// Set to true to upload each file of a selection using an individual request.
singleFileUploads: false,
// Delay the file upload request by returning a promise.
// File upload will start after the promise resolves with the formData.
beforeRequest: function (files, formData) { return $.when(formData); }
};

Expand All @@ -33,23 +29,29 @@ function LiteUploader (element, options) {
this._init();
}

window.LiteUploader = LiteUploader;

LiteUploader.prototype = {
_init: function () {
if (this.options.changeHandler) {
this.el.change(function () {
this._start();
this._validateInputAndFiles();
}.bind(this));
}

if (this.options.clickElement) {
this.options.clickElement.click(function () {
this._start();
this._validateInputAndFiles();
}.bind(this));
}
},

_start: function () {
var files = this.el.get(0).files;
_getInputFiles: function () {
return this.el.get(0).files;
},

_validateInputAndFiles: function () {
var files = this._getInputFiles();
var errors = this._getInputErrors(files);
if (!errors) errors = this._getFileErrors(files);

Expand All @@ -63,21 +65,21 @@ LiteUploader.prototype = {
},

_startUploadWithFiles: function (files) {
function performUpload() {
this.el.trigger('lu:before', [files]);
this.options.beforeRequest(files, this._collateFormData(files))
.done(this._performUpload.bind(this));
}

if (this.options.singleFileUploads) {
$.each(files, function (i) {
performUpload.call(this, [files[i]]);
this._beforeUpload.call(this, [files[i]]);
}.bind(this));
} else {
performUpload.call(this, files);
this._beforeUpload.call(this, files);
}
},

_beforeUpload: function (files) {
this.el.trigger('lu:before', files);
this.options.beforeRequest(files, this._collateFormData(files))
.done(this._performUpload.bind(this));
},

_resetInput: function () {
this.el.val('');
},
Expand Down Expand Up @@ -173,8 +175,12 @@ LiteUploader.prototype = {
return formData;
},

_getXmlHttpRequestObject: function () {
return new XMLHttpRequest();
},

_buildXhrObject: function () {
var xhr = new XMLHttpRequest();
var xhr = this._getXmlHttpRequestObject();
xhr.upload.addEventListener('progress', this._onXHRProgress.bind(this), false);
this.xhrs.push(xhr);
return xhr;
Expand Down
17 changes: 17 additions & 0 deletions package.json
@@ -0,0 +1,17 @@
{
"name": "lite-uploader",
"version": "2.2.0",
"scripts": {
"tests": "./node_modules/mocha/bin/_mocha",
"coverage": "./node_modules/istanbul/lib/cli.js cover -x **/node_modules/** --hook-run-in-context --report html --print both ./node_modules/mocha/bin/_mocha -- --recursive test/"
},
"devDependencies": {
"chai": "^3.4.1",
"istanbul": "^0.4.0",
"jquery": "^2.1.4",
"jsdom": "3.1.2",
"mocha": "^2.3.4",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0"
}
}
11 changes: 9 additions & 2 deletions readme.md
Expand Up @@ -185,9 +185,16 @@ The two main HTML5 dependencies for the plugin are the File API and XHR2, and us

Using [this tool I built](http://browser.burtdev.net) which is based on stats from [gs.statcounter.com](http://gs.statcounter.com), as of April 2015, the browser versions listed above should account for approx 86% of all internet users

### Examples & Tests
### Examples

There are 3 examples in the `example` directory (using PHP as the server-side language) to help you get on your way and also there is a full suite of Jasmine tests to back the plugin. They can be found in the `tests` directory and run by opening `runner.html`
See [examples.md](https://github.com/burt202/lite-uploader/blob/master/examples.md)

### Tests & Coverage

`cd to project root`
`npm i`
`npm run tests`
`npm run coverage`

### Changelog

Expand Down

0 comments on commit 2b9e5bf

Please sign in to comment.