Skip to content

Commit

Permalink
feat: simplify karma config (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Aug 17, 2018
1 parent c2ba58f commit add0696
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 185 deletions.
11 changes: 1 addition & 10 deletions generators/app/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,12 @@ const DEFAULTS = {
'conventional-changelog-videojs',
'in-publish',
'karma',
'karma-browserstack-launcher',
'karma-teamcity-reporter',
'karma-chrome-launcher',
'karma-detect-browsers',
'karma-firefox-launcher',
'karma-ie-launcher',
'karma-qunit',
'karma-safari-launcher',
'mkdirp',
'serve-static',
'npm-run-all',
'qunit',
'rimraf',
'rollup',
'videojs-generate-rollup-config',
'videojs-generate-karma-config',
'not-prerelease',
'sinon',
'videojs-standard'
Expand Down
166 changes: 3 additions & 163 deletions generators/app/templates/scripts/_karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,166 +1,6 @@
/* eslint-disable no-console, camelcase */
const serveStatic = require('serve-static');
const pkg = require('../package.json');

/* allow static files to be served, note karma will takeover the /test directory */
const StaticMiddlewareFactory = function(config) {
console.log(`**** static file server started for ${config.basePath} *****`);

const serve = serveStatic(
config.basePath,
{index: ['index.html', 'index.htm']}
);

return function(req, res, next) {
res.setHeader('Cache-Control', 'no-cache,must-revalidate');
return serve(req, res, next);
};
};

/* browsers to run on teamcity */
const teamcityLaunchers = {};

/* browsers to run on browserstack */
const browserstackLaunchers = {
bsChrome: {
base: 'BrowserStack',
browser: 'chrome',
os: 'Windows',
os_version: '10'
},

bsFirefox: {
base: 'BrowserStack',
browser: 'firefox',
os: 'Windows',
os_version: '10'
},

bsSafariSierra: {
base: 'BrowserStack',
browser: 'safari',
os: 'OS X',
os_version: 'Sierra'
},

bsEdgeWin10: {
base: 'BrowserStack',
browser: 'edge',
os: 'Windows',
os_version: '10'
},

bsIE11Win10: {
base: 'BrowserStack',
browser: 'ie',
browser_version: '11',
os: 'Windows',
os_version: '10'
},

bsIE11Win7: {
base: 'BrowserStack',
browser: 'ie',
browser_version: '11',
os: 'Windows',
os_version: '7'
}
};

/* browsers to run on travis */
const travisLaunchers = {
travisFirefox: {
base: 'Firefox'
},
travisChrome: {
base: 'Chrome',
flags: ['--no-sandbox']
}
};
const generate = require('videojs-generate-karma-config');

module.exports = function(config) {
/* Default configuration */
config.set({
basePath: '..',
frameworks: ['qunit', 'detectBrowsers'],
customLaunchers: Object.assign(
{},
travisLaunchers,
teamcityLaunchers,
browserstackLaunchers
),
client: {clearContext: false, qunit: {showUI: true, testTimeout: 5000}},

detectBrowsers: {
enabled: false,
usePhantomJS: false
},
browserStack: {
project: process.env.TEAMCITY_PROJECT_NAME || pkg.name,
name: '',
build: process.env.TRAVIS_BUILD_NUMBER || process.env.BUILD_NUMBER,
pollingTimeout: 30000,
captureTimeout: 600,
timeout: 600
},
reporters: ['dots'],
files: [
'node_modules/video.js/dist/video-js.css',<% if (css) { %>
'dist/<%= pluginName %>.css',<% } %>
'node_modules/sinon/pkg/sinon.js',
'node_modules/video.js/dist/video.js',
'test/dist/bundle.js'
],
port: 9999,
urlRoot: '/test/',
plugins: [
{'middleware:static': ['factory', StaticMiddlewareFactory]},
'karma-*'
],
middleware: ['static'],
colors: true,
autoWatch: false,
singleRun: true,
concurrency: Infinity,

captureTimeout: 30000,
browserNoActivityTimeout: 300000
});

/* dynamic configuration, for ci and detectBrowsers */

// determine what browsers should be run on this environment
if (process.env.BROWSER_STACK_USERNAME) {
config.browsers = Object.keys(browserstackLaunchers);
} else if (process.env.TRAVIS) {
config.browsers = Object.keys(travisLaunchers);
} else if (process.env.TEAMCITY_VERSION) {
config.browsers = Object.keys(teamcityLaunchers);
}

// if running on travis
if (process.env.TRAVIS) {
config.browserStack.name = process.env.TRAVIS_BUILD_NUMBER;
if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
config.browserStack.name += process.env.TRAVIS_PULL_REQUEST;
config.browserStack.name += ' ';
config.browserStack.name += process.env.TRAVIS_PULL_REQUEST_BRANCH;
}

config.browserStack.name += ' ' + process.env.TRAVIS_BRANCH;

// if running on teamcity
} else if (process.env.TEAMCITY_VERSION) {
config.reporters.push('teamcity');
config.browserStack.name = process.env.TEAMCITY_PROJECT_NAME;
config.browserStack.name += '_';
config.browserStack.name += process.env.BUILD_NUMBER;
}

// If no browsers are specified, we enable `karma-detect-browsers`
// this will detect all browsers that are available for testing
if (config.browsers !== false && !config.browsers.length) {
config.detectBrowsers.enabled = true;
}

config = generate(config);
// any custom stuff here!
};
15 changes: 3 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,17 @@
"in-publish": "^2.0.0",
"jsdoc": "^3.4.3",
"karma": "^2.0.2",
"karma-browserstack-launcher": "^1.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-detect-browsers": "^2.2.6",
"karma-firefox-launcher": "^1.1.0",
"karma-ie-launcher": "^1.0.0",
"karma-qunit": "^2.0.0",
"karma-safari-launcher": "^1.0.0",
"karma-teamcity-reporter": "^1.1.0",
"mkdirp": "^0.5.1",
"npm-run-all": "^4.1.2",
"postcss-banner": "^3.0.0",
"postcss-cli": "^6.0.0",
"postcss-import": "^11.1.0",
"postcss-preset-env": "^5.1.0",
"qunit": "^2.5.1",
"rollup": "^0.63.2",
"videojs-generate-rollup-config": "~1.0.0",
"serve-static": "^1.13.2",
"sinon": "^5.1.0",
"video.js": "^6 || ^7",
"videojs-languages": "^1.0.0"
"videojs-languages": "^1.0.0",
"videojs-generate-karma-config": "~1.0.0",
"videojs-generate-rollup-config": "~1.0.0"
}
}

0 comments on commit add0696

Please sign in to comment.