From 013f30dc23b05b9da646b3bea2f72b58de41f271 Mon Sep 17 00:00:00 2001 From: Brett Uglow Date: Thu, 31 Aug 2017 14:33:35 +1000 Subject: [PATCH] feat(generator): use Chrome for unit testing and visual regression testing Remove PhantomJS dependency from all projects ISSUES CLOSED: #124 --- lib/buildTool/codecept/codeceptResources.yml | 2 +- .../templates/{ => helpers}/codeceptHelper.js | 0 .../templates/backstop.config.js.tpl | 2 +- .../testUnit/templates/helpers/karmaHelper.js | 0 .../testUnit/templates/karma.common.js.tpl | 19 ++++++++++++----- .../testUnit/templates/karma.conf.js.tpl | 2 ++ .../testUnit/templates/test.files.js.tpl | 3 --- lib/buildTool/webpack/webpackResources.yml | 3 --- lib/core/packages.yml | 21 ++----------------- 9 files changed, 20 insertions(+), 32 deletions(-) rename lib/buildTool/codecept/testSystem/templates/{ => helpers}/codeceptHelper.js (100%) create mode 100644 lib/buildTool/webpack/testUnit/templates/helpers/karmaHelper.js diff --git a/lib/buildTool/codecept/codeceptResources.yml b/lib/buildTool/codecept/codeceptResources.yml index 5546c94..460fb6e 100644 --- a/lib/buildTool/codecept/codeceptResources.yml +++ b/lib/buildTool/codecept/codeceptResources.yml @@ -30,7 +30,7 @@ testSystem: features: templateFiles: - - src: codeceptHelper.js + - src: helpers/codeceptHelper.js dest: <%= paths.config.configDir + resources.confitLib.configSubDir%>codecept/helper.js overwrite: true diff --git a/lib/buildTool/codecept/testSystem/templates/codeceptHelper.js b/lib/buildTool/codecept/testSystem/templates/helpers/codeceptHelper.js similarity index 100% rename from lib/buildTool/codecept/testSystem/templates/codeceptHelper.js rename to lib/buildTool/codecept/testSystem/templates/helpers/codeceptHelper.js diff --git a/lib/buildTool/npm/testVisualRegression/templates/backstop.config.js.tpl b/lib/buildTool/npm/testVisualRegression/templates/backstop.config.js.tpl index 88b05af..1b5ba8e 100644 --- a/lib/buildTool/npm/testVisualRegression/templates/backstop.config.js.tpl +++ b/lib/buildTool/npm/testVisualRegression/templates/backstop.config.js.tpl @@ -46,7 +46,7 @@ let config = { testReportFileName: vis-reg-unit.xml testSuiteName: 'backstopJS' } - engine: 'phantomjs', + engine: 'chrome', report: ['CLI', 'browser', 'CI'], casperFlags: [ '--ignore-ssl-errors=true', diff --git a/lib/buildTool/webpack/testUnit/templates/helpers/karmaHelper.js b/lib/buildTool/webpack/testUnit/templates/helpers/karmaHelper.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/buildTool/webpack/testUnit/templates/karma.common.js.tpl b/lib/buildTool/webpack/testUnit/templates/karma.common.js.tpl index 4ff4b75..f7a91c3 100644 --- a/lib/buildTool/webpack/testUnit/templates/karma.common.js.tpl +++ b/lib/buildTool/webpack/testUnit/templates/karma.common.js.tpl @@ -53,14 +53,24 @@ let karmaConfig = { // web server default port port: 8081, - // Start these browsers, currently available: - // - Chrome, ChromeCanary, Firefox, Opera, Safari (only Mac), PhantomJS, IE (only Windows) + // Browser to test with browsers: [ - 'PhantomJS' + 'ChromeHeadless' ], + customLaunchers: { + ChromeHeadless: { + base: 'Chrome', + flags: [ + '--no-sandbox', + // See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md + '--headless', + '--disable-gpu', + '--remote-debugging-port=9222', + ], + }, + }, plugins: [ - 'karma-phantomjs-launcher', 'karma-jasmine', 'karma-junit-reporter', 'karma-coverage', @@ -71,7 +81,6 @@ let karmaConfig = { ], files: [ - 'node_modules/phantomjs-polyfill/bind-polyfill.js', '<%- paths.config.configDir + resources.testUnit.configSubDir %>test.files.js' ], diff --git a/lib/buildTool/webpack/testUnit/templates/karma.conf.js.tpl b/lib/buildTool/webpack/testUnit/templates/karma.conf.js.tpl index beb69aa..18663b4 100644 --- a/lib/buildTool/webpack/testUnit/templates/karma.conf.js.tpl +++ b/lib/buildTool/webpack/testUnit/templates/karma.conf.js.tpl @@ -20,6 +20,8 @@ function getConfitConfig(config) { if (debugMode) { + commonConfig.browsers = ['Chrome']; // Use Chrome + <% if (buildJS.sourceFormat === 'TypeScript') { %> var webpackHelpers = require('../webpack/webpackHelpers.js')(); // Remove the coverage reporter, otherwise it runs against the instrumented code, making it difficult to debug the code. diff --git a/lib/buildTool/webpack/testUnit/templates/test.files.js.tpl b/lib/buildTool/webpack/testUnit/templates/test.files.js.tpl index 155b841..18b1d3e 100644 --- a/lib/buildTool/webpack/testUnit/templates/test.files.js.tpl +++ b/lib/buildTool/webpack/testUnit/templates/test.files.js.tpl @@ -13,9 +13,6 @@ // START_CONFIT_GENERATED_CONTENT Error.stackTraceLimit = Infinity; -// Polyfill required for PhantomJS -require('phantomjs-polyfill'); - // Load the test dependencies! <% diff --git a/lib/buildTool/webpack/webpackResources.yml b/lib/buildTool/webpack/webpackResources.yml index be3beda..94160d0 100644 --- a/lib/buildTool/webpack/webpackResources.yml +++ b/lib/buildTool/webpack/webpackResources.yml @@ -272,13 +272,10 @@ testUnit: - <<: *pkg_karma-coverage - <<: *pkg_karma-jasmine - <<: *pkg_karma-junit-reporter - - <<: *pkg_karma-phantomjs-launcher - <<: *pkg_karma-sourcemap-loader - <<: *pkg_karma-threshold-reporter - <<: *pkg_karma-webpack - <<: *pkg_jasmine-core - - <<: *pkg_phantomjs-prebuilt - - <<: *pkg_phantomjs-polyfill - <<: *pkg_@types/jasmine tasks: diff --git a/lib/core/packages.yml b/lib/core/packages.yml index b0d6090..f8c977b 100644 --- a/lib/core/packages.yml +++ b/lib/core/packages.yml @@ -95,7 +95,7 @@ $packages: - &pkg_backstopjs name: backstopjs - version: 2.7.0 + version: 3.0.22 - &pkg_chokidar-cli name: chokidar-cli @@ -351,10 +351,6 @@ $packages: name: karma-junit-reporter version: 1.2.0 - - &pkg_karma-phantomjs-launcher - name: karma-phantomjs-launcher - version: 1.0.4 - - &pkg_karma-sourcemap-loader name: karma-sourcemap-loader version: 0.3.7 @@ -405,18 +401,6 @@ $packages: version: 4.1.1 isDependency: true - # TODO: deprecate PhantomJS - - &pkg_phantomjs-polyfill - name: phantomjs-polyfill - version: 0.0.2 - - - &pkg_phantomjs-prebuilt - name: phantomjs-prebuilt - version: 2.1.14 - # For karma-phantomjs-launcher to work, this package *must* appaear in package.json - # So install it globally AND include it in package.json - global: both - - &pkg_postcss-loader name: postcss-loader version: 1.3.3 @@ -426,8 +410,7 @@ $packages: version: 7.1.1 isDependency: true - # TODO: deprecate in favour of CodeceptJS - - &pkg_protractor # v5 available, but breaking changes + - &pkg_protractor name: protractor version: 5.1.2