From fb944520e1f9dfb00e054d242e489eb7c44840f7 Mon Sep 17 00:00:00 2001 From: Jeoffrey Mendez Date: Tue, 25 Aug 2015 23:21:15 -0400 Subject: [PATCH] [PBW-3069-jest] added jest, js unit testing framework, to alice. Includes code coverage --- .gitignore | 4 +++- README.md | 11 ++++++++++ gulpfile.js | 4 ++++ package.json | 32 ++++++++++++++++++++++++++--- scripts/jest/environment.js | 1 + scripts/jest/preprocessor.js | 7 +++++++ tests/components/sharePanel-test.js | 17 +++++++++++++++ 7 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 scripts/jest/environment.js create mode 100644 scripts/jest/preprocessor.js create mode 100644 tests/components/sharePanel-test.js diff --git a/.gitignore b/.gitignore index b7dab5e9c..e0d8964bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules -build \ No newline at end of file +build +coverage +.idea \ No newline at end of file diff --git a/README.md b/README.md index 707dc768e..e6f52f612 100644 --- a/README.md +++ b/README.md @@ -76,5 +76,16 @@ To start a python server, cd into the repo directory and run: You should now be able to load the sample page by hitting http://localhost:8000/sample.html +## Testing +To run tests, run this command: + + npm test + +Add test files to directory `tests/`. + +Test file should have same location and name as `js/` file with `-test` after test file name. + +For example, component file `js/components/sharePanel.js` will have test file `tests/components/sharePanel-test.js`. + ## Publisher and Ooyala Customer Able to fork git repo and build the skin at will. Terms and condition apply. Please read [Ooyala open-source onboarding guide](http://www.ooyala.com) diff --git a/gulpfile.js b/gulpfile.js index bb96b1a24..93ace5a67 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,7 @@ var gulp = require('gulp'), uglify = require('gulp-uglify'), jshint = require('gulp-jshint'), react = require('gulp-react'); + shell = require('gulp-shell'); var path = { scripts: ['./js/include/header.js', './js/components/*.js', './js/*.js', './js/include/footer.js'], @@ -34,6 +35,9 @@ gulp.task('buildCss', function() { .pipe(gulp.dest('build')); }); +// Run tests +gulp.task('test', shell.task(['npm test'])); + // Initiate a watch gulp.task('watch', function() { gulp.watch(path.scripts, ['concat', 'buildScript']); diff --git a/package.json b/package.json index fbb1dc23d..97ff63cc3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "main": "html5-skin.js", "scripts": { "build": "", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "jest" }, "repository": { "type": "git", @@ -18,13 +18,16 @@ }, "dependencies": { "gulp": "3.8.11", + "react": "0.12.2", "react-tools":"*" }, "devDependencies": { "gulp-concat": "2.5.2", "gulp-uglify": "1.1.0", "gulp-jshint": "1.10.0", - "gulp-react": "3.0.1" + "gulp-react": "3.0.1", + "gulp-shell": "0.4.2", + "jest-cli": "0.4.18" }, "author": "Ooyala", "contributors": [ @@ -34,5 +37,28 @@ "bugs": { "url": "https://github.com/ooyala/html5-skin/issues" }, - "homepage": "https://github.com/ooyala/html5-skin" + "homepage": "https://github.com/ooyala/html5-skin", + "jest": { + "modulePathIgnorePatterns": [ + "/build/", + "/node_modules/" + ], + "persistModuleRegistryBetweenSpecs": true, + "preprocessorIgnorePatterns": [ + "/node_modules/" + ], + "rootDir": "", + "scriptPreprocessor": "scripts/jest/preprocessor.js", + "setupEnvScriptFile": "scripts/jest/environment.js", + "unmockedModulePathPatterns": [ + "/node_modules/react", + "react" + ], + + "testPathDirs": [ + "" + ], + "testDirectoryName": "tests", + "collectCoverage": true + } } \ No newline at end of file diff --git a/scripts/jest/environment.js b/scripts/jest/environment.js new file mode 100644 index 000000000..8f7624205 --- /dev/null +++ b/scripts/jest/environment.js @@ -0,0 +1 @@ +__DEV__ = true; \ No newline at end of file diff --git a/scripts/jest/preprocessor.js b/scripts/jest/preprocessor.js new file mode 100644 index 000000000..0158d52fb --- /dev/null +++ b/scripts/jest/preprocessor.js @@ -0,0 +1,7 @@ +var ReactTools = require('react-tools'); + +module.exports = { + process: function (src) { + return ReactTools.transform(src); + } +}; \ No newline at end of file diff --git a/tests/components/sharePanel-test.js b/tests/components/sharePanel-test.js new file mode 100644 index 000000000..419d8aac6 --- /dev/null +++ b/tests/components/sharePanel-test.js @@ -0,0 +1,17 @@ +jest.dontMock('../../js/components/sharePanel.js'); + +describe('SharePanel', function () { + it('displays social screen after click', function () { + var React = require('react/addons'); + //var SharePanel = require('../../js/components/sharePanel.js'); + var TestUtils = React.addons.TestUtils; + + // Render share panel in document + /* + var sharePanel = TestUtils.renderIntoDocument( + + ); + */ + + }); +}); \ No newline at end of file