From c55ec14e44bbc5fa437776b2627e93be59b38639 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Fri, 14 Jul 2017 16:44:56 +0200 Subject: [PATCH 01/11] =?UTF-8?q?Use=20Chrome=20Headless=20by=20default=20?= =?UTF-8?q?to=20run=20unit=20tests=20=F0=9F=98=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++++- package.json | 2 +- src/configure-karma/index.js | 17 +++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d87a069..e8bef57 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,12 @@ Sagui will automatically run every test file that follows this convention. Under the hood it uses [Karma test runner](http://karma-runner.github.io/) to allow running the tests in the most diverse browsers and even through [Selenium](http://docs.seleniumhq.org/) (not natively). -By default Sagui uses [PhantomJS](http://phantomjs.org/) to run the tests headlessly. To **speed up installing the dependencies** (`npm install`) it is advisable to have PhantomJS [installed globally](https://github.com/Medium/phantomjs#using-phantomjs-from-disk) in the machine. +To run the tests Sagui uses [Chrome Headless](https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md), but it fallbacks to [PhantomJS](http://phantomjs.org/) if Chrome is not installed on the machine. + +Make sure either of these browsers is installed to be able to run the tests: + +- [Chrome](https://www.google.com/chrome/browser/desktop/index.html) +- [PhantomJS](https://github.com/Medium/phantomjs#using-phantomjs-from-disk) To open the tests in a browser (or in multiple browsers!), simply follow the link Karma outputs when you start running the script `test:unit:watch`. Running them in a browser allows you to set breakpoints and debug your code properly. Note watch mode is necessary, else tests will stop running when finished. diff --git a/package.json b/package.json index 93ece8d..72cfb6c 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "karma": "^1.6.0", "karma-chrome-launcher": "^2.0.0", "karma-coverage": "^1.1.1", + "karma-detect-browsers": "^2.2.5", "karma-firefox-launcher": "^1.0.1", "karma-jasmine": "^1.1.0", "karma-mocha-reporter": "^2.2.3", @@ -110,7 +111,6 @@ "node-sass": "^4.5.2", "null-loader": "^0.1.1", "parent-module": "^0.1.0", - "phantomjs-prebuilt": "^2.1.14", "postcss-loader": "^1.3.3", "prettier": "^1.3.1", "raw-loader": "^0.5.1", diff --git a/src/configure-karma/index.js b/src/configure-karma/index.js index 175f954..944d36c 100644 --- a/src/configure-karma/index.js +++ b/src/configure-karma/index.js @@ -9,7 +9,7 @@ export default (saguiConfig = {}, webpackConfig) => { } const buildStandardKarmaConfig = (saguiConfig, webpackConfig) => { - const { projectPath, watch, coverage } = saguiConfig + const { projectPath, watch, coverage, additionalKarmaConfig = {} } = saguiConfig return { // Webpack itself supports an array of configurations @@ -26,7 +26,20 @@ const buildStandardKarmaConfig = (saguiConfig, webpackConfig) => { ...(coverage ? ['coverage'] : []) ], - frameworks: ['jasmine'], + frameworks: ['jasmine', 'detectBrowsers'], + + detectBrowsers: { + enabled: additionalKarmaConfig.browsers && additionalKarmaConfig.browsers > 0, + usePhantomJS: true, + + postDetection: function (availableBrowser) { + if (availableBrowser.indexOf('Chrome') > -1) { + return ['ChromeHeadless'] + } + + return ['PhantomJS'] + } + }, // first run will have the full output and // the next runs just output the summary and From a205a7dbf43f001c9bb54b5c632d8e2b8a169b80 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Fri, 14 Jul 2017 16:55:29 +0200 Subject: [PATCH 02/11] =?UTF-8?q?Bump=20the=20karma-chrome-launcher=20vers?= =?UTF-8?q?ion=20=E2=98=9D=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72cfb6c..cd2be16 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "html-webpack-plugin": "^2.28.0", "jasmine-core": "^2.5.2", "karma": "^1.6.0", - "karma-chrome-launcher": "^2.0.0", + "karma-chrome-launcher": "^2.2.0", "karma-coverage": "^1.1.1", "karma-detect-browsers": "^2.2.5", "karma-firefox-launcher": "^1.0.1", From 8b348257432e08433c9cc34c776e8e9347f2453a Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Sat, 15 Jul 2017 17:27:35 +0200 Subject: [PATCH 03/11] Use custom ChromeHeadless launcher --- src/configure-karma/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/configure-karma/index.js b/src/configure-karma/index.js index 944d36c..fe581a7 100644 --- a/src/configure-karma/index.js +++ b/src/configure-karma/index.js @@ -34,13 +34,23 @@ const buildStandardKarmaConfig = (saguiConfig, webpackConfig) => { postDetection: function (availableBrowser) { if (availableBrowser.indexOf('Chrome') > -1) { - return ['ChromeHeadless'] + return ['ChromeHeadlessLauncher'] } return ['PhantomJS'] } }, + customLaunchers: { + 'ChromeHeadlessLauncher': { + base: 'Chrome', + chromeFlags: [ + '--disable-gpu', + '--headless' + ] + } + }, + // first run will have the full output and // the next runs just output the summary and // errors in mocha style From 537c2b3785746e55df04386601fc116eb8eb6188 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 16:29:24 +0200 Subject: [PATCH 04/11] =?UTF-8?q?Specify=20'trusty'=20as=20ubuntu=20versio?= =?UTF-8?q?n=20to=20be=20able=20to=20install=20Chrome=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 831eed6..bb25c9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,10 @@ language: node_js node_js: - 6.11.1 - 8.1.4 -sudo: false +dist: trusty # needs Ubuntu Trusty to install Chrome +sudo: false # no need for virtualization. +addons: + chrome: stable before_install: - curl -o- -L https://yarnpkg.com/install.sh | bash # until yarn is - export PATH=$HOME/.yarn/bin:$PATH # pre-installed From ba961a51de17bdddf09fa194a190924889b2ce4b Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 16:34:29 +0200 Subject: [PATCH 05/11] =?UTF-8?q?Remove=20the=20custom=20launcher=20for=20?= =?UTF-8?q?ChromeHeadless=20=E2=9C=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configure-karma/index.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/configure-karma/index.js b/src/configure-karma/index.js index fe581a7..944d36c 100644 --- a/src/configure-karma/index.js +++ b/src/configure-karma/index.js @@ -34,23 +34,13 @@ const buildStandardKarmaConfig = (saguiConfig, webpackConfig) => { postDetection: function (availableBrowser) { if (availableBrowser.indexOf('Chrome') > -1) { - return ['ChromeHeadlessLauncher'] + return ['ChromeHeadless'] } return ['PhantomJS'] } }, - customLaunchers: { - 'ChromeHeadlessLauncher': { - base: 'Chrome', - chromeFlags: [ - '--disable-gpu', - '--headless' - ] - } - }, - // first run will have the full output and // the next runs just output the summary and // errors in mocha style From fe345f10e6cb7ff061f6e2d8b2ea8e0af8301551 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 17:05:39 +0200 Subject: [PATCH 06/11] =?UTF-8?q?Run=20Chrome=20and=20PhantomJS=20tests=20?= =?UTF-8?q?in=20Travis=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb25c9f..f67389d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,42 @@ language: node_js + node_js: -- 6.11.1 -- 8.1.4 -dist: trusty # needs Ubuntu Trusty to install Chrome -sudo: false # no need for virtualization. -addons: - chrome: stable + - 6.11.1 + - 8.1.4 + before_install: -- curl -o- -L https://yarnpkg.com/install.sh | bash # until yarn is -- export PATH=$HOME/.yarn/bin:$PATH # pre-installed + - curl -o- -L https://yarnpkg.com/install.sh | bash # until yarn is + - export PATH=$HOME/.yarn/bin:$PATH # pre-installed + script: -- node bin/ci.js -env: - matrix: - - TEST_TYPE=lint_and_test_unit - - TEST_TYPE=integration_test - - TEST_TYPE=test_create_project_npm - - TEST_TYPE=test_create_project_yarn + - node bin/ci.js + +matrix: + include: + - sudo: false + env: TEST_TYPE=lint_and_test_unit + + - sudo: false + env: TEST_TYPE=test_create_project_npm + + - sudo: false + env: TEST_TYPE=test_create_project_yarn + + # Test with Chrome available + - dist: trusty + addons: + chrome: stable + sudo: false + env: TEST_TYPE=integration_test + + # Test with PhantomJS available + - sudo: false + env: TEST_TYPE=integration_test + cache: directories: - - node_modules + - node_modules + deploy: provider: npm email: paulo@ragonha.me From 809b88b1bae4058573a278132f28d9cbc5fe6b46 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 17:08:35 +0200 Subject: [PATCH 07/11] =?UTF-8?q?Specify=20node=20version=20for=20all=20te?= =?UTF-8?q?st=20variations=20=F0=9F=92=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f67389d..6233c5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,5 @@ language: node_js -node_js: - - 6.11.1 - - 8.1.4 - before_install: - curl -o- -L https://yarnpkg.com/install.sh | bash # until yarn is - export PATH=$HOME/.yarn/bin:$PATH # pre-installed @@ -15,12 +11,15 @@ matrix: include: - sudo: false env: TEST_TYPE=lint_and_test_unit + node_js: 6.11.1 - sudo: false env: TEST_TYPE=test_create_project_npm + node_js: 6.11.1 - sudo: false env: TEST_TYPE=test_create_project_yarn + node_js: 6.11.1 # Test with Chrome available - dist: trusty @@ -28,10 +27,12 @@ matrix: chrome: stable sudo: false env: TEST_TYPE=integration_test + node_js: 6.11.1 # Test with PhantomJS available - sudo: false env: TEST_TYPE=integration_test + node_js: 6.11.1 cache: directories: From 1d3f8c3d763aa4f73bd5ee448866a79ed02be8f6 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 17:11:51 +0200 Subject: [PATCH 08/11] =?UTF-8?q?Show=20the=20browser=20name=20in=20which?= =?UTF-8?q?=20tests=20are=20running=20=F0=9F=85=B0=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6233c5c..377ff01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,12 +26,16 @@ matrix: addons: chrome: stable sudo: false - env: TEST_TYPE=integration_test + env: + - TEST_TYPE=integration_test + - BROWSER=Chrome node_js: 6.11.1 # Test with PhantomJS available - sudo: false - env: TEST_TYPE=integration_test + env: + - TEST_TYPE=integration_test + - BROWSER=PhantomJS node_js: 6.11.1 cache: From 766e77e06290eac6c3c917767eb35af2869d9b07 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 17:18:43 +0200 Subject: [PATCH 09/11] =?UTF-8?q?Fallback=20to=20PhanthomJS=20if=20CHROME?= =?UTF-8?q?=5FBIN=20is=20not=20set=20=F0=9F=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configure-karma/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configure-karma/index.js b/src/configure-karma/index.js index 944d36c..b4f22d5 100644 --- a/src/configure-karma/index.js +++ b/src/configure-karma/index.js @@ -33,7 +33,7 @@ const buildStandardKarmaConfig = (saguiConfig, webpackConfig) => { usePhantomJS: true, postDetection: function (availableBrowser) { - if (availableBrowser.indexOf('Chrome') > -1) { + if (availableBrowser.indexOf('Chrome') > -1 && process.env['CHROME_BIN']) { return ['ChromeHeadless'] } From 400cf4ea4e154141546d2b5280be9d08c094e646 Mon Sep 17 00:00:00 2001 From: Nikola Pejoski Date: Mon, 17 Jul 2017 17:31:14 +0200 Subject: [PATCH 10/11] Do not run other tests while test_create_project --- bin/ci.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/ci.js b/bin/ci.js index a1ab844..2df2a54 100644 --- a/bin/ci.js +++ b/bin/ci.js @@ -28,7 +28,7 @@ if (process.env.TEST_TYPE === 'integration_test') { if (process.env.TEST_TYPE === 'test_create_project_npm') { // # builds Sagui before installing exec('npm run build', saguiPath) - exec('npm pack') + exec('npm pack --ignore-scripts') var npmProjectPath = createTempFolder() @@ -47,7 +47,7 @@ if (process.env.TEST_TYPE === 'test_create_project_npm') { if (process.env.TEST_TYPE === 'test_create_project_yarn') { // # builds Sagui before installing exec('npm run build', saguiPath) - exec('npm pack') + exec('npm pack --ignore-scripts') var yarnProjectPath = createTempFolder() From 5042f7d7fbd9e5fcf5da68cb8a699085fd6039f7 Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Wed, 19 Jul 2017 10:52:40 +0200 Subject: [PATCH 11/11] =?UTF-8?q?Fix=20Travis=20not=20correctly=20using=20?= =?UTF-8?q?Chrome=20when=20available=20=F0=9F=94=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configure-karma/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/configure-karma/index.js b/src/configure-karma/index.js index b4f22d5..205e110 100644 --- a/src/configure-karma/index.js +++ b/src/configure-karma/index.js @@ -33,7 +33,11 @@ const buildStandardKarmaConfig = (saguiConfig, webpackConfig) => { usePhantomJS: true, postDetection: function (availableBrowser) { - if (availableBrowser.indexOf('Chrome') > -1 && process.env['CHROME_BIN']) { + const isTravis = process.env['TRAVIS'] === 'true' + const isChromeAvailable = availableBrowser.indexOf('Chrome') > -1 + const isTravisChromeAvailable = (process.env['TRAVIS_STACK_FEATURES'] || '').indexOf('google-chrome') !== -1 + + if (isChromeAvailable && (!isTravis || (isTravis && isTravisChromeAvailable))) { return ['ChromeHeadless'] }