Skip to content

Commit

Permalink
Add test infrastructure to the Rect UI
Browse files Browse the repository at this point in the history
Fixes #148
  • Loading branch information
ipeychev committed Mar 24, 2015
1 parent 3160465 commit 325cc02
Show file tree
Hide file tree
Showing 12 changed files with 1,757 additions and 36 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"dependencies": {},
"devDependencies": {
"bourbon": "https://github.com/thoughtbot/bourbon/tarball/master",
"chai": "^2.1.1",
"chai": "^2.1.2",
"del": "^1.1.1",
"event-stream": "^3.3.0",
"gulp": "~3.8.11",
"gulp-compass": "^2.0.3",
"gulp-compass": "^2.0.4",
"gulp-concat": "^2.5.2",
"gulp-consolidate": "^0.1.2",
"gulp-iconfont": "^1.0.0",
"gulp-karma": "0.0.4",
"gulp-minify-css": "^1.0.0",
"gulp-react": "^3.0.0",
"gulp-react": "^3.0.1",
"gulp-rename": "^1.2.0",
"gulp-replace": "^0.5.3",
"gulp-sass": "~1.3.3",
Expand All @@ -35,11 +35,12 @@
"karma-sauce-launcher": "^0.2.10",
"karma-sinon": "^1.0.4",
"lodash": "^3.5.0",
"mkdirp": "^0.5.0",
"mocha": "^2.2.1",
"require-dir": "^0.1.0",
"require-dir": "^0.2.0",
"run-sequence": "^1.0.2",
"sinon": "^1.13.0",
"yargs": "^3.5.3"
"sinon": "^1.14.1",
"yargs": "^3.6.0"
},
"scripts": {
"test": "gulp test"
Expand Down
18 changes: 18 additions & 0 deletions src/ui/react/_src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = [
'core/debounce.js',
'core/link.js',
'core/selection-region.js',
'core/tools.js',
'core/uicore.js',
'plugins/drop-images.js',
'plugins/placeholder.js',
'ui/react/src/oop/lang.js',
'ui/react/src/oop/oop.js',
'ui/react/src/oop/attribute.js',
'ui/react/src/oop/base.js',
'ui/react/src/adapter/alloy-editor-adapter.js*',
'ui/react/src/components/base/*.js*',
'ui/react/src/components/buttons/*.js*',
'ui/react/src/components/toolbars/*.js*',
'ui/react/src/components/main.js*'
];
37 changes: 11 additions & 26 deletions src/ui/react/gulp-tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var pkg = require(path.join(rootDir, 'package.json'));
var distFolder = path.join(rootDir, 'dist');
var editorDistFolder = path.join(distFolder, 'alloy-editor-' + pkg.version, 'alloy-editor');

var srcFiles = require('../_src.js');

function errorHandler(error) {
console.log(error.toString());

Expand All @@ -29,7 +31,7 @@ function errorHandler(error) {

gulp.task('build', function(callback) {
runSequence(
'clean-dist', ['build-css', 'build-js'], 'minimize-js', [
'clean-dist', ['build-css', 'build-js'], ['minimize-css', 'minimize-js'], [
'create-alloy-editor', 'create-alloy-editor-min'
],
'build-demo',
Expand All @@ -49,7 +51,7 @@ gulp.task('build-demo', function() {

return gulp.src([
path.join(reactDir, 'demo', 'index.html'),
path.join(reactDir, 'demo', 'bootstrap.css'),
path.join(reactDir, 'demo', 'bootstrap.css')
])
.pipe(template({
resources: fs.readFileSync(path.join(reactDir, 'template', templateHead))
Expand All @@ -60,7 +62,7 @@ gulp.task('build-demo', function() {
gulp.task('build-js', function(callback) {
runSequence([
'copy-ckeditor',
'create-alloy-editor-core',
'create-alloy-editor-core'
], 'wrap-alloy-editor-core', 'wrap-alloy-editor-global', callback);
});

Expand All @@ -77,7 +79,7 @@ gulp.task('create-alloy-editor', function() {
return gulp.src([
path.join(editorDistFolder, 'ckeditor.js'),
path.join(reactDir, 'vendor', 'react.js'),
path.join(editorDistFolder, 'alloy-editor-core.js'),
path.join(editorDistFolder, 'alloy-editor-core.js')
])
.pipe(concat('alloy-editor-all.js'))
.pipe(replace(/ckeditor(\\?).js/g, 'alloy-editor-all$1.js'))
Expand All @@ -88,35 +90,18 @@ gulp.task('create-alloy-editor-min', function() {
return gulp.src([
path.join(editorDistFolder, 'ckeditor.js'),
path.join(reactDir, 'vendor', 'react-min.js'),
path.join(editorDistFolder, 'alloy-editor-core-min.js'),
path.join(editorDistFolder, 'alloy-editor-core-min.js')
])
.pipe(concat('alloy-editor-all-min.js'))
.pipe(replace(/ckeditor(\\?).js/g, 'alloy-editor-all-min$1.js'))
.pipe(gulp.dest(editorDistFolder));
});

gulp.task('create-alloy-editor-core', function() {
return gulp.src([
path.join(rootDir, 'src/core/debounce.js'),
path.join(rootDir, 'src/core/link.js'),
path.join(rootDir, 'src/core/selection-region.js'),
path.join(rootDir, 'src/core/tools.js'),
path.join(rootDir, 'src/core/uicore.js'),
path.join(rootDir, 'src/plugins/drop-images.js'),
path.join(rootDir, 'src/plugins/placeholder.js'),
path.join(reactDir, 'src/oop/lang.js'),
path.join(reactDir, 'src/oop/attribute.js'),
path.join(reactDir, 'src/oop/oop.js'),
path.join(reactDir, 'src/oop/base.js'),
path.join(reactDir, 'src/adapter/alloy-editor-adapter.js*'),
path.join(reactDir, 'src/components/base/*.js*'),
path.join(reactDir, 'src/components/buttons/*.js*'),
path.join(reactDir, 'src/components/toolbars/*.js*'),
path.join(reactDir, 'src/components/main.jsx')
])
.pipe(react()).on('error', errorHandler)
.pipe(concat('alloy-editor-core.js'))
.pipe(gulp.dest(editorDistFolder));
return gulp.src(srcFiles, {cwd : rootDir + '/src'})
.pipe(react()).on('error', errorHandler)
.pipe(concat('alloy-editor-core.js'))
.pipe(gulp.dest(editorDistFolder));
});

gulp.task('minimize-js', function() {
Expand Down
11 changes: 11 additions & 0 deletions src/ui/react/gulp-tasks/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ var del = require('del');
var es = require('event-stream');
var fs = require('fs');
var gulp = require('gulp');
var minifyCSS = require('gulp-minify-css');
var path = require('path');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');

Expand Down Expand Up @@ -60,6 +62,15 @@ gulp.task('build-css', function(callback) {
runSequence(['sass2css', 'generate-fonts'], 'join-css', 'clean-fonts', callback);
});

gulp.task('minimize-css', function() {
return gulp.src(path.join(editorDistFolder, 'assets/*.css'))
.pipe(minifyCSS())
.pipe(rename({
suffix: '-min'
}))
.pipe(gulp.dest(path.join(editorDistFolder, 'assets')));
});

gulp.task('clean-fonts', function(callback) {
del([
path.join(editorDistFolder, 'assets/alloyeditor-font.css'),
Expand Down
39 changes: 36 additions & 3 deletions src/ui/react/gulp-tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,43 @@

var gulp = require('gulp');
var karma = require('karma').server;
var mkdirp = require('mkdirp');
var path = require('path');
var react = require('gulp-react');
var runSequence = require('run-sequence');

gulp.task('test', ['build'], function (done) {
// TODO: run karma here with the tests for ReactUI
var rootDir = path.join(__dirname, '..', '..', '..', '..');
var reactDir = path.join(rootDir, 'src', 'ui', 'react');
var pkg = require(path.join(rootDir, 'package.json'));

done();
var distFolder = path.join(rootDir, 'dist');
var editorDistFolder = path.join(distFolder, 'alloy-editor-' + pkg.version, 'alloy-editor');

var srcFiles = require('../_src.js');

gulp.task('prepare-files', function(done) {
runSequence(
'clean-dist', 'create-output-dir', ['build-css', 'copy-ckeditor', 'copy-src-files', 'copy-react'], done);
});

gulp.task('create-output-dir', function(callback) {
mkdirp(editorDistFolder, callback);
});

gulp.task('copy-src-files', function() {
return gulp.src(srcFiles, {cwd: 'src', base: 'src'})
.pipe(react())
.pipe(gulp.dest(path.join(editorDistFolder, 'test')));
});

gulp.task('copy-react', function() {
return gulp.src(path.join(reactDir, 'vendor', 'react.js'))
.pipe(gulp.dest(editorDistFolder));
});

gulp.task('test', ['prepare-files'], function (done) {
karma.start({
configFile: path.join(__dirname, '../karma.js'),
singleRun: true
}, done);
});
Loading

0 comments on commit 325cc02

Please sign in to comment.