From fe4a5706acb4a734acccc86a01416ed695ffbd06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 21 Feb 2017 13:41:17 -0500 Subject: Test rails-ujs in our travis matrix --- .gitignore | 2 + .travis.yml | 9 ++ actionview/Rakefile | 27 ++++ actionview/coffeelint.json | 135 +++++++++++++++++++ actionview/package.json | 2 +- actionview/test/ujs/config.ru | 1 + actionview/test/ujs/server.rb | 37 +---- .../test/ujs/views/layouts/application.html.erb | 23 +--- actionview/test/ujs/views/tests/index.html.erb | 14 -- ci/phantomjs.js | 149 +++++++++++++++++++++ ci/travis.rb | 9 +- 11 files changed, 338 insertions(+), 70 deletions(-) create mode 100644 actionview/coffeelint.json create mode 100644 ci/phantomjs.js diff --git a/.gitignore b/.gitignore index 4961ad588f..32939b7bfd 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ pkg /railties/doc /railties/tmp /guides/output +node_modules/ +/actionview/log diff --git a/.travis.yml b/.travis.yml index eafa06e44f..ae4d78a31f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ cache: directories: - /tmp/cache/unicode_conformance - /tmp/beanstalkd-1.10 + - node_modules + - $HOME/.nvm services: - memcached @@ -21,6 +23,11 @@ before_install: - "gem update bundler" - "[ -f /tmp/beanstalkd-1.10/Makefile ] || (curl -L https://github.com/kr/beanstalkd/archive/v1.10.tar.gz | tar xz -C /tmp)" - "pushd /tmp/beanstalkd-1.10 && make && (./beanstalkd &); popd" + - "[[ $GEM != 'av:ujs' ]] || nvm install node" + - "[[ $GEM != 'av:ujs' ]] || node --version" + - "[[ $GEM != 'av:ujs' ]] || (cd actionview && npm install)" + - "[[ $GEM != 'av:ujs' ]] || [[ $(phantomjs --version) > '2' ]] || npm install -g phantomjs-prebuilt" + before_script: # Set Sauce Labs username and access key. Obfuscated, purposefully not encrypted. @@ -52,6 +59,8 @@ rvm: matrix: include: + - rvm: 2.4.0 + env: "GEM=av:ujs" - rvm: 2.2.6 env: "GEM=aj:integration" services: diff --git a/actionview/Rakefile b/actionview/Rakefile index cba4684076..00ab92129d 100644 --- a/actionview/Rakefile +++ b/actionview/Rakefile @@ -1,4 +1,5 @@ require "rake/testtask" +require "fileutils" desc "Default Task" task default: :test @@ -25,6 +26,32 @@ namespace :test do t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) end + task :ujs do + begin + Dir.mkdir("log") + pid = spawn("bundle exec rackup test/ujs/config.ru -p 4567 -s puma > log/test.log 2>&1") + + start_time = Time.now + + loop do + break if system("lsof -i :4567 >/dev/null") + + if Time.now - start_time > 5 + puts "Timed out after 5 seconds" + exit 1 + end + end + + system("npm run lint && phantomjs ../ci/phantomjs.js http://localhost:4567/") + status = $?.to_i + ensure + Process.kill("KILL", pid) if pid + FileUtils.rm_f("log") + end + + exit status + end + namespace :integration do desc "ActiveRecord Integration Tests" Rake::TestTask.new(:active_record) do |t| diff --git a/actionview/coffeelint.json b/actionview/coffeelint.json new file mode 100644 index 0000000000..cf8bf2171b --- /dev/null +++ b/actionview/coffeelint.json @@ -0,0 +1,135 @@ +{ + "arrow_spacing": { + "level": "warn" + }, + "braces_spacing": { + "level": "warn", + "spaces": 1, + "empty_object_spaces": 0 + }, + "camel_case_classes": { + "level": "error" + }, + "coffeescript_error": { + "level": "error" + }, + "colon_assignment_spacing": { + "level": "warn", + "spacing": { + "left": 0, + "right": 1 + } + }, + "cyclomatic_complexity": { + "level": "warn", + "value": 10 + }, + "duplicate_key": { + "level": "error" + }, + "empty_constructor_needs_parens": { + "level": "warn" + }, + "ensure_comprehensions": { + "level": "warn" + }, + "eol_last": { + "level": "warn" + }, + "indentation": { + "value": 2, + "level": "error" + }, + "line_endings": { + "level": "warn", + "value": "unix" + }, + "max_line_length": { + "value": 80, + "level": "ignore", + "limitComments": true + }, + "missing_fat_arrows": { + "level": "ignore" + }, + "newlines_after_classes": { + "value": 3, + "level": "warn" + }, + "no_backticks": { + "level": "error" + }, + "no_debugger": { + "level": "warn", + "console": false + }, + "no_empty_functions": { + "level": "warn" + }, + "no_empty_param_list": { + "level": "warn" + }, + "no_implicit_braces": { + "level": "ignore", + "strict": true + }, + "no_implicit_parens": { + "level": "ignore", + "strict": true + }, + "no_interpolation_in_single_quotes": { + "level": "warn" + }, + "no_nested_string_interpolation": { + "level": "warn" + }, + "no_plusplus": { + "level": "warn" + }, + "no_private_function_fat_arrows": { + "level": "warn" + }, + "no_stand_alone_at": { + "level": "warn" + }, + "no_tabs": { + "level": "error" + }, + "no_this": { + "level": "warn" + }, + "no_throwing_strings": { + "level": "error" + }, + "no_trailing_semicolons": { + "level": "error" + }, + "no_trailing_whitespace": { + "level": "error", + "allowed_in_comments": false, + "allowed_in_empty_lines": true + }, + "no_unnecessary_double_quotes": { + "level": "warn" + }, + "no_unnecessary_fat_arrows": { + "level": "warn" + }, + "non_empty_constructor_needs_parens": { + "level": "warn" + }, + "prefer_english_operator": { + "level": "ignore", + "doubleNotLevel": "warn" + }, + "space_operators": { + "level": "warn" + }, + "spacing_after_comma": { + "level": "warn" + }, + "transform_messes_up_line_numbers": { + "level": "warn" + } +} + diff --git a/actionview/package.json b/actionview/package.json index ec3306c299..5c2ba75e8a 100644 --- a/actionview/package.json +++ b/actionview/package.json @@ -12,7 +12,7 @@ "scripts": { "build": "bundle exec blade build", "test": "echo \"See the README: https://github.com/rails/rails-ujs#how-to-run-tests\" && exit 1", - "lint": "coffeelint src && eslint test/public/test", + "lint": "coffeelint app/assets/javascripts && eslint test/public/test" }, "repository": { "type": "git", diff --git a/actionview/test/ujs/config.ru b/actionview/test/ujs/config.ru index 414c2063c3..48b7a4b53a 100644 --- a/actionview/test/ujs/config.ru +++ b/actionview/test/ujs/config.ru @@ -1,3 +1,4 @@ $LOAD_PATH.unshift File.expand_path("..", __FILE__) require "server" + run UJS::Server diff --git a/actionview/test/ujs/server.rb b/actionview/test/ujs/server.rb index 25f70baf5f..7deb208af0 100644 --- a/actionview/test/ujs/server.rb +++ b/actionview/test/ujs/server.rb @@ -1,11 +1,10 @@ +require "rack" require "rails" require "action_controller/railtie" require "action_view/railtie" require "blade" require "json" -JQUERY_VERSIONS = %w[ 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.10.0 1.10.1 1.10.2 1.11.0 2.0.0 2.1.0].freeze - module UJS class Server < Rails::Application routes.append do @@ -18,7 +17,7 @@ module UJS config.cache_classes = false config.eager_load = false config.secret_key_base = "59d7a4dbd349fa3838d79e330e39690fc22b931e7dc17d9162f03d633d526fbb92dfdb2dc9804c8be3e199631b9c1fbe43fc3e4fc75730b515851849c728d5c7" - config.paths["app/views"].unshift("#{Rails.root / "views"}") + config.paths["app/views"].unshift("#{Rails.root}/views") config.public_file_server.enabled = true config.logger = Logger.new(STDOUT) config.log_level = :error @@ -26,32 +25,6 @@ module UJS end module TestsHelper - def jquery_link(version) - if params[:version] == version - "[#{version}]" - else - "#{version}".html_safe - end - end - - def cdn_link(cdn) - if params[:cdn] == cdn - "[#{cdn}]" - else - "#{cdn}".html_safe - end - end - - def jquery_src - if params[:version] == "edge" - "/vendor/jquery.js" - elsif params[:cdn] && params[:cdn] == "googleapis" - "https://ajax.googleapis.com/ajax/libs/jquery/#{params[:version]}/jquery.min.js" - else - "http://code.jquery.com/jquery-#{params[:version]}.js" - end - end - def test_to(*names) names = ["/vendor/qunit.js", "settings"] + names names.map { |name| script_tag name }.join("\n").html_safe @@ -61,10 +34,6 @@ module TestsHelper src = "/test/#{src}.js" unless src.index("/") %().html_safe end - - def jquery_versions - JQUERY_VERSIONS - end end class TestsController < ActionController::Base @@ -72,8 +41,6 @@ class TestsController < ActionController::Base layout "application" def index - params[:version] ||= ENV["JQUERY_VERSION"] || "1.11.0" - params[:cdn] ||= "jquery" render :index end diff --git a/actionview/test/ujs/views/layouts/application.html.erb b/actionview/test/ujs/views/layouts/application.html.erb index e09b213b72..a69cd2d739 100644 --- a/actionview/test/ujs/views/layouts/application.html.erb +++ b/actionview/test/ujs/views/layouts/application.html.erb @@ -3,30 +3,15 @@ <%= @title %> - - - <%= script_tag jquery_src %> + <%= script_tag "http://code.jquery.com/jquery-2.2.0.js" %>