commit 06376bd032593a7f52b9656c6131219aa9e085b2
parent ea149ee703e2399e951d894b3ef1a4245d648ae9
Author: Konstantin Tarkus <hello@tarkus.me>
Date: Wed, 8 Oct 2014 12:14:21 +0400
Merge branch 'master' of https://github.com/metagen/react-starter-kit into jest
Diffstat:
7 files changed, 46 insertions(+), 89 deletions(-)
diff --git a/.travis.yml b/.travis.yml
@@ -3,11 +3,4 @@ node_js:
- '0.10'
before_script:
- - export DISPLAY=:99.0
- - sh -e /etc/init.d/xvfb start
- - node_modules/.bin/gulp > /dev/null &
- - npm run update-webdriver
- - sleep 1 # give server time to start
-
-script:
- - node_modules/karma/bin/karma start ./config/karma.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox
+ - npm install
diff --git a/README.md b/README.md
@@ -94,6 +94,13 @@ $ git merge upstream/master
$ npm install
```
+### Running Unit Tests
+Jest tests are located in the __tests__ directory. Run them with this npm script:
+
+```shell
+$ npm test
+```
+
### Learn More
* [Getting Started with React.js](http://facebook.github.io/react/)
@@ -102,6 +109,7 @@ $ npm install
* [React.js Discussion Board](https://groups.google.com/forum/#!forum/reactjs)
* [Flux Architecture for Building User Interfaces](http://facebook.github.io/flux/)
* [The Future of React](https://github.com/reactjs/react-future)
+ * [Jest | Painless Unit Testing](http://facebook.github.io/jest/)
### Support
diff --git a/config/karma.js b/config/karma.js
@@ -1,58 +0,0 @@
-/*!
- * Facebook React Starter Kit | https://github.com/kriasoft/react-starter-kit
- * Copyright (c) KriaSoft, LLC. All rights reserved. See LICENSE.txt
- */
-
-/*
- * Karma configuration. For more information visit
- * http://karma-runner.github.io/0.12/config/configuration-file.html
- */
-
-'use strict';
-
-var webpackConfig = require('./webpack.js')(/* release */ false);
-
-module.exports = function (config) {
- config.set({
-
- basePath: '../',
-
- files: [
- 'src/**/*Spec.jsx'
- ],
-
- preprocessors: {
- 'src/**/*Spec.jsx': ['webpack']
- },
-
- webpack: {
- cache: true,
- module: {
- loaders: webpackConfig.module.loaders
- }
- },
-
- webpackServer: {
- stats: {
- colors: true
- }
- },
-
- autoWatch: false,
-
- singleRun: true,
-
- frameworks: ['jasmine'],
-
- browsers: ['Chrome'],
-
- plugins: [
- 'karma-chrome-launcher',
- 'karma-firefox-launcher',
- 'karma-phantomjs-launcher',
- 'karma-jasmine',
- 'karma-webpack'
- ]
-
- });
-};
diff --git a/config/preprocessor.js b/config/preprocessor.js
@@ -0,0 +1,11 @@
+'use strict';
+
+var ReactTools = require('react-tools');
+
+module.exports = {
+ process: function(src, path) {
+ return ReactTools.transform(
+ path.match(/\.jsx$/) ? '/**@jsx React.DOM*/' + src : src,
+ {harmony: true});
+ }
+};
diff --git a/package.json b/package.json
@@ -34,30 +34,29 @@
"gulp-size": "^1.1.0",
"gulp-uglify": "^1.0.1",
"gulp-util": "^3.0.1",
+ "jest-cli": "^0.1.18",
"jshint": "^2.5.6",
"jshint-loader": "^0.8.0",
"jshint-stylish": "^1.0.0",
"jsx-loader": "^0.11.2",
- "karma": "^0.12.24",
- "karma-chrome-launcher": "^0.1.5",
- "karma-firefox-launcher": "^0.1.3",
- "karma-jasmine": "^0.1.5",
- "karma-phantomjs-launcher": "^0.1.4",
- "karma-webpack": "^1.2.2",
"merge-stream": "^0.1.6",
"minimist": "^1.1.0",
"protractor": "^1.3.1",
"psi": "^0.1.2",
+ "react-tools": "^0.11.2",
"run-sequence": "^1.0.1",
"url-loader": "^0.5.5",
"webpack": "^1.4.4",
"webpack-dev-server": "^1.6.5"
},
+ "jest": {
+ "rootDir": "src",
+ "scriptPreprocessor": "../config/preprocessor.js",
+ "unmockedModulePathPatterns": ["react"]
+ },
"scripts": {
- "prestart": "npm install",
"start": "gulp",
- "pretest": "npm install",
- "test": "karma start ./config/karma.js --single-run",
+ "test": "jest",
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update"
}
diff --git a/src/components/NavbarSpec.jsx b/src/components/NavbarSpec.jsx
@@ -1,14 +0,0 @@
-'use strict';
-
-describe('Navbar', () => {
- var Navbar, component;
-
- beforeEach(() => {
- Navbar = require('./Navbar.jsx');
- component = Navbar();
- });
-
- it('should create a new instance of Navbar', () => {
- expect(component).toBeDefined();
- });
-});
diff --git a/src/components/__tests__/Navbar-test.js b/src/components/__tests__/Navbar-test.js
@@ -0,0 +1,18 @@
+/* global jest, describe, it, expect */
+
+'use strict';
+
+jest.dontMock('../Navbar.jsx');
+
+describe('Navbar', function() {
+ it('sets class name', function() {
+ var React = require('react/addons');
+ var TestUtils = React.addons.TestUtils;
+
+ var Navbar = require('../Navbar.jsx');
+ var Component = TestUtils.renderIntoDocument(new Navbar());
+
+ var element = TestUtils.findRenderedDOMComponentWithClass(Component, 'navbar-top');
+ expect(element).toBeDefined();
+ });
+});