From 5baa6361e091fa402b1361191dbcb0b837b45595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Matall=C3=ADn?= Date: Fri, 22 Sep 2017 11:08:16 +0200 Subject: [PATCH] restore editor browser tests --- CONTRIBUTING.md | 12 +++++++++++- Gruntfile.js | 20 ++++++++++++-------- lib/build/tasks/browserify.js | 1 + lib/build/tasks/jasmine.js | 23 +++++++++++++++++++++++ lib/build/tasks/watch.js | 14 ++++++++++++++ 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dd0847f156..df62ad4344 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -107,7 +107,17 @@ grunt editor_specs After the building process finish, a webpage will show up with a link to the Jasmine page with all the specs. The URL of this page is `http://localhost:8089/_SpecRunner.html` -Editor specs process won't watch for changes, so every time you modify any file you'll have to run again the Editor specs command. +Then, the process will watch changes in the codebase and will regenerate the specs as needed. Just refresh the Jasmine page to pass again the tests. + +**Run specs and regular codebase simultaneously** + +If you want to run simultaneously the application and the specs generation follow these steps: + +1. Open a terminal with Node v6.9.2 (use nvm) and run `grunt dev`. This will build the application assets and will watch for changes. + +2. Open a second terminal and run `grunt affected_editor_specs`. + +3. That's it. When you change any Builder Javascript file `grunt dev` will build the application bundle and `grunt affected_editor_specs` will build the specs. #### Builder specs diff --git a/Gruntfile.js b/Gruntfile.js index 6deeac9e39..013219685c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -319,6 +319,7 @@ module.exports = function (grunt) { grunt.registerTask('js_editor', [ 'cdb', 'copy:js_cartodb', + 'setConfig:env.browserify_watch:true', 'run_browserify', 'concat:js', 'jst' @@ -440,13 +441,6 @@ module.exports = function (grunt) { 'watch:js_affected' ]); - grunt.registerTask('build-jasmine-specrunners', _.chain(jasmineCfg) - .keys() - .map(function (name) { - return ['jasmine', name, 'build'].join(':'); - }) - .value()); - grunt.registerTask('setConfig', 'Set a config property', function (name, val) { grunt.config.set(name, val); }); @@ -457,7 +451,17 @@ module.exports = function (grunt) { grunt.registerTask('editor_specs', [ 'js_editor', 'jasmine:cartodbui:build', - 'connect:server' + 'connect:server', + 'watch:js_affected_editor' + ]); + + /** + * `grunt affected_editor_specs` compile all Editor specs and launch a webpage in the browser. + */ + grunt.registerTask('affected_editor_specs', 'Build Editor specs', [ + 'jasmine:cartodbui_affected:build', + 'connect:server', + 'watch:js_affected_editor' ]); /** diff --git a/lib/build/tasks/browserify.js b/lib/build/tasks/browserify.js index 8733db582a..17fd031a9c 100644 --- a/lib/build/tasks/browserify.js +++ b/lib/build/tasks/browserify.js @@ -14,6 +14,7 @@ module.exports = { // enables watchify when grunt is run with a watch task // must be evaluated lazily (using template var) to allow override by setConfig task. + // watch: '<%= env.browserify_watch %>', watch: '<%= env.browserify_watch %>', browserifyOptions: { diff --git a/lib/build/tasks/jasmine.js b/lib/build/tasks/jasmine.js index dd9f1c589e..641f29f252 100644 --- a/lib/build/tasks/jasmine.js +++ b/lib/build/tasks/jasmine.js @@ -21,6 +21,29 @@ module.exports = { } }, + cartodbui_affected: { + src: js_files.all.concat([ + 'lib/build/user_data.js', + '<%= assets_dir %>/javascripts/templates_mustache.js', + '<%= assets_dir %>/javascripts/templates.js', + 'lib/build/test_init.js']), + options: { + browser: 'phantomjs', + headless: true, + timeout: 20000, + keepRunner: true, + outfile: '_SpecRunner-affected.html', + host: 'http://localhost:8088', + summary: true, + display: 'short', + helpers: ['http://maps.googleapis.com/maps/api/js?sensor=false&v=3.12'].concat(js_files._spec_helpers), + reportSlowerThan: 2000, + specs: [ + '.grunt/browserify_modules_tests.js' + ] + } + }, + affected: { options: { browser: 'phantomjs', diff --git a/lib/build/tasks/watch.js b/lib/build/tasks/watch.js index e0ee1a4e07..5e9c94c913 100644 --- a/lib/build/tasks/watch.js +++ b/lib/build/tasks/watch.js @@ -79,6 +79,20 @@ exports.task = function () { spawn: false, atBegin: false } + }, + js_affected_editor: { + files: [ + 'lib/assets/test/spec/cartodb/**/*' + ], + tasks: [ + 'concat:js', + 'jst', + 'jasmine:cartodbui_affected:build' + ], + options: { + spawn: false, + atBegin: false + } } }; };