diff --git a/.travis.yml b/.travis.yml index 19164129c52..851365acbd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ services: addons: postgresql: "9.6" + chrome: stable apt: sources: - sourceline: "ppa:mc3man/trusty-media" @@ -34,7 +35,6 @@ before_install: - "[[ $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. diff --git a/Gemfile b/Gemfile index f545dd5fa15..38125cf0cc4 100644 --- a/Gemfile +++ b/Gemfile @@ -102,6 +102,11 @@ group :storage do gem "mini_magick" end +group :ujs do + gem "qunit-selenium" + gem "chromedriver-helper" +end + # Add your own local bundler stuff. local_gemfile = File.expand_path(".Gemfile", __dir__) instance_eval File.read local_gemfile if File.exist? local_gemfile diff --git a/Gemfile.lock b/Gemfile.lock index ac56bca4ced..0889d69d3fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -136,6 +136,8 @@ GEM addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) amq-protocol (2.2.0) + archive-zip (0.7.0) + io-like (~> 0.3.0) ast (2.3.0) aws-partitions (1.20.0) aws-sdk-core (3.3.0) @@ -199,6 +201,9 @@ GEM xpath (~> 2.0) childprocess (0.7.1) ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (1.1.0) + archive-zip (~> 0.7.0) + nokogiri (~> 1.6) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -289,6 +294,7 @@ GEM http_parser.rb (0.6.0) httpclient (2.8.3) i18n (0.8.6) + io-like (0.3.0) jmespath (1.3.1) json (2.1.0) jwt (1.5.6) @@ -356,6 +362,9 @@ GEM public_suffix (2.0.5) puma (3.9.1) que (0.14.0) + qunit-selenium (0.0.4) + selenium-webdriver + thor racc (1.4.14) rack (2.0.3) rack-cache (1.7.0) @@ -498,6 +507,7 @@ DEPENDENCIES bootsnap (>= 1.1.0) byebug capybara (~> 2.15) + chromedriver-helper coffee-rails dalli (>= 2.2.1) delayed_job @@ -520,6 +530,7 @@ DEPENDENCIES puma que queue_classic! + qunit-selenium racc (>= 1.4.6) rack-cache (~> 1.2) rails! diff --git a/actionview/Rakefile b/actionview/Rakefile index 20dfa4e1149..5f1c0556923 100644 --- a/actionview/Rakefile +++ b/actionview/Rakefile @@ -45,7 +45,7 @@ namespace :test do end end - system("npm run lint && phantomjs ../ci/phantomjs.js http://localhost:4567/") + system("npm run lint && bundle exec ruby ../ci/qunit-selenium-runner.rb http://localhost:4567/") status = $?.to_i ensure Process.kill("KILL", pid) if pid diff --git a/ci/phantomjs.js b/ci/phantomjs.js deleted file mode 100644 index 7a33fb14a3d..00000000000 --- a/ci/phantomjs.js +++ /dev/null @@ -1,149 +0,0 @@ -/* - * PhantomJS Runner QUnit Plugin 1.2.0 - * - * PhantomJS binaries: http://phantomjs.org/download.html - * Requires PhantomJS 1.6+ (1.7+ recommended) - * - * Run with: - * phantomjs runner.js [url-of-your-qunit-testsuite] - * - * e.g. - * phantomjs runner.js http://localhost/qunit/test/index.html - */ - -/*global phantom:false, require:false, console:false, window:false, QUnit:false */ - -(function() { - 'use strict'; - - var url, page, timeout, - args = require('system').args; - - // arg[0]: scriptName, args[1...]: arguments - if (args.length < 2 || args.length > 3) { - console.error('Usage:\n phantomjs runner.js [url-of-your-qunit-testsuite] [timeout-in-seconds]'); - phantom.exit(1); - } - - url = args[1]; - page = require('webpage').create(); - if (args[2] !== undefined) { - timeout = parseInt(args[2], 10); - } - - // Route `console.log()` calls from within the Page context to the main Phantom context (i.e. current `this`) - page.onConsoleMessage = function(msg) { - console.log(msg); - }; - - page.onInitialized = function() { - page.evaluate(addLogging); - }; - - page.onCallback = function(message) { - var result, - failed; - - if (message) { - if (message.name === 'QUnit.done') { - result = message.data; - failed = !result || !result.total || result.failed; - - if (!result.total) { - console.error('No tests were executed. Are you loading tests asynchronously?'); - } - - phantom.exit(failed ? 1 : 0); - } - } - }; - - page.open(url, function(status) { - if (status !== 'success') { - console.error('Unable to access network: ' + status); - phantom.exit(1); - } else { - // Cannot do this verification with the 'DOMContentLoaded' handler because it - // will be too late to attach it if a page does not have any script tags. - var qunitMissing = page.evaluate(function() { return (typeof QUnit === 'undefined' || !QUnit); }); - if (qunitMissing) { - console.error('The `QUnit` object is not present on this page.'); - phantom.exit(1); - } - - // Set a timeout on the test running, otherwise tests with async problems will hang forever - if (typeof timeout === 'number') { - setTimeout(function() { - console.error('The specified timeout of ' + timeout + ' seconds has expired. Aborting...'); - phantom.exit(1); - }, timeout * 1000); - } - - // Do nothing... the callback mechanism will handle everything! - } - }); - - function addLogging() { - window.document.addEventListener('DOMContentLoaded', function() { - var currentTestAssertions = []; - - QUnit.log(function(details) { - var response; - - // Ignore passing assertions - if (details.result) { - return; - } - - response = details.message || ''; - - if (typeof details.expected !== 'undefined') { - if (response) { - response += ', '; - } - - response += 'expected: ' + details.expected + ', but was: ' + details.actual; - } - - if (details.source) { - response += "\n" + details.source; - } - - currentTestAssertions.push('Failed assertion: ' + response); - }); - - QUnit.testDone(function(result) { - var i, - len, - name = ''; - - if (result.module) { - name += result.module + ': '; - } - name += result.name; - - if (result.failed) { - console.log('\n' + 'Test failed: ' + name); - - for (i = 0, len = currentTestAssertions.length; i < len; i++) { - console.log(' ' + currentTestAssertions[i]); - } - } - - currentTestAssertions.length = 0; - }); - - QUnit.done(function(result) { - console.log('\n' + 'Took ' + result.runtime + 'ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.'); - - if (typeof window.callPhantom === 'function') { - window.callPhantom({ - 'name': 'QUnit.done', - 'data': result - }); - } - }); - }, false); - } -})(); - diff --git a/ci/qunit-selenium-runner.rb b/ci/qunit-selenium-runner.rb new file mode 100644 index 00000000000..1d18d666b07 --- /dev/null +++ b/ci/qunit-selenium-runner.rb @@ -0,0 +1,13 @@ +require 'qunit/selenium/test_runner' +require 'chromedriver/helper' + +driver_options = Selenium::WebDriver::Chrome::Options.new +driver_options.add_argument('--headless') +driver_options.add_argument('--disable-gpu') + +driver = ::Selenium::WebDriver.for(:chrome, options: driver_options) +result = QUnit::Selenium::TestRunner.new(driver).open(ARGV[0], timeout: 60) +driver.quit + +puts "Time: #{result.duration} seconds, Total: #{result.tests[:total]}, Passed: #{result.tests[:passed]}, Failed: #{result.tests[:failed]}" +exit(result.tests[:failed] > 0 ? 1 : 0)