Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add teamcity & browserstack support #185

Merged
merged 2 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions generators/app/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const DEFAULTS = {
'conventional-changelog-videojs',
'in-publish',
'karma',
'karma-browserstack-launcher',
'karma-teamcity-reporter',
'karma-chrome-launcher',
'karma-detect-browsers',
'karma-firefox-launcher',
Expand Down
164 changes: 129 additions & 35 deletions generators/app/templates/scripts/_karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,116 @@
/* eslint-disable no-console */
/* eslint-disable no-console, camelcase */
const serveStatic = require('serve-static');
const path = require('path');
const serve = serveStatic(
path.join(__dirname, '..'),
{index: ['index.html', 'index.htm']}
);
const pkg = require('../package.json');

/* allow static files to be served, note karma will takeover the /test directory */
const StaticMiddlewareFactory = function(config) {
console.log(`**** Dev server started at http://${config.listenAddress}:${config.port}/ *****`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this info being printed elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The karma server prints it when it starts up. Oftentimes the address we were printing here is the address we were passed. This means that when port 9999 is in use and get incremented by karma to 10000. we still print 9999.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool.

console.log(`**** static file server started for ${config.basePath} *****`);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should server the basePath, rather than trying to determine our own.


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

module.exports = function(config) {
const detectBrowsers = {
enabled: false,
usePhantomJS: false
};
/* browsers to run on teamcitystack */
const teamcityLaunchers = {}

// On Travis CI, we can only run in Firefox and Chrome; so, enforce that.
if (process.env.TRAVIS) {
config.browsers = ['Firefox', 'travisChrome'];
/* 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'
}
};

// 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) {
detectBrowsers.enabled = true;
/* browsers to run on travis */
const travisLaunchers = {
travisFirefox: {
base: 'Firefox'
},
travisChrome: {
base: 'Chrome',
flags: ['--no-sandbox']
}
};

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'
],
customLaunchers: {
travisChrome: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
client: {
clearContext: false,
qunit: {
showUI: true,
testTimeout: 5000
}
},
detectBrowsers,
reporters: ['dots'],
port: 9999,
urlRoot: '/test/',
plugins: [
Expand All @@ -67,6 +121,46 @@ module.exports = function(config) {
colors: true,
autoWatch: false,
singleRun: true,
concurrency: Infinity
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;
}

};
Loading