diff --git a/.travis.yml b/.travis.yml index 6e5919de..1398bdd8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: node_js node_js: - "0.10" +before_install: npm install -g grunt-cli \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 95e9943c..76d91b63 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -40,15 +40,24 @@ module.exports = function (grunt) { 'emojify-emoticons.css': 'images/emoji/{blush,scream,smirk,smiley,stuck_out_tongue_closed_eyes,stuck_out_tongue_winking_eye,rage,disappointed,sob,kissing_heart,wink,pensive,confounded,flushed,relaxed,mask,heart,broken_heart}.png' } } + }, + mochaTest: { + test: { + options: { + reporter: 'spec' + }, + src: ['tests/node/*.js'] + } } }); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-cssmin'); + grunt.loadNpmTasks('grunt-mocha-test'); grunt.loadNpmTasks('grunt-datauri'); - + grunt.registerTask('test-node', 'mochaTest'); grunt.registerTask( 'default', [ diff --git a/package.json b/package.json index 792a8e31..e911b1a4 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A Javascript module to convert emoji keywords to images.", "main": "emojify.js", "scripts": { - "test": "phantomjs phantom.js" + "test": "grunt test-node && phantomjs phantom.js" }, "repository": { "type": "git", @@ -27,7 +27,9 @@ "grunt-contrib-uglify": "~0.2.4", "grunt-datauri": "^0.4.0", "jstest": "~1.0.4", - "q": "^1.0.1" + "q": "^1.0.1", + "grunt-mocha-test": "~0.12.0", + "chai": "~1.9.1" }, "testling": { "html": "tests/browser.html", @@ -41,5 +43,6 @@ "ipad/6..latest", "android-browser/latest" ] - } + }, + "dependencies": {} } diff --git a/phantom.js b/phantom.js index eea7bbe7..10356bc0 100644 --- a/phantom.js +++ b/phantom.js @@ -4,4 +4,4 @@ phantom.injectJs('./node_modules/jstest/jstest.js'); var options = {format: 'dot'}, reporter = new JS.Test.Reporters.Headless(options); -reporter.open('./tests/browser.html'); \ No newline at end of file +reporter.open('./tests/browser/browser.html'); \ No newline at end of file diff --git a/tests/browser.html b/tests/browser.html deleted file mode 100644 index 0de720a5..00000000 --- a/tests/browser.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - jstest - - - - - - - - - diff --git a/tests/browser/browser.html b/tests/browser/browser.html new file mode 100644 index 00000000..be0a8bcd --- /dev/null +++ b/tests/browser/browser.html @@ -0,0 +1,14 @@ + + + + + jstest + + + + + + + + + diff --git a/tests/dom_spec.js b/tests/browser/dom_spec.js similarity index 100% rename from tests/dom_spec.js rename to tests/browser/dom_spec.js diff --git a/tests/emojify_tag_type_spec.js b/tests/browser/emojify_tag_type_spec.js similarity index 100% rename from tests/emojify_tag_type_spec.js rename to tests/browser/emojify_tag_type_spec.js diff --git a/tests/runner.js b/tests/browser/runner.js similarity index 50% rename from tests/runner.js rename to tests/browser/runner.js index 575e9f36..b63a52cb 100644 --- a/tests/runner.js +++ b/tests/browser/runner.js @@ -4,12 +4,12 @@ var run = function() { JS.Test.autorun(); }; -var ROOT = JS.ENV.ROOT || '..'; +var ROOT = JS.ENV.ROOT || '../..'; // JS.cache = false; JS.load(ROOT + '/emojify.js', - ROOT + '/tests/string_spec.js', - ROOT + '/tests/dom_spec.js', - ROOT + '/tests/emojify_tag_type_spec.js', + ROOT + '/tests/browser/string_spec.js', + ROOT + '/tests/browser/dom_spec.js', + ROOT + '/tests/browser/emojify_tag_type_spec.js', // add files here as the project grows run); diff --git a/tests/string_spec.js b/tests/browser/string_spec.js similarity index 100% rename from tests/string_spec.js rename to tests/browser/string_spec.js diff --git a/tests/node/index.js b/tests/node/index.js new file mode 100644 index 00000000..cfbb619a --- /dev/null +++ b/tests/node/index.js @@ -0,0 +1,22 @@ +var chai = require('chai'), + expect = chai.expect, + emojify; + +describe('emojify in a Node environment', function(){ + + beforeEach(function(){ + emojify = require('../../'); + }); + + describe('.replace', function(){ + it('should replace named emoji', function() { + var result = emojify.replace(':smile:'); + expect(result).to.equal(":smile:"); + }); + + it('should replace two-character emoji', function(){ + var result = emojify.replace(':)'); + expect(result).to.equal(":smile:"); + }); + }); +});