Skip to content

Commit

Permalink
Added tests and travis config.
Browse files Browse the repository at this point in the history
  • Loading branch information
enyo committed Apr 4, 2013
1 parent c330e8f commit 00433eb
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .travis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.10
- 0.8
- 0.6
25 changes: 23 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ Please do also **send pull requests to the `develop` branch**.
I will **not** merge pull requests to the `master` branch.


### Developer Dependencies

The first thing you need to do, is to install the developer dependencies:

```bash
$ npm install
```

This will install all the tools you need to compile the source files and to test
the library.

### Coffeescript & Stylus (-> Javascript & CSS)

Dropzone is written in [Coffeescript](http://coffeescript.org) and
Expand All @@ -24,16 +35,26 @@ Please don't include compiled `.js` or `.css` files in your pull requests but on
`.coffee` or `.styl` files. That way pull requests aren't polluted and I can see
immediately what you changed.

### Building

If you want to build the library to test it, use [grunt](http://gruntjs.com).
To build the library use [grunt](http://gruntjs.com).

```bash
$ grunt -h # Displays available options
$ grunt # compiles all coffeescript and stylus files
$ grunt watch # watches for changes and builds on the fly
```

> I recommend using `grunt watch` when you begin developing. This way you can't
> forget to compile the source files and will avoid headaches.
### Testing

To test the library, open `test/test.html` in your browser or type `npm test`
which will run the tests in your console in a headless browser.

The tests are also written in coffeescript in the `test/test.coffee` file,
and compiled with `grunt js` or `grunt watch`.


* Thanks for contributing!*

10 changes: 9 additions & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ module.exports = (grunt) ->
default:
files:
"lib/dropzone.js": "src/dropzone.coffee"

test:
files:
"test/test.js": "test/*.coffee"

component:
app:
Expand Down Expand Up @@ -51,6 +53,12 @@ module.exports = (grunt) ->
]
tasks: [ "js" ]
options: nospawn: on
test:
files: [
"test/*.coffee"
]
tasks: [ "coffee:test" ]
options: nospawn: on
css:
files: [
"downloads/css/stylus/*.styl"
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"email": "[email protected]",
"web": "http://www.matiasmeno.com"
}],
"scripts": {
"test": "node_modules/mocha-phantomjs/bin/mocha-phantomjs test/test.html"
},
"bugs": {
"mail": "[email protected]"
},
Expand All @@ -36,7 +39,10 @@
"grunt-contrib-uglify": "*",
"grunt-component-build": "*",
"grunt-contrib-copy": "*",
"grunt-contrib-watch": "*"
"grunt-contrib-watch": "*",
"mocha-phantomjs": "*",
"mocha": "*",
"chai": "*"
}

}
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Dropzone.js Version 2.0.9-dev

![Build status](https://travis-ci.org/enyo/dropzone.png?branch=master) (Master)
![Build status](https://travis-ci.org/enyo/dropzone.png) (Development)

Dropzone.js is a light weight JavaScript library that turns an HTML element into a dropzone.
This means that a user can drag and drop a file onto it, and the file gets uploaded to the server via AJAX.

Expand Down
12 changes: 12 additions & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
chai.should()

describe "Dropzone", ->
describe "constructor()", ->

it "should throw an exception if the element is invalid", ->
expect(-> new Dropzone "#invalid-element").to.throw "Invalid dropzone element."

it "should throw an exception if assigned twice to the same element", ->
element = document.createElement "div"
new Dropzone element, url: "url"
expect(-> new Dropzone element, url: "url").to.throw "Dropzone already attached."
21 changes: 21 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />

<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../downloads/dropzone.js"></script>

<script>
mocha.ui('bdd');
mocha.reporter('html');
expect = chai.expect;
chai.should();
</script>
<script src="test.js"></script>

<script>
if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
else { mocha.run(); }
</script>
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function() {
chai.should();

describe("Dropzone", function() {
return describe("constructor()", function() {
it("should throw an exception if the element is invalid", function() {
return expect(function() {
return new Dropzone("#invalid-element");
}).to["throw"]("Invalid dropzone element.");
});
return it("should throw an exception if assigned twice to the same element", function() {
var element;

element = document.createElement("div");
new Dropzone(element, {
url: "url"
});
return expect(function() {
return new Dropzone(element, {
url: "url"
});
}).to["throw"]("Dropzone already attached.");
});
});
});

}).call(this);

0 comments on commit 00433eb

Please sign in to comment.