Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Commit

Permalink
Merge pull request #59 from adam-lynch/node-tests
Browse files Browse the repository at this point in the history
Added some tests for Node
  • Loading branch information
hassankhan committed Sep 23, 2014
2 parents 3fe0900 + 9b9b3c3 commit 94e5979
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 23 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
language: node_js
node_js:
- "0.10"
before_install: npm install -g grunt-cli
11 changes: 10 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
[
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -41,5 +43,6 @@
"ipad/6..latest",
"android-browser/latest"
]
}
},
"dependencies": {}
}
2 changes: 1 addition & 1 deletion phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
reporter.open('./tests/browser/browser.html');
14 changes: 0 additions & 14 deletions tests/browser.html

This file was deleted.

14 changes: 14 additions & 0 deletions tests/browser/browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jstest</title>
</head>
<body>

<script src="../../node_modules/jstest/jstest.js"></script>
<script>ROOT = '../..'</script>
<script src="runner.js"></script>

</body>
</html>
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions tests/runner.js → tests/browser/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/node/index.js
Original file line number Diff line number Diff line change
@@ -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("<img title=':smile:' alt=':smile:' class='emoji' src='images/emoji/smile.png' align='absmiddle' />");
});

it('should replace two-character emoji', function(){
var result = emojify.replace(':)');
expect(result).to.equal("<img title=':smile:' alt=':smile:' class='emoji' src='images/emoji/smile.png' align='absmiddle' />");
});
});
});

0 comments on commit 94e5979

Please sign in to comment.