diff --git a/.eslintrc.js b/.eslintrc.js index 533de61..78a8eaa 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,8 @@ module.exports = { extends: 'loris/es5', root: true, env: { - node: true + node: true, + mocha: true }, rules: { strict: 'off', diff --git a/.gitignore b/.gitignore index 0db216b..8f771f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ npm-debug.log node_modules +coverage diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3bc0f29 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - "6" + - "5" + - "4" +script: + - npm run lint + - npm run test-coveralls diff --git a/README.md b/README.md index 087727b..7561c16 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # [React] Server render +[](https://travis-ci.org/alt-j/react-server) +[](https://david-dm.org/alt-j/react-server) +[](https://david-dm.org/alt-j/react-server?type=dev) +[](https://coveralls.io/github/alt-j/react-server) + The module for rendering react-element in the server **12 times as fast** (see [benchmarks](https://github.com/alt-j/react-server-benchmark)) as [traditional react rendering](https://facebook.github.io/react/docs/environments.html) (in production mode). ## Quick start diff --git a/package.json b/package.json index d25d2fe..c8ad4df 100644 --- a/package.json +++ b/package.json @@ -21,11 +21,19 @@ "registry": "https://registry.npmjs.org/" }, "scripts": { - "lint": "./node_modules/.bin/eslint . --quiet" + "test": "npm run lint && npm run test-cov", + "test-cov": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --recursive --check-leaks", + "test-coveralls": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", + "lint": "./node_modules/.bin/eslint . --quiet --ignore-path .gitignore" }, "devDependencies": { - "eslint": "^3.4.0", - "eslint-config-loris": "^5.1.0", - "git-hooks": "^1.1.0" + "chai": "3.5.0", + "coveralls": "2.11.12", + "eslint": "3.4.0", + "eslint-config-loris": "5.1.0", + "git-hooks": "1.1.0", + "istanbul": "0.4.5", + "mocha": "3.0.2", + "mocha-lcov-reporter": "1.2.0" } } diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..08e754a --- /dev/null +++ b/test/index.js @@ -0,0 +1,39 @@ +var chai = require('chai'); +var expect = chai.expect; +var React = require('../index'); + +describe('React', function () { + describe('cleanHtml', function () { + it('should be a function', function () { + expect(React.cleanHtml).to.be.a('function'); + }); + + it('should clean rendered string', function () { + expect(React.cleanHtml('link')).to.equal('link'); + }); + }); + + describe('createClass', function () { + it('should be a function', function () { + expect(React.createClass).to.be.a('function'); + }); + + it('should return a function', function () { + expect(React.createClass({})).to.be.a('function'); + }); + }); + + describe('createElement', function () { + it('should be a function', function () { + expect(React.createElement).to.be.a('function'); + }); + + it('should render div as string', function () { + expect(React.createElement('div')).to.equal('
'); + }); + + it('should render null object', function () { + expect(React.createElement(null)).to.equal(''); + }); + }); +}); diff --git a/test/utils/dasherize.js b/test/utils/dasherize.js new file mode 100644 index 0000000..0241cb0 --- /dev/null +++ b/test/utils/dasherize.js @@ -0,0 +1,34 @@ +var chai = require('chai'); +var expect = chai.expect; +var dasherize = require('../../utils/dasherize'); + +describe('dasherize', function () { + it('should be a function', function () { + expect(dasherize).to.be.a('function'); + }); + + it('should change UpperCamelCase to kebab-case', function () { + expect(dasherize('UpperCamelCase')).to.equal('upper-camel-case'); + }); + + it('should change lowerCamelCase to kebab-case', function () { + expect(dasherize('lowerCamelCase')).to.equal('lower-camel-case'); + }); + + it('should not change lowercase string', function () { + var string = 'lowercase string'; + expect(dasherize(string)).to.equal(string); + }); + + it('should return `background` css properties', function () { + expect(dasherize('background')).to.equal('background'); + }); + + it('should return `z-index` css properties', function () { + expect(dasherize('zIndex')).to.equal('z-index'); + }); + + it('should return `border-bottom-color` css properties', function () { + expect(dasherize('borderBottomColor')).to.equal('border-bottom-color'); + }); +}); diff --git a/test/utils/escape/attr.js b/test/utils/escape/attr.js new file mode 100644 index 0000000..f6781db --- /dev/null +++ b/test/utils/escape/attr.js @@ -0,0 +1,22 @@ +var chai = require('chai'); +var expect = chai.expect; +var attr = require('../../../utils/escape/attr'); + +describe('attr', function () { + it('should be a function', function () { + expect(attr).to.be.a('function'); + }); + + it('should not change correct string', function () { + var string = 'forbidden'; + expect(attr(string)).to.equal(string); + }); + + it('should escape `&` sign', function () { + expect(attr('&')).to.equal('&'); + }); + + it('should escape `"` sign', function () { + expect(attr('"')).to.equal('"'); + }); +}); diff --git a/test/utils/escape/html.js b/test/utils/escape/html.js new file mode 100644 index 0000000..079f0b8 --- /dev/null +++ b/test/utils/escape/html.js @@ -0,0 +1,30 @@ +var chai = require('chai'); +var expect = chai.expect; +var html = require('../../../utils/escape/html'); + +describe('html', function () { + it('should be a function', function () { + expect(html).to.be.a('function'); + }); + + it('should not change correct string', function () { + var string = 'div a="b"'; + expect(html(string)).to.equal(string); + }); + + it('should escape `&` sign', function () { + expect(html('&')).to.equal('&'); + }); + + it('should escape `<` sign', function () { + expect(html('<')).to.equal('<'); + }); + + it('should escape `>` sign', function () { + expect(html('>')).to.equal('>'); + }); + + it('should escape html string', function () { + expect(html('