From 17157cd6f0a3299c3a15f17ec6a7b2ce8cb47a9d Mon Sep 17 00:00:00 2001 From: Adam Lynch Date: Mon, 22 Sep 2014 12:07:29 +0100 Subject: [PATCH 1/2] Added some tests for Node --- .travis.yml | 1 + Gruntfile.js | 11 +++++++++- package.json | 9 +++++--- phantom.js | 2 +- tests/browser.html | 14 ------------- tests/browser/browser.html | 14 +++++++++++++ tests/{ => browser}/dom_spec.js | 0 tests/{ => browser}/emojify_tag_type_spec.js | 0 tests/{ => browser}/runner.js | 8 +++---- tests/{ => browser}/string_spec.js | 0 tests/node/index.js | 22 ++++++++++++++++++++ 11 files changed, 58 insertions(+), 23 deletions(-) delete mode 100644 tests/browser.html create mode 100644 tests/browser/browser.html rename tests/{ => browser}/dom_spec.js (100%) rename tests/{ => browser}/emojify_tag_type_spec.js (100%) rename tests/{ => browser}/runner.js (50%) rename tests/{ => browser}/string_spec.js (100%) create mode 100644 tests/node/index.js 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 ca386314..27749763 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -27,6 +27,14 @@ module.exports = function (grunt) { src: 'emojify.css', dest: 'emojify.min.css' } + }, + mochaTest: { + test: { + options: { + reporter: 'spec' + }, + src: ['tests/node/*.js'] + } } }); @@ -63,8 +71,9 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-cssmin'); + grunt.loadNpmTasks('grunt-mocha-test'); - + grunt.registerTask('test-node', 'mochaTest'); grunt.registerTask( 'default', [ diff --git a/package.json b/package.json index 66e34654..3d3460e0 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", @@ -26,7 +26,9 @@ "grunt-contrib-jshint": "~0.6.4", "grunt-contrib-uglify": "~0.2.4", "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", @@ -40,5 +42,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:"); + }); + }); +}); From 9b9b3c30201f134a405e702f5e003aa265e7bfb3 Mon Sep 17 00:00:00 2001 From: Adam Lynch Date: Tue, 23 Sep 2014 10:40:43 +0100 Subject: [PATCH 2/2] Merge in from master --- Gruntfile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Gruntfile.js b/Gruntfile.js index e878415a..76d91b63 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -54,6 +54,7 @@ module.exports = function (grunt) { 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');