Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
extends: 'loris/es5',
root: true,
env: {
node: true
node: true,
mocha: true
},
rules: {
strict: 'off',
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npm-debug.log
node_modules
coverage
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js
node_js:
- "6"
- "5"
- "4"
script:
- npm run lint
- npm run test-coveralls
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# [React] Server render

[![Build Status](https://travis-ci.org/alt-j/react-server.svg?branch=master)](https://travis-ci.org/alt-j/react-server)
[![dependencies Status](https://david-dm.org/alt-j/react-server/status.svg)](https://david-dm.org/alt-j/react-server)
[![devDependencies Status](https://david-dm.org/alt-j/react-server/dev-status.svg)](https://david-dm.org/alt-j/react-server?type=dev)
[![Coverage Status](https://coveralls.io/repos/github/alt-j/react-server/badge.svg)](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
Expand Down
16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
39 changes: 39 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var chai = require('chai');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the coming days, lib API will change (#5), so you can cover only utils

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I left only the primary tests

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('<!----><a>link</a>')).to.equal('<a>link</a>');
});
});

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('<!----><div></div>');
});

it('should render null object', function () {
expect(React.createElement(null)).to.equal('');
});
});
});
34 changes: 34 additions & 0 deletions test/utils/dasherize.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
22 changes: 22 additions & 0 deletions test/utils/escape/attr.js
Original file line number Diff line number Diff line change
@@ -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('&amp;');
});

it('should escape `"` sign', function () {
expect(attr('"')).to.equal('&quot;');
});
});
30 changes: 30 additions & 0 deletions test/utils/escape/html.js
Original file line number Diff line number Diff line change
@@ -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('&amp;');
});

it('should escape `<` sign', function () {
expect(html('<')).to.equal('&lt;');
});

it('should escape `>` sign', function () {
expect(html('>')).to.equal('&gt;');
});

it('should escape html string', function () {
expect(html('<div class="name">&gt;</div>')).to.equal('&lt;div class="name"&gt;&amp;gt;&lt;/div&gt;');
});
});
87 changes: 87 additions & 0 deletions test/utils/extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
var chai = require('chai');
var expect = chai.expect;
var extend = require('../../utils/extend');

var str = 'me a test';
var integer = 10;
var arr = [1, 'what', new Date(81, 8, 4)];
var date = new Date(81, 4, 13);

var Foo = function () {};

var obj = {
str: str,
integer: integer,
arr: arr,
date: date,
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};

describe('extend', function () {
it('should be a function', function () {
expect(extend).to.be.a('function');
});

it('without arguments should return an object', function () {
expect(extend()).to.deep.equal({});
});

it('should merge object with object', function () {
var ori = {
str: 'no shit',
integer: 76,
arr: [1, 2, 3, 4],
date: new Date(81, 7, 26),
foo: 'bar'
};
var target = extend(ori, obj);
var expectedObj = {
str: 'me a test',
integer: 10,
arr: [1, 'what', new Date(81, 8, 4)],
date: new Date(81, 4, 13),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
var expectedTarget = {
str: 'me a test',
integer: 10,
arr: [1, 'what', new Date(81, 8, 4)],
date: new Date(81, 4, 13),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
expect(obj).to.deep.equal(expectedObj);
expect(target).to.deep.equal(expectedTarget);
});

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add test for case one and three object

it('should handle null object normally', function () {
var target = extend(null, obj);
expect(target).to.deep.equal(obj);
});

it('should merge any count of objects', function () {
var ori = {
str: 'no shit',
integer: 76,
arr: [1, 2, 3, 4],
date: new Date(81, 7, 26),
foo: 'bar'
};
var target = extend(ori, obj, {str: 'normal', integer: 0}, {integer: 42});
var expectedTarget = {
str: 'normal',
integer: 42,
arr: [1, 'what', new Date(81, 8, 4)],
date: new Date(81, 4, 13),
constructor: 'fake',
isPrototypeOf: 'not a function',
foo: new Foo()
};
expect(target).to.deep.equal(expectedTarget);
});
});