Skip to content

Commit

Permalink
Cleanup the Karma Configuration File (madoar#245)
Browse files Browse the repository at this point in the history
- cleanup the karma config file
- use karma-browser-detect plugin to detect all testable browsers
- overhaul the .travis.yml file
- add safari as testing browser
- install chromium instead of chrome on gitpod
  • Loading branch information
madoar authored Nov 30, 2019
1 parent ce01534 commit 1ccf492
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 84 deletions.
61 changes: 42 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
sudo: required
dist: trusty

language: node_js

addons:
chrome: stable

branches:
only:
- master
- develop

node_js:
- "12"
- "11"
- "10"
addons:
chrome: stable
firefox: latest

jobs:
include:
- stage: Coverage
node_js: "12"
script: npm test
after_success:
- npm install -g codacy-coverage
- codacy-coverage < coverage/lcov.info
- stage: Build
node_js: "12"
script: npm run build
# Tests
- stage: Test
os: linux
dist: trusty
node_js: "10"
- stage: Test
os: linux
dist: trusty
node_js: "11"
- stage: Test
os: linux
dist: trusty
node_js: "12"
- stage: Test
os: osx
node_js: "10"
- stage: Test
os: osx
node_js: "11"
- stage: Test
os: osx
node_js: "12"
# Build
- stage: Build
os: linux
node_js: "12"
addons:
chrome: stable
script: npm run build
# Coverage
- stage: Coverage
os: linux
node_js: "12"
addons:
chrome: stable
script: npm test
after_success:
- npm install -g codacy-coverage
- codacy-coverage < coverage/lcov.info
51 changes: 5 additions & 46 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,12 @@
FROM gitpod/workspace-full:latest

# Change to root for the installation(s)
USER root
# Install chrome dependencies
RUN apt-get update && apt-get install -y \
gconf-service \
libappindicator3-1 \
libasound2 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
ca-certificates \
fonts-liberation \
libappindicator1 \
libnss3 \
lsb-release \
xdg-utils \
wget

# Install chrome
RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb
# Install Chromium
RUN apt-get update && apt-get install -y --no-install-recommends chromium-browser chromium-browser-l10n chromium-codecs-ffmpeg \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Give back control
USER root
65 changes: 47 additions & 18 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,61 @@
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
frameworks: ['jasmine', '@angular-devkit/build-angular', 'detectBrowsers'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
'karma-jasmine',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-safari-launcher',
'karma-detect-browsers',
'karma-jasmine-html-reporter',
'karma-coverage-istanbul-reporter',
'@angular-devkit/build-angular/plugins/karma'
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
fixWebpackSourcePaths: true,
thresholds: {
statements: 80,
lines: 80,
branches: 80,
functions: 80
}
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ModifiedChromeHeadless'],
customLaunchers: {
ModifiedChromeHeadless: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
},
ChromiumHeadlessNoSandbox: {
base: 'ChromiumHeadless',
flags: ['--no-sandbox']
}
},
detectBrowsers: {
// enable/disable, default is true
enabled: true,

// enable/disable phantomjs support, default is true
usePhantomJS: false,

// use headless mode, for browsers that support it, default is false
preferHeadless: true,

postDetection: function (availableBrowsers) {
if (availableBrowsers.includes('ChromeHeadless')) {
const index = availableBrowsers.indexOf('ChromeHeadless');

availableBrowsers[index] = 'ChromeHeadlessNoSandbox';
}

if (availableBrowsers.includes('ChromiumHeadless')) {
const index = availableBrowsers.indexOf('ChromiumHeadless');

availableBrowsers[index] = 'ChromiumHeadlessNoSandbox';
}

return availableBrowsers;
}
},
singleRun: true
Expand Down
34 changes: 33 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@
"karma": "~4.2.0",
"karma-chrome-launcher": "~3.0.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-detect-browsers": "^2.3.3",
"karma-firefox-launcher": "^1.2.0",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"karma-safari-launcher": "^1.0.0",
"ng-packagr": "^5.3.0",
"node-sass": "^4.12.0",
"protractor": "~5.4.0",
Expand Down

0 comments on commit 1ccf492

Please sign in to comment.